← Notes · December 2026

Spectral analysis of sensor data: some theory

The periodogram, its distribution, filters, harmonics, coherence and the Wiener filter, with proofs, and why a single regression correction cannot fix errors that depend on frequency.

A scatter plot of a low-cost sensor against a reference monitor gives one number: how well they agree overall. But pollution varies on many time scales at once, from traffic peaks lasting hours to seasonal cycles, and a sensor can be accurate on some scales and poor on others. Spectral analysis splits the variance of a time series by frequency, so agreement can be checked scale by scale. These notes collect the main results, with proofs where they are short.

1. Setup

Let \(x_t\) be a weakly stationary series with mean \(\mu\) and autocovariance \(\gamma(h) = \operatorname{Cov}(x_{t+h}, x_t)\). If \(\sum_h|\gamma(h)|<\infty\), its spectral density is

\[ f(\nu) = \sum_{h=-\infty}^{\infty} \gamma(h)\, e^{-2\pi i \nu h}, \qquad \nu \in [-\tfrac12, \tfrac12], \qquad \gamma(h) = \int_{-1/2}^{1/2} f(\nu)\, e^{2\pi i\nu h}\, d\nu . \]

Frequency \(\nu\) is in cycles per time step (per hour for hourly data), and the period is \(1/\nu\). Setting \(h = 0\) gives \(\operatorname{Var}(x_t) = \int f(\nu)\,d\nu\): the spectral density says how the variance is spread over frequencies.

From data \(x_0,\dots,x_{N-1}\), the periodogram at the Fourier frequencies \(\nu_k = k/N\) is

\[ I(\nu_k) = \frac1N\Big|\sum_{t=0}^{N-1} x_t\, e^{-2\pi i \nu_k t}\Big|^2 . \]

2. The periodogram

Proposition 1 (variance decomposition). If \(\bar x = 0\), then \[ \frac1N\sum_{t=0}^{N-1} x_t^2 \;=\; \frac1N\sum_{k=1}^{N-1} I(\nu_k). \]

Proof. The vectors \(e_k = (e^{2\pi i kt/N})_{t}\) are orthogonal with \(\|e_k\|^2 = N\). Writing \(X_k = \sum_t x_t e^{-2\pi ikt/N}\), Parseval's identity gives \(\sum_t x_t^2 = \frac1N\sum_k |X_k|^2 = \sum_k I(\nu_k)\). The \(k=0\) term is \(N\bar x^2 = 0\). \(\square\)

Proposition 2 (periodogram and autocovariance). For \(k \neq 0\), \[ I(\nu_k) = \sum_{|h|

Proof. Since \(\sum_t e^{-2\pi i\nu_k t} = 0\) for \(k\neq0\), subtracting \(\bar x\) does not change \(X_k\). Expand \(|X_k|^2 = \sum_{s,t}(x_s-\bar x)(x_t-\bar x)e^{-2\pi i\nu_k(s-t)}\) and group the terms by the lag \(h = s-t\). \(\square\)

So the periodogram is the sample version of the spectral density. It is, however, a noisy one.

Proposition 3 (white noise). If \(x_t\) are independent \(\mathcal N(0,\sigma^2)\), then for \(0

Proof. Write \(X_k = A_k - iB_k\) with \(A_k = \sum_t x_t\cos(2\pi kt/N)\) and \(B_k = \sum_t x_t\sin(2\pi kt/N)\). For \(0

Remark (general series). The same picture holds approximately for linear processes with a smooth spectral density: for fixed frequencies \(0<\nu_1<\dots<\nu_r<\tfrac12\), the values \(I(\nu_j)/f(\nu_j)\) are asymptotically independent \(\mathrm{Exp}(1)\) (Brockwell and Davis, 1991, Ch. 10). Hence \(\mathbb E\,I(\nu)\to f(\nu)\), but \(\operatorname{Var} I(\nu) \to f(\nu)^2\), which does not shrink as \(N\) grows. The raw periodogram is asymptotically unbiased but not consistent. Averaging \(L\) approximately independent values (neighbouring frequencies, Welch segments, or separate sites) reduces the variance to about \(f^2/L\).

3. Filters and harmonics

Proposition 4 (filtering). If \(y_t = \sum_j w_j x_{t-j}\) with \(\sum_j|w_j|<\infty\), then \[ f_y(\nu) = |H(\nu)|^2 f_x(\nu), \qquad H(\nu) = \sum_j w_j e^{-2\pi i\nu j}. \]

Proof. \(\gamma_y(h) = \sum_{j,l} w_j w_l\,\gamma_x(h-j+l)\). Substituting \(\gamma_x(u) = \int f_x(\nu)e^{2\pi i\nu u}d\nu\) and summing over \(j\) and \(l\) gives \(\gamma_y(h) = \int |H(\nu)|^2 f_x(\nu)\, e^{2\pi i\nu h}d\nu\). \(\square\)

For example, the KZ components of the previous note have spectra \(|H_m|^{2k} f\) and \(|1-H_m^k|^2 f\). Filtering never creates power at a frequency; it only rescales what is there.

Lemma 5 (harmonics). If \(d_t\) is periodic with integer period \(P\), then \(d_t = \sum_{n=0}^{P-1} c_n e^{2\pi i nt/P}\). Its periodogram over whole periods is zero except at the frequencies \(n/P\), that is, at periods \(P, P/2, P/3, \dots\)

Proof. A sequence with period \(P\) is a vector in \(\mathbb C^P\), and the \(P\) vectors \((e^{2\pi i nt/P})_{t=0}^{P-1}\) form an orthogonal basis (the discrete Fourier basis). Over \(N = MP\) samples, \(\sum_t e^{2\pi i nt/P}e^{-2\pi ikt/N}\) vanishes unless \(k = nM\), i.e. \(\nu_k = n/P\). \(\square\)

Remark (interpreting peaks). For hourly data with a daily cycle (\(P = 24\)), Lemma 5 says a single daily pattern produces peaks at 24, 12, 8, 6 and 4.8 hours unless its shape is a pure sinusoid. A daily profile with morning and evening rush hours already has strong 12 h and 8 h peaks. So a peak at 8 or 12 hours can come from a separate process, or from the shape of the daily cycle. Telling them apart needs extra information, such as comparing weekdays with weekends, or summer with winter.

4. Calibration in the frequency domain

Model a sensor as a linear time-invariant response to the true concentration, plus noise:

\[ s_t = \sum_j g_j\, y_{t-j} + e_t, \qquad G(\nu) = \sum_j g_j e^{-2\pi i\nu j}, \]

with \(e_t\) uncorrelated with \(y\) and with spectral density \(f_e\). A sensor that responds to fast changes less than to slow ones has \(|G(\nu)|\) decreasing in \(\nu\).

Proposition 6 (static corrections). Under this model, any affine correction \(\hat y_t = a + b\,s_t\) has \[ \frac{f_{\hat y}(\nu)}{f_y(\nu)} = b^2\Big(|G(\nu)|^2 + \frac{f_e(\nu)}{f_y(\nu)}\Big). \] This ratio equals 1 at every frequency only if \(|G|^2 + f_e/f_y\) is constant. In particular, if \(b\) is chosen so that slow components are right (\(b|G(0)|\approx1\)) and noise is small, components at frequency \(\nu\) are still scaled by \(|G(\nu)|^2/|G(0)|^2\).

Proof. Since \(e\) is uncorrelated with \(y\), Proposition 4 gives \(f_s = |G|^2 f_y + f_e\). Adding a constant does not change the spectrum, and multiplying by \(b\) multiplies it by \(b^2\). \(\square\)

Adding covariates such as humidity or temperature to the regression adds their own (rescaled) spectra, but it does not change how the correction responds to \(y\) at each frequency. A regression with constant coefficients treats all time scales the same way, so it cannot undo a response that depends on frequency.

The natural alternative is a correction that is itself a filter. Define the cross-spectrum \(f_{ys}(\nu) = \sum_h \operatorname{Cov}(y_{t+h}, s_t)\,e^{-2\pi i\nu h}\) and the coherence

\[ C(\nu) = \frac{|f_{ys}(\nu)|^2}{f_y(\nu)\, f_s(\nu)} \in [0,1]. \]
Theorem 7 (Wiener filter). Among linear time-invariant estimators \(\hat y_t = \sum_j h_j s_{t-j}\) of a zero-mean \(y\), the mean squared error is minimised by the filter with frequency response \[ H^\star(\nu) = \frac{f_{ys}(\nu)}{f_s(\nu)}, \] and the minimum error is \[ \mathbb E\,(y_t - \hat y_t)^2 = \int_{-1/2}^{1/2} f_y(\nu)\,\big(1 - C(\nu)\big)\, d\nu . \]

Proof. Let \(\varepsilon = y - \hat y\). By the computation in Proposition 4, \(\operatorname{Cov}(y_{t+h}, \hat y_t)\) has spectrum \(\overline{H}\,f_{ys}\), so \[ f_\varepsilon = f_y - \overline{H} f_{ys} - H\,\overline{f_{ys}} + |H|^2 f_s = f_s\Big|H - \frac{f_{ys}}{f_s}\Big|^2 + f_y - \frac{|f_{ys}|^2}{f_s}. \] The error \(\mathbb E\varepsilon_t^2 = \int f_\varepsilon\,d\nu\) is minimised frequency by frequency by making the first term zero, which leaves \(f_y(1-C)\). \(\square\)

Coherence therefore has a direct meaning: \(C(\nu)\) is the fraction of the reference variance at frequency \(\nu\) that any linear correction of the sensor can recover. Where coherence is low, no calibration of this kind will help, and better hardware or more information is needed.

5. Implementation

A minimal Python version with scipy.signal, for hourly series y (reference) and s (sensor) on the same timestamps. Tested on synthetic data: the periodogram integrates to the variance (Proposition 1), and white-noise ordinates have mean \(\sigma^2\) and variance \(\sigma^4\) (Proposition 3).

import numpy as np
from scipy import signal

# periodogram (one-sided, frequencies in cycles per hour)
f, P = signal.periodogram(y - y.mean(), fs=1.0)
periods = 1 / f[1:]                      # hours

# averaged estimate (Welch, two-week segments) - consistent, lower variance
fw, Pw = signal.welch(y - y.mean(), fs=1.0, nperseg=24*14)

# coherence between sensor and reference, by period
fc, C = signal.coherence(s, y, fs=1.0, nperseg=24*14)
for p in [48, 24, 12, 8, 4]:
    i = np.argmin(abs(1/fc[1:] - p))
    print(f"coherence at {p} h: {C[1:][i]:.2f}")

In R, spec.pgram() computes smoothed periodograms and, for two series, their coherence.

6. An application

We used spectral analysis to compare hourly PM2.5 from PurpleAir low-cost sensors with EPA monitors in Cook County, Illinois, over October 2019 to September 2021. Corrected sensor data matched the reference over medium and long time scales, but not over the short term, where traffic-related variation appears. Both the standard US-wide correction and a local regression correction failed over the short term, and the corrected sensor data captured only a small fraction of the 8-hour peak. This is consistent with Proposition 6: a regression with constant coefficients cannot treat all time scales equally, which points toward frequency-based calibration. Details are in Kumar et al. (2023).

Exercises

  1. Under the sensor model of Section 4, show that \(C(\nu) = \dfrac{|G|^2 f_y}{|G|^2 f_y + f_e}\) and \(H^\star = \dfrac{\overline{G}\, f_y}{|G|^2 f_y + f_e}\). Interpret both.
    Show answer

    \(\operatorname{Cov}(y_{t+h}, s_t) = \sum_j g_j\gamma_y(h+j)\), whose spectrum is \(\overline{G} f_y\), so \(f_{ys} = \overline G f_y\). By Proposition 4, \(f_s = |G|^2f_y + f_e\). Substituting gives both formulas. Coherence is a signal-to-noise ratio at each frequency: close to 1 where the sensor's response to \(y\) dominates its noise, and close to 0 where noise dominates. The Wiener filter inverts \(G\) where the signal is strong (\(H^\star\approx 1/G\) when \(f_e \ll |G|^2 f_y\)) and shrinks toward zero where it is weak, instead of amplifying noise.

  2. Show that a daily profile that is a pure sinusoid, \(d_t = A\cos(2\pi t/24 + \phi)\), gives a peak only at 24 hours, while \(d_t = A\cos(2\pi t/24) + B\cos(2\pi t/12)\) also peaks at 12 hours. What does this say about reading the 12-hour peak in real data?
    Show answer

    A pure sinusoid has Fourier coefficients only at \(n = \pm1\) in Lemma 5, so only the 24 h period appears. The second profile has coefficients at \(n=\pm1\) and \(n=\pm2\), so it peaks at 24 h and 12 h. Any daily profile that is not a pure sinusoid, such as one with two rush hours, contains such harmonics. A 12-hour peak alone therefore does not prove a separate 12-hour process; it may simply reflect the shape of the daily cycle.

  3. Suppose \(\bar I\) is the average of \(L\) independent periodogram values, each distributed as \(f\cdot\mathrm{Exp}(1)\). Find the distribution of \(2L\bar I/f\) and a 95% confidence interval for \(f\) when \(L = 8\).
    Show answer

    Each \(2I/f \sim \chi^2_2\), so \(2L\bar I/f \sim \chi^2_{2L}\). With \(2L = 16\), the 2.5% and 97.5% quantiles are 6.91 and 28.85, so a 95% interval is \(\big[16\bar I/28.85,\ 16\bar I/6.91\big] \approx [0.55\,\bar I,\ 2.32\,\bar I]\). Even after averaging eight values, the interval spans a factor of about four. This is why single periodogram peaks should be read with care.

References

  • Brockwell, P. J., and Davis, R. A. (1991). Time Series: Theory and Methods (2nd ed.). Springer.
  • Percival, D. B., and Walden, A. T. (1993). Spectral Analysis for Physical Applications. Cambridge University Press.
  • Welch, P. D. (1967). The use of fast Fourier transform for the estimation of power spectra. IEEE Transactions on Audio and Electroacoustics, 15(2), 70–73.
  • Wiener, N. (1949). Extrapolation, Interpolation, and Smoothing of Stationary Time Series. MIT Press.
  • Kumar, V., Senarathna, D., Gurajala, S., Olsen, W., Sur, S., Mondal, S., and Dhaniyala, S. (2023). Spectral analysis approach for assessing the accuracy of low-cost air quality sensor network data. Atmospheric Measurement Techniques, 16, 5415–5427.