How to Filter Noise in ECG and EEG Signals Using MATLAB

Table of Contents

Identifying cardiovascular and neurological diseases relies in large part on using ECG and EEG biomedical signals. They usually end up distorted because of noise, interference from nearby power lines, muscle movements and baseline wander. Noise removal is a pre-processing stage that increases signal quality further analysis. The tutorial takes you through the noise filtering process of ECG and EEG signals in MATLAB while covering FIR/IIR filters and Wavelet Transforms. Learning How to Pre-process and Clean Biomedical Signals using FIR/IIR Filters and Wavelet Transforms

📌 Why Filter ECG and EEG Signals?

Noise in ECG and EEG Signals Using MATLAB, Filtering is an important step in biomedical signal processing because it helps to:

• Deletes irrelevant artifacts (e.g., EMG noise, eye blink, powerline noise)

• Improve Signal Noise Ratio (SNR)

• Improve the capacity of correct diagnosis

• Prepare signals for feature extraction and machine learning

 

🛠️ Tools Used:

MATLAB

• Signal Processing Toolbox

• Wavelet Toolbox

 

🎯 Objective:

Understand the application of FIR and IIR filters

• Use Wavelet Transforms for advanced noise removal

• Visualize the results in MATLAB

1. Loading the Signal

Begin by loading the biomedical signal. You can utilize real data (e.g., PhysioNet) or MATLAB's in-built datasets.

 

load('ecg.mat'); % Example ECG signal

fs = 360; % Sampling frequency

t = (0:length(ecg)-1)/fs;

plot(t, ecg); title('Raw ECG Signal');

 

2. Applying FIR Filter

FIR (Finite Impulse Response) filters stay stable and show linear phase traits.

Low-Pass Filter to Get Rid of High-Frequency Noise

 

lpFilt = designfilt('lowpassfir', 'PassbandFrequency', 40, ...

                    'StopbandFrequency', 50, ...

                    'SampleRate', fs);

ecg_fir = filter(lpFilt, ecg);

 

plot(t, ecg_fir); title('FIR Filtered ECG Signal');

 

3. Applying IIR Filter

IIR (Infinite Impulse Response) filters work well and make sharp transitions.

Band-Pass Filter for ECG (0.5 – 40 Hz)

 

bpFilt = designfilt('bandpassiir','FilterOrder',6, ...

         'HalfPowerFrequency1',0.5,'HalfPowerFrequency2',40, ...

         'SampleRate',fs);

ecg_iir = filtfilt(bpFilt, ecg);

 

plot(t, ecg_iir); title('IIR Filtered ECG Signal');

 

4. Wavelet Transform for Denoising

Wavelet Transform works best for signals that change over time such as EEG and ECG.

 

[thr,sorh,keepapp] = ddencmp('den','wv',ecg);

ecg_wave = wdencmp('gbl', ecg, 'db6', 6, thr, sorh, keepapp);

 

plot(t, ecg_wave); title('Wavelet Denoised ECG Signal');

You can replace 'db6' with other wavelets (e.g., 'sym4', 'coif3') and adjust the level for better results.

5. EEG Signal Processing (Example)

The same approach can be applied to EEG:

  • Band-pass filter between 0.5 Hz and 50 Hz
  • Use wavelet denoising to remove eye-blink and muscle artifacts

load('eeg.mat'); % EEG signal

bpEEG = bandpass(eeg, [0.5 50], fs);

eeg_wave = wden(bpEEG, 'sqtwolog', 's', 'mln', 5, 'db4');

 

plot(t, eeg_wave); title('Filtered EEG Signal');

 

Results Comparison

Method

Pros

Cons

FIR Filter

Linear phase, stable

Requires higher order

IIR Filter

Efficient, sharp cutoff

Non-linear phase

Wavelet Transform

Adaptive to signal characteristics

Complex to tune

Conclusion

By using FIR/IIR filters and wavelet transforms to pre-process signals processing in MATLAB it can substantially enhance the quality of the data for this study. Using MATLAB is a mixture of classical and advanced techniques, when used correctly, will bring significant noise reduction to the signals and therefore the potential performance of the diagnostic algorithms.

Final year projects