|
| 1 | +# Notch / Comb Filter |
| 2 | + |
| 3 | +## Overview & Motivation |
| 4 | + |
| 5 | +Narrow-band interference — mains hum at 50/60 Hz and its harmonics — contaminates bio-signal |
| 6 | +acquisition (ECG, EEG, EMG) and precision instrumentation. A notch filter surgically eliminates |
| 7 | +a single frequency while leaving the rest of the spectrum intact. A comb filter extends this idea |
| 8 | +to an entire harmonic series using a single delay line, making it far more efficient than cascading |
| 9 | +individual notches when the interference is periodic. |
| 10 | + |
| 11 | +## Mathematical Theory |
| 12 | + |
| 13 | +### Notch Filter (RBJ Biquad) |
| 14 | + |
| 15 | +The continuous-time transfer function for a band-reject filter with centre frequency $f_0$ and |
| 16 | +quality factor $Q$ is: |
| 17 | + |
| 18 | +$$H(s) = \frac{s^2 + \omega_0^2}{s^2 + \frac{\omega_0}{Q}s + \omega_0^2}$$ |
| 19 | + |
| 20 | +Applying the bilinear transform with $\omega_0 = 2\pi f_0 / f_s$, the discrete-time biquad |
| 21 | +coefficients (Bristow-Johnson "Cookbook" notch) are: |
| 22 | + |
| 23 | +$$\alpha = \frac{\sin(\omega_0)}{2Q}, \quad c_\omega = \cos(\omega_0)$$ |
| 24 | + |
| 25 | +$$b_0 = b_2 = \frac{1}{1+\alpha}, \quad b_1 = \frac{-2c_\omega}{1+\alpha}$$ |
| 26 | + |
| 27 | +$$a_1 = \frac{-2c_\omega}{1+\alpha}, \quad a_2 = \frac{1-\alpha}{1+\alpha}$$ |
| 28 | + |
| 29 | +The zeros lie exactly on the unit circle at $e^{\pm j\omega_0}$, guaranteeing infinite attenuation |
| 30 | +at $f_0$ in exact arithmetic. |
| 31 | + |
| 32 | +Transposed Direct Form II (TDF-II) realises this with two state variables $z_1, z_2$: |
| 33 | + |
| 34 | +$$y[n] = b_0 x[n] + z_1[n-1]$$ |
| 35 | +$$z_1[n] = b_1 x[n] - a_1 y[n] + z_2[n-1]$$ |
| 36 | +$$z_2[n] = b_2 x[n] - a_2 y[n]$$ |
| 37 | + |
| 38 | +### Comb Filter |
| 39 | + |
| 40 | +A comb filter exploits the identity: subtracting (or adding) a signal delayed by $D$ samples |
| 41 | +creates periodic nulls (or peaks) spaced every $f_s / D$ Hz: |
| 42 | + |
| 43 | +**Feedforward (FIR) comb:** |
| 44 | + |
| 45 | +$$y[n] = x[n] - g \cdot x[n-D]$$ |
| 46 | + |
| 47 | +Zeros at $\omega = 2\pi k / D$ for $k = 0, 1, \ldots, D-1$. The system is always stable. |
| 48 | + |
| 49 | +**Feedback (IIR) comb:** |
| 50 | + |
| 51 | +$$y[n] = x[n] + g \cdot y[n-D]$$ |
| 52 | + |
| 53 | +Poles at the same locations. The system is stable if and only if $|g| < 1$. |
| 54 | + |
| 55 | +## Complexity Analysis |
| 56 | + |
| 57 | +| Case | Time | Space | Notes | |
| 58 | +|-------|--------|--------|-----------------------------------| |
| 59 | +| Notch | $O(1)$ | $O(1)$ | Fixed biquad; 2 multiplies/adds | |
| 60 | +| Comb | $O(1)$ | $O(D)$ | Single circular-buffer read/write | |
| 61 | + |
| 62 | +## Step-by-Step Walkthrough |
| 63 | + |
| 64 | +**Notch example** — $f_0 = 50$ Hz, $f_s = 1000$ Hz, $Q = 10$: |
| 65 | + |
| 66 | +1. $\omega_0 = 2\pi \cdot 0.05 \approx 0.3142$ |
| 67 | +2. $c_\omega = \cos(0.3142) \approx 0.9511$, $\alpha = \sin(0.3142)/(20) \approx 0.01564$ |
| 68 | +3. $a_0 = 1.01564$; divide all coefficients by $a_0$ |
| 69 | +4. $b_0 = b_2 \approx 0.9846$, $b_1 = a_1 \approx -1.8730$, $a_2 \approx 0.9693$ |
| 70 | +5. At each sample: compute $y = b_0 x + z_1$, then update $z_1, z_2$. |
| 71 | + |
| 72 | +**Comb example** — $D = 4$, $g = 1$ (FIR): |
| 73 | + |
| 74 | +Impulse response: $[1, 0, 0, 0, -1, 0, 0, 0, 0, \ldots]$ — zeros at 0, fs/4, fs/2, 3fs/4. |
| 75 | + |
| 76 | +## Pitfalls & Edge Cases |
| 77 | + |
| 78 | +- **High Q instability**: a very narrow notch ($Q \gg 10$) places poles close to the unit circle. |
| 79 | + Finite-precision arithmetic can shift them outside, causing instability. Use double precision or |
| 80 | + second-order-section cascades when $Q > 30$. |
| 81 | +- **Detuned comb**: if $f_s$ is not an exact integer multiple of the harmonic spacing, the comb |
| 82 | + nulls misalign and leave residual hum. Prefer a sample rate that divides evenly, or cascade |
| 83 | + individual biquad notches. |
| 84 | +- **Feedback comb stability**: gain must satisfy $|g| < 1$ with margin. Values near 1 produce |
| 85 | + extremely long ring-down and amplify quantisation noise. |
| 86 | +- **DC gain**: the RBJ notch has unity gain at DC and Nyquist; FIR comb has gain $(1 - g)$ at DC. |
| 87 | + |
| 88 | +## Variants & Generalizations |
| 89 | + |
| 90 | +- **Notch with adjustable bandwidth**: replace the fixed $Q$ with an adaptive estimator tracking |
| 91 | + the instantaneous interference frequency (e.g., a phase-locked loop). |
| 92 | +- **All-pass + notch cascade**: derive a steep-skirt band-stop by cascading a notch with an |
| 93 | + all-pass tuned to the same frequency. |
| 94 | +- **Comb as reverberator**: adding (instead of subtracting) a delayed, attenuated copy produces |
| 95 | + artificial reverberation (Schroeder comb). |
| 96 | +- **Multi-rate comb**: operate the comb at a lower decimated rate, then interpolate — reduces |
| 97 | + delay-line length proportionally. |
| 98 | + |
| 99 | +## Applications |
| 100 | + |
| 101 | +- Bio-signal acquisition: removing 50/60 Hz mains hum and harmonics from ECG/EEG/EMG. |
| 102 | +- Power-line harmonic suppression in current/voltage sensors. |
| 103 | +- Audio effects: chorus, flange, reverberation. |
| 104 | +- Synchronous sampling: align comb nulls with switching-converter ripple harmonics. |
| 105 | + |
| 106 | +## Connections to Other Algorithms |
| 107 | + |
| 108 | +- **BiquadCascade** — the notch is a single biquad section; a cascade realizes higher-order |
| 109 | + band-stop designs with better numerical conditioning. |
| 110 | +- **IirFilterDesign** — a band-stop Butterworth/Chebyshev design from a bilinear transform |
| 111 | + produces a family of notches; the RBJ notch here is the minimal single-section special case. |
| 112 | +- **GoertzelAlgorithm** — detects the frequency that the notch removes; useful for adaptive |
| 113 | + centre-frequency tuning. |
| 114 | + |
| 115 | +## References & Further Reading |
| 116 | + |
| 117 | +- R. Bristow-Johnson, "Cookbook formulae for audio EQ biquad filter coefficients", |
| 118 | + <https://www.w3.org/TR/audio-eq-cookbook/> |
| 119 | +- R. G. Lyons, *Understanding Digital Signal Processing*, 3rd ed., Prentice Hall, 2011, Ch. 6. |
| 120 | +- A. V. Oppenheim & R. W. Schafer, *Discrete-Time Signal Processing*, 3rd ed., Ch. 5. |
0 commit comments