Library / Signal processing and digital filters / DSP-31
Signal processing and digital filters
Moving-average magnitude response
Magnitude response of an M-tap moving average with weights 1/M, normalised to one at DC, for 0 ≤ f ≤ fs/2.
- Ref
- DSP-31
- Rev
- v1
- Field
- Signal processing and digital filters
- Result
- G
An M-tap moving average with weights 1/M has the response sin(πMf/fs)/(M sin(πf/fs)), which equals sinc(Mf/fs)/sinc(f/fs) in the normalised form used here. It is one at DC, has nulls at multiples of fs/M, and has high sidelobes, so it removes noise but does not filter sharply.
Magnitude response of an M-tap moving average with weights 1/M, normalised to one at DC, for 0 ≤ f ≤ fs/2. The nulls fall at nonzero multiples of fs/M within the band, and the sidelobes are high.
Calculator
- Gain in dB−2.277 dB
- First null frequency, fs/M250 Hz
- Noise variance reduction factor, 1/M0.25
What drives the result
Each variable is moved across its typical range while the others stay at the values above. The longest bar is the key driver.
- At 100 Hz the 4-point moving average passes 0.7694 of the signal amplitude (−2.28 dB).
- The first null is at 250 Hz, and white noise power falls by the factor 0.25, which is the trade between noise reduction and bandwidth.
Chart data as tables
Ranked variables
| Variable | Typical range | Lowest result | Highest result | Swing () | Local step | Change in result |
|---|---|---|---|---|---|---|
| M Number of taps | 1 to 64 taps | 3.963e-17 | 1 | 1 | +1 taps | −15.9 % |
| f Frequency | 0 to 500 Hz | 4.33e-17 | 1 | 1 | +10% | −5.78 % |
| fs Sampling rate | 250 to 1,000,000 Hz | 0.0935 | 1 | 0.9065 | +10% | +4.91 % |
Sweep of Frequency
| Frequency (Hz) | Gain relative to DC |
|---|---|
| 0 | 1 |
| 62.5 | 0.9061 |
| 125 | 0.6533 |
| 187.5 | 0.3182 |
| 250 | 4.33e-17 |
| 312.5 | 0.2126 |
| 375 | 0.2706 |
| 437.5 | 0.1802 |
| 500 | 6.123e-17 |
Sweep one variable
Variables and how each one contributes
Gain relative to DC
What the equation gives you. Everything else feeds it.
Number of taps
The number of taps (weights 1/M each). More taps lower the cutoff and narrow the main lobe, with nulls at fs/M. Raising it by 10 % (to 4.4) moves the result by +0 %, from 0.7694 to 0.7694.
Frequency
The frequency, in Hz, up to fs/2. Higher frequencies are attenuated, with nulls at multiples of fs/M. Raising it by 10 % (to 110) moves the result by −5.78 %, from 0.7694 to 0.725.
Sampling rate
The sampling rate, in Hz. A higher rate makes a given frequency a smaller fraction of fs, so it passes better. Raising it by 10 % (to 1,100) moves the result by +4.91 %, from 0.7694 to 0.8072.
Worked example with the values above
- Numerator: sinc(Mf/fs) = sinc(0.4) = 0.75683.
- Denominator: sinc(f/fs) = sinc(0.1) = 0.98363.
- G = |0.75683 / 0.98363| = 0.76942.
Assumptions and limits
- Equally spaced samples, and noise that is uncorrelated from sample to sample.
- A signal that is smooth over the filter span, so a local quadratic fit describes it.
Common mistakes
- Using these filters at the ends of a record, where the window is incomplete.
- Forgetting that centred filters add a delay of half the window length in real-time use.
- Using a moving average where the sinc sidelobes let high frequencies leak through.
Statistics and uncertainty
Smoothing reduces random error and adds bias, which cannot both be small. A Savitzky–Golay fit lowers the noise variance by the factor Σc² (here 0.49) but flattens any curvature of higher order than a quadratic.
Where it is used
- Smoothing sensor signals and estimating velocity from position records.
- Predicting the noise reduction and frequency response of simple FIR smoothers.
Maths you need
- Moving average: the mean of the latest M samples
- Least-squares fit: the polynomial that minimises squared error
- Noise power gain: Σh² for an FIR filter