Fast Fourier Transform
ShippingfftWindowed DFT: magnitude, phase, and frequency outputs
Signature
Inputs
signalSignalrequired
Outputs
magnitudeSignalphaseSignalfrequencySignal
Parameters
| Key | Type | Default | Notes |
|---|---|---|---|
window_function | enum | hann | one of: none, hann, hamming, blackman, blackman_harris, flattop, bartlett |
output_type | enum | magnitude | one of: magnitude, power, db |
one_sided | bool | true |
Description
FFT computes a windowed discrete Fourier transform of the incoming signal, producing three co-registered outputs: magnitude (scaled per output_type), phase (in radians), and the frequency axis (in Hz). It is the primary spectral-analysis primitive: it moves a time-domain record into the frequency domain so periodic structure, tones, and noise floors become directly readable.
Before transforming, the input is tapered by the selected window_function (hann by default) to suppress spectral leakage from finite-length records, then zero-padded to the next power of two. The transform requires at least 2 samples. When one_sided is enabled (the default), only the positive-frequency half is kept ( bins) and every non-DC, non-Nyquist bin is doubled so the reported energy remains correct despite discarding the mirrored half.
The frequency axis is derived from the input sample rate, so it carries a Hz unit. The magnitude output inherits the physical unit of the input signal for magnitude/power scaling; the db scaling produces a dimensionless logarithmic quantity. FFT is stateless — each evaluation transforms only the current record with no memory across runs, and the ctx parameter is ignored for zero overhead.
Mathematics
Examples
Identifying a tone with a Hann window
Feed a 50 Hz sine sampled at 1000 Hz into fft with window_function = hann, output_type = magnitude, one_sided = true. The magnitude output shows a sharp peak whose corresponding frequency bin reads Hz; the Hann taper keeps the skirts low so nearby components stay resolvable. Pair magnitude and frequency on an XY plot to get a spectrum.
Power spectrum in decibels
Set output_type = db to view the spectrum on a logarithmic scale, ideal for inspecting a noise floor spanning many orders of magnitude:
signal_generator -> fft(window=blackman_harris, output_type=db)The blackman_harris window trades main-lobe width for very low side-lobes, exposing weak spurs that a rectangular window would bury under leakage.
Applications
- Vibration and machine-health monitoring: extracting rotational and bearing-fault frequencies from accelerometer records.
- Audio and acoustics: spectral content analysis, harmonic distortion measurement, and octave-band inspection.
- Communications and RF: locating carrier tones, measuring spurious emissions, and estimating occupied bandwidth.
- Instrumentation and lab characterization: measuring noise floors and SNR of sensors and data-acquisition front-ends.
Neat
Doubling the non-DC/non-Nyquist bins in one-sided mode is what makes the reported amplitudes physically correct — the discarded negative-frequency half carried exactly that energy.
Because the record is zero-padded to the next power of two, spectral bins land at interpolated frequencies; padding improves the visual density of the spectrum but does not add true frequency resolution, which is fixed by the record duration.
Known issues
Inputs whose length is not a power of two are zero-padded, which shifts the effective bin spacing and can make peak frequencies read slightly off from the naive expectation; window and zero-pad choices affect apparent amplitude.
With `window_function = none` (rectangular), a tone that does not fall exactly on a bin center suffers strong spectral leakage, spreading energy into neighboring bins and biasing magnitude readings.