The Electrocardiogram (ECG or EKG) is the most fundamental physiological signal recorded in clinical and research settings. It captures the electrical activity of the heart over time. However, raw ECG data exported from devices like the Polar H10, OpenBCI, or BITalino is almost never ready for immediate analysis. It is typically contaminated by various noise sources that distort the true cardiac waveform.
To perform accurate Heart Rate Variability (HRV) calculations or QRS complex detection, the signal must be digitally filtered.
Understanding the ECG Waveform
A healthy, noise-free ECG consists of a standard sequence of electrical events representing a single heartbeat:
- P Wave: Represents atrial depolarization (contraction of the upper chambers). It is a small, low-frequency wave.
- QRS Complex: Represents ventricular depolarization (contraction of the lower chambers). This is the most prominent feature of the ECG, characterized by a sharp, high-amplitude spike. Identifying the R-peak is critical for calculating heart rate.
- T Wave: Represents ventricular repolarization (recovery of the lower chambers). It is typically a broader, lower-amplitude wave following the QRS complex.
The frequency content of a standard diagnostic ECG ranges from approximately 0.05 Hz to 150 Hz. Preserving this frequency band while eliminating noise outside it is the primary goal of ECG signal processing.
Common Noise Sources in ECG Recordings
When you upload a raw data file containing ECG data, you will likely encounter three primary types of interference:
- Baseline Wander (Low-Frequency Noise): This causes the entire ECG signal to drift up and down on the Y-axis. It is primarily caused by patient respiration (breathing) and electrode movement. It typically exists below 0.5 Hz.
- Powerline Interference (50 Hz or 60 Hz): Depending on your geographic location, ambient electromagnetic noise from the power grid will couple into your recording equipment. This appears as a thick, fuzzy sine wave superimposed over your entire ECG trace.
- EMG Artifacts (High-Frequency Noise): If the subject moves their chest muscles or shivers, high-frequency electromyographic (EMG) noise will corrupt the ECG trace. This noise shares frequency space with the QRS complex, making it difficult to remove without distorting the cardiac signal.
Recommended Butterworth Filtering Parameters for ECG
To clean an ECG signal, we use digital IIR (Infinite Impulse Response) filters. Specifically, a Zero-Phase Butterworth filter is ideal because it provides a maximally flat frequency response and, crucially, zero-phase filtering (forward and backward passes) ensures that the R-peaks are not shifted in time.
Common ECG filter starting point:
- High-Pass Filter: 0.5 Hz (Order 2 or 4)
Removes baseline wander caused by breathing while preserving the ST segment. - Notch Filter: 50 Hz or 60 Hz
Crucial for eliminating powerline interference. Choose based on your country's power grid. - Low-Pass Filter: 40 Hz to 150 Hz (Order 4)
For exploratory R-peak review, a 40 Hz low-pass strongly attenuates muscle noise. For waveform-shape review where P and T morphology matters, use 150 Hz when your sampling rate supports it.
How to Filter Your ECG Data Online
Analyzing your data using the BioSignal Workstation is straightforward:
- Export to Supported Format: Ensure your recording device exports data in a standard format (CSV, XLS, XLSX, or TXT) where columns represent channels and rows represent time samples.
- Upload privately: Drag and drop your file into our analyzer tool. Processing happens in your browser via Web Workers, and signal files are not uploaded to BioSignal Workstation servers. Users remain responsible for following their institution's privacy and data-handling requirements.
- Apply the ECG Preset: Click the "ECG" preset button in the configuration panel. This automatically populates the recommended 0.5 Hz High-Pass and 150 Hz Low-Pass values.
- Verify Sampling Rate: Ensure the Sampling Frequency (Hz) matches your hardware settings (e.g., 250 Hz, 500 Hz, or 1000 Hz). This is critical for the filter math to work correctly.
- Export Clean Data: Use the interactive chart to inspect your QRS complexes. Once satisfied, export the filtered array as a new file for further HRV analysis in Python or R.
Spectral Analysis (Welch PSD) of ECG
While ECG is primarily analyzed in the time domain, looking at the frequency domain via a Power Spectral Density (PSD) plot is an excellent way to verify filter performance. Before filtering, you will likely see a massive spike at 0 Hz (DC offset) and a sharp spike at 50/60Hz. After applying the Butterworth filters, the PSD should show a clean curve concentrated between 1 Hz and 30 Hz, with no powerline spikes.