ECG Noise Filtering
When a hospital ECG machine cleans the heartbeat trace before showing it to a cardiologist, it does this: take the noisy signal into the frequency domain, delete the bins that don't belong to a heart, take it back. Same maths drives every biosignal monitor on the planet.
The pipeline
Reference: Wikipedia — Low-pass filter; MIT 6.003 Signals & Systems, Lecture 20. Oppenheim, A. V., & Schafer, R. W. (2010). Discrete-Time Signal Processing, 3rd ed., Ch. 7.
🧪 Try these experiments in order
- Set noise = 0 and mains hum = 0. You see a clean heartbeat pattern. Note the regular spikes — those are the QRS complexes.
- Push mains hum to maximum. The 50 Hz interference swamps the trace — this is exactly what happens when an ECG cable runs too close to a power outlet.
- Now drag cutoff from 80 Hz down to 30 Hz. Watch the 50 Hz spike in the spectrum vanish, and the heart trace return cleanly underneath.
- Push noise to max too. Drag cutoff lower — at what frequency does the heartbeat start to lose its sharp R-spike?
Noisy input signal (what the electrode actually sees)
Magnitude spectrum (yellow = kept, red = filtered out)
Filtered output (what the cardiologist sees)
⚠ Watch out for
- Cutoff too low (below ~15 Hz) starts deleting the QRS spike itself — the R-wave goes round and smooth. In a real ICU this would hide arrhythmias.
- The brick-wall mask used here is what textbooks call an "ideal" filter — in real hardware it would introduce ringing (Gibbs again). Real ECG machines use gentler Butterworth or Chebyshev filters.
✅ Do
Pick the cutoff just above the highest frequency that carries information you care about (≈40 Hz for ECG diagnostics).
❌ Don't
Reuse the same cutoff for every signal. A 40 Hz lowpass is right for ECG, lethal for music (you'd lose every cymbal), wrong for EEG (cutoff ≈ 70 Hz).
Where this matters in industry
ICU and bedside ECG monitors, Holter recorders, fitness-tracker heart-rate algorithms, EEG/EMG biomedical work, seismometers, audio noise gates, power-line interference removal on every sensor that touches a mains-powered system.
🎯 Learning checkpoint
If you set the cutoff higher than 50 Hz, does the mains hum disappear? Why or why not? (Try it.)