viewof T = Inputs.range([2, 120], { value: 20, step: 1, label: "Recording duration T (s)" })
viewof f1 = Inputs.range([0.5, 4], { value: 1.0, step: 0.01, label: "f₁ (Hz), amplitude 1" })
viewof f2 = Inputs.range([0.5, 4], { value: 1.6, step: 0.01, label: "f₂ (Hz)" })
viewof a2 = Inputs.range([0.001, 1], { value: 0.02, step: 0.001, label: "Amplitude of f₂" })
viewof nz = Inputs.range([0, 1], { value: 0.05, step: 0.01, label: "Noise SD" })
viewof win = Inputs.radio(["Rectangular", "Hann"], { value: "Rectangular", label: "Window" })
viewof welch = Inputs.toggle({ label: "Welch's method (split into segments and average)", value: false })
viewof segLen = Inputs.range([2, 60], { value: 10, step: 1, label: "Welch segment length (s)" })6 Fourier Analysis and Spectral Estimation
LF/HF in HRV, the alpha rhythm in EEG, heart-rate estimation from PPG —— many biosignal metrics are computed from “which frequency components are present, and how strongly” (the spectrum). This chapter covers three things you need to know when estimating a spectrum: frequency resolution, spectral leakage (window functions), and the variance of the estimate (Welch’s method).
6.1 Intuition for the Fourier transform
Any signal can be represented as a sum of sinusoids of various frequencies. The Fourier transform is the operation that finds how large a contribution each frequency’s sinusoid makes to the signal.
The discrete Fourier transform (DFT) of an N-point discrete signal x[n] is:
X[k] = \sum_{n=0}^{N-1} x[n]\, e^{-j 2\pi k n / N}, \qquad f_k = \frac{k}{N} f_s
X[k] expresses “how similar the signal is to a sinusoid of frequency f_k (an inner product)”. The fast Fourier transform (FFT) is the name of an algorithm that computes the DFT quickly.
The power spectral density (PSD) is |X[k]|^2 suitably normalized; its unit is (signal unit)²/Hz. For HRV it is ms²/Hz.
6.2 Point 1: frequency resolution is set by the recording duration
The frequency spacing of the DFT is
\Delta f = \frac{f_s}{N} = \frac{1}{T} \qquad (T: \text{recording duration})
Raising the sampling frequency does not improve frequency resolution; the only way is a longer recording.
- A 5-minute (300 s) recording → \Delta f \approx 0.0033 Hz
- It is no coincidence that the lower limit of the HRV VLF band, 0.0033 Hz, matches the resolution of a 5-minute recording
- With a 1-minute recording, \Delta f \approx 0.017 Hz, so assessment of the LF band (0.04–0.15 Hz) becomes coarse
NoteZero padding does not increase resolution
Appending zeros to the data to make N larger makes the displayed spectrum smoother, but this is merely interpolation; it does not improve the ability to separate two nearby frequencies.
6.3 Point 2: spectral leakage and window functions
Cutting out a finite-length segment of a signal is the same as multiplying an infinitely long signal by a rectangular window. Because the signal is cut off abruptly at the window edges, a spectrum that should be a single line leaks into neighbouring frequencies (spectral leakage).
Window functions such as the Hann window greatly reduce leakage by smoothly tapering the edges toward 0. In exchange, the main peak becomes wider (resolution decreases) and its amplitude becomes smaller.
6.4 Point 3: variance and Welch’s method
A spectrum computed from a single record (the periodogram) has the property that its variance does not decrease even if the recording is made longer.
Welch’s method splits the record into multiple (overlapping) segments and averages the spectra of the segments, reducing the variance. In exchange, because the segments are shorter, frequency resolution decreases.
6.5 Demo: three trade-offs in spectral estimation
We estimate the spectrum of a signal sampled at 10 Hz consisting of a large sinusoid at frequency f_1 and a small sinusoid at frequency f_2, plus noise. The vertical axis is relative, with the maximum set to 0 dB.
Blue dashed line: f_1; red dashed line: f_2
TipTry it
- Resolution: with the rectangular window and a_2 = 1 (equal amplitude), move f_2 closer to f_1 (e.g. 1.05 Hz). Shortening the recording duration T makes the two peaks impossible to separate. How is the smallest separable difference related to 1/T?
- Spectral leakage: at the defaults (a_2 = 0.02, −34 dB), switch between the rectangular and Hann windows. With which one can you see the small f_2 peak? Also confirm that setting f_1 to a value off the resolution grid, such as 1.05 Hz, makes the leakage of the rectangular window even larger
- Variance: raise the noise SD to 0.5 and toggle Welch’s method on and off with T = 120 s. What happens to the variance, and to the resolution, when you shorten the segment length?
NoteExplanation
- Two peaks can be separated roughly when |f_2 - f_1| is at least 1–2 times the resolution 1/T (with the Hann window the main peak is wider, so an even longer recording is needed).
- The rectangular window has large leakage (sidelobes) of about −13 dB that decays only slowly, so a small nearby component gets buried in the leakage. The Hann window has sidelobes of about −31 dB that decay quickly, so the small component becomes visible. The same thing happens in HRV analysis when you look at components near large VLF and LF components.
- The shorter the segments in Welch’s method, the more segments are averaged and the smaller the variance, but the resolution 1/(\text{segment length}) becomes coarser. For 5-minute HRV recordings, averaging over segments of around 128–256 s is common.
6.6 Unevenly sampled data: the Lomb-Scargle periodogram
Data whose sampling interval is not constant, such as a series of RR intervals, cannot be fed to the DFT directly. There are two approaches.
- Resample to even spacing and then apply the DFT (common in HRV analysis; the interpolation method affects the spectrum)
- Lomb-Scargle periodogram: estimates the spectrum without resampling, by least-squares fitting of a sinusoid at each frequency. It is also robust to data with gaps due to missing values or artifact removal
6.7 Spectra that change over time
When the properties of a signal change over time, as during exercise or sleep, methods such as
- Short-time Fourier transform (STFT): computes the spectrum while sliding a window (spectrogram). Time resolution and frequency resolution are a trade-off
- Wavelet transform: analyses low frequencies with long windows and high frequencies with short windows
are used.
6.8 Summary
- Frequency resolution = 1 / recording duration. Neither a higher sampling frequency nor zero padding improves it
- Window functions: the rectangular window has high resolution but large leakage; the Hann window has small leakage but lower resolution
- Welch’s method: reduces variance at the cost of resolution
- For unevenly sampled data, use resampling or Lomb-Scargle