📊

FFT Scope

Sinks
Run the live example Free · no sign-up · runs in your browser

The FFTScope block is a real-time frequency spectrum analyzer that performs the Fast Fourier Transform (FFT) on incoming simulation signals. It functions as a sink block, accepting one or more input signal connections and displaying their overlaid, color-coded magnitude or phase spectra directly on the canvas.

Control engineers and signal processing specialists use this block to identify dominant resonant modes, evaluate harmonic distortion in non-linear loops, verify digital filter stopband rejection, and inspect phase alignment across frequency bins.

Mathematical Model

For a discrete-time signal sequence x[n]x[n] conditioned by a tapering window w[n]w[n] over buffer length NN:

X[k]=∑n=0N−1x[n] w[n] e−j2πNkn,k=0,1,…,N−1X[k] = \sum_{n=0}^{N-1} x[n] \, w[n] \, e^{-j \frac{2\pi}{N} k n}, \quad k = 0, 1, \dots, N-1

The discrete frequency corresponding to bin kk is fk=k⋅fsNf_k = \frac{k \cdot f_s}{N}, where fs=1Tsf_s = \frac{1}{T_s} is the simulation sample rate. Depending on displayMode, the spectral values are computed as:

Magnitude (dB):YdB[k]=20log⁡10(2∣X[k]∣N+ε)Magnitude (linear):Ylin[k]=2∣X[k]∣NPhase (degrees):Φ[k]=atan2(Im{X[k]},Re{X[k]})⋅180∘π\begin{aligned} \text{Magnitude (dB):} \quad & Y_{\text{dB}}[k] = 20 \log_{10} \left( \frac{2 |X[k]|}{N} + \varepsilon \right) \\ \text{Magnitude (linear):} \quad & Y_{\text{lin}}[k] = \frac{2 |X[k]|}{N} \\ \text{Phase (degrees):} \quad & \Phi[k] = \text{atan2}\left(\text{Im}\{X[k]\}, \text{Re}\{X[k]\}\right) \cdot \frac{180^\circ}{\pi} \end{aligned}

Inputs & Outputs

Direction ID Label Type Status
→ In signal Signal number Required

Parameters

Parameters Label Type Default Description
title Title text Frequency Spectrum
displayMode Display Mode select db
analysisMode Analysis Mode select window
fftSize FFT Window Size select 1024 Number of samples used per FFT computation.
windowFunction Window Function select hann Reduces spectral leakage.
maxFrequency Max Frequency (Hz, 0 = auto) number 0 Set to 0 to auto-scale based on the Nyquist frequency.
peakHold Peak Hold boolean false Maintains the maximum value reached across all spectra.
showLegend Show Legend boolean true
showGrid Show Grid boolean true

Usage Examples

Example 1: Harmonic Distortion in Saturated Feedback Loops

Measuring harmonic content generated by an amplifier with saturation non-linearities. Wiring the saturated output to FFTScope in "db" mode with fftSize = "1024" and windowFunction = "blackman". The spectrum displays the primary excitation peak at 50 Hz alongside third (150 Hz) and fifth (250 Hz) harmonic spurs at −13.5-13.5 dB and −21-21 dB below fundamental.

Example 2: Digital Filter Passband and Attenuation Verification

Verifying stopband attenuation of a DigitalFilter lowpass block fed by broadband white noise. Connecting both raw noise and filtered output to the multi-input port with displayMode = "db" and peakHold = true. The comparative spectra confirm a flat response up to the 100 Hz cutoff followed by steep −40-40 dB/decade roll-off.

Remarks & Best Practices

  • Nyquist-Shannon Sampling Boundary: The maximum observable frequency is limited to half the simulation sample rate (fNyquist=12Tsf_{\text{Nyquist}} = \frac{1}{2 T_s}). Frequencies exceeding this limit will alias into lower frequency bins.
  • Window Trade-Offs: The Hann window offers optimal trade-off between main-lobe width and side-lobe suppression for continuous oscillations; use Blackman for high dynamic range and Rectangular for transient impulses.
  • Resolution Scaling: Frequency bin resolution improves with larger buffer sizes (Δf=fs/N\Delta f = f_s / N); use "full" analysis mode post-simulation for ultra-fine sub-Hertz spectral line extraction.
  • Buffer Initialization: If the simulation has stepped fewer times than fftSize, the input buffer is zero-padded to allow immediate spectral estimation.

Related Components

  • uPlotDisplay: Multi-channel time-series oscilloscope for time-domain waveform analysis.
  • DigitalFilter: Configurable IIR/FIR filter block for band-limiting signals.
  • SignalGenerator: Multi-waveform signal source for frequency-domain stimulus.
  • NumericDisplay: Real-time scalar readout for instantaneous signal magnitudes.