Report Exp5
Report Exp5
Experiment 5 report
The goal of this task is to improve the quality of an ECG (Electrocardiogram) signal by
reducing noise and enhancing the important elements of the signal. The raw ECG data,
typically affected by noise from various physiological and external sources, requires filtering
to isolate diagnostically significant features. The stability and predictability of Finite Impulse
Response (FIR) filters in signal processing make them ideal for this task. Here, the ECG signal
was subjected to several FIR filters with different orders and frequency ranges in order to assess
how well they reduced noise and protected features and through a combination of Butterworth
and Finite Impulse Response (FIR) filtering techniques.
• Procedure
Task1:
1. Original ECG Signal: To detect noise contamination the original, unprocessed ECG signal
was first plotted.
2. Filter Design:
- Four FIR filters (Finite Impulse Response), each with different orders and characteristics,
were designed to target noise in the ECG signal. Each filter configuration had a specific
frequency range and filter order:
- b1b1: Bandpass filter, order 3, with a range of 0.9 Hz to 59 Hz.
- b2b2: Low-pass filter, order 6, covering the same frequency range.
- b3b3: Low-pass filter, order 15, within the same frequency range.
- b4b4: Low-pass filter, order 30, within the same frequency range.
3. Filtering Process:
Each filtered signal 𝑦𝑖yi (where 𝑖i ranges from 1 to 4) was obtained by applying the respective
filter 𝑏𝑖bi to the original signal 𝑥x. The filtered ECG signals for each filter are displayed in
subsequent plots. The filter's ability to eliminate noise and preserve its original signal
components improves with increasing filter order.
4. Additional Filters:
- Three additional FIR filters were designed to target specific frequency bands:
Task 2:
1. Butterworth Filter Application:
A second-order Butterworth bandpass filter with cutoff frequencies of 0.9 Hz and 59 Hz was
designed to reduce noise in the ECG signal. This bandpass configuration focuses on preserving
important ECG features while excluding higher- and lower-frequency noise.
The filtered signal 𝑦7y7 was obtained by applying the Butterworth filter to the original signal
𝑥1x1.
A plot comparing the original and Butterworth-filtered signals illustrates the effectiveness of
the Butterworth filter in noise reduction while retaining the essential ECG waveform.
2. Frequency Response Analysis:
The frequency response of the Butterworth filter was calculated and plotted to visualize its
amplitude response across frequencies.
This analysis confirmed the filter’s bandpass characteristics, indicating that it effectively
attenuates frequencies outside the specified range, further validating its suitability for ECG
filtering.
3. FIR Filter Application:
An FIR filter with a moving average impulse response was designed and applied to the
Butterworth-filtered signal 𝑦7y7 twice sequentially, resulting in filtered signals y8y8 and 𝑦9y9.
The FIR filter aims to further smooth the signal and attenuate any remaining noise components.
Plots of the sequentially FIR-filtered signals show how the signal becomes progressively
smoother and less noisy with each iteration.
• Results and discussion
TASK1:
Clear
clc
close all
load('lead3.mat');
fs= 1000
t = [1:length(lead3)]/fs;
figure;
plot(t, lead3)
xlabel('Time (s)')
ylabel('Amplitude')
title('original ECG Signal')
a=1
b1 = fir1 (3, [0.9 59]/(fs/2), 'bandpass')
b2 = fir1(6, [0.9 59]/(fs/2), 'bandpass')
b3 = fir1(15, [0.9 59]/(fs/2), 'bandpass')
b4 = fir1(30, [0.9 59]/(fs/2), 'bandpass')
y1 = filter(b1, a, lead3)
y2 = filter(b2, a, lead3)
y3 = filter(b3, a, lead3)
y4 = filter(b4, a, lead3)
figure
subplot(2,2,1)
plot(t, y1)
xlabel('Time (s)')
ylabel('Amplitude')
title('Filtered ECG,Y1')
subplot(2,2,2)
plot(t, y2)
xlabel('Time (s)')
ylabel('Amplitude')
title('Filtered ECG, Y2')
subplot(2,2,3)
plot(t, y3)
xlabel('Time (s)')
ylabel('Amplitude')
title('Filtered ECG,Y3')
subplot(2,2,4)
plot(t, y4)
xlabel('Time (s)')
ylabel('Amplitude')
title('Filtered ECG, Y4')
y5 = filter(b5, a, lead3);
y6 = filter(b6, a, lead3);
figure
subplot(3,1,1)
plot(t, y2)
xlabel('Time (s)')
ylabel('Amplitude')
title('Filtered ECG, Y2')
subplot(3,1,2)
plot(t, y5)
xlabel('Time (s)')
ylabel('Amplitude')
title('Filtered ECG, Y5')
subplot(3,1,3)
plot(t, y6)
xlabel('Time (s)')
ylabel('Amplitude')
title('Filtered ECG,Y6');
TASK2:
clear
clc
close all
load('lead3.mat');
x1 = lead3;
fs2 = 1000;
t2 = [1:length(x1)] / fs2;
[z p] = butter(2,[0.9 59]/fs2/2,'bandpass');
y7 = filter(z,p,x1);
figure
subplot(2,1,1)
plot(t2,x1)
xlabel('time')
ylabel('voltage')
title('Original Signal')
subplot(2,1,2)
plot(t2,y7)
xlabel('time')
ylabel('voltage')
title('Butterworth Filtered Signal')
[h w] = freqz(z,p,512,fs2);
mag = abs(h)
figure
plot(w, mag)
a=1
b = (1/20)*ones(1,20);
[h w] = freqz(b,a,512,fs2)
mag = abs(h)
figure
plot(w, mag)
y8 = filter(b,a,y7);
y9 = filter(b,a,y8);
figure
subplot(3,1,1)
plot(t2,y7)
xlabel('time')
ylabel('amplitude')
title('Butterworth Filtered Signal')
subplot(3,1,2)
plot(t2,y8)
xlabel('time')
ylabel('amplitude')
title('1st Time Moving Average Filtered Signal')
subplot(3,1,3)
plot(t2,y9)
xlabel('time')
ylabel('amplitude')
title('2nd Time Moving Average Filtered Signal')
This task's filtering procedure showed how well the FIR and Butterworth filters reduced noise
and improved the quality of the ECG data. Initially, FIR filters with greater orders were used,
demonstrating that while they raised processing demands, higher orders enhanced noise
absorption, especially for low-pass filters. This incremental increase from 𝑦 1 y 1 to 𝑦 4 y 4
shows how filter order affects filtering performance.
Additional FIR filters, such 𝑏 5b 5 and 𝑏 6b 6, were made to separate frequency bands, which
may be helpful in eliminating interference. A balance is necessary since too much filtering
could skew diagnostic features like the QRS complex and P-waves.
In order to effectively attenuate undesirable frequencies while maintaining essential ECG
components, the second-order Butterworth filter used a bandpass design to offer broad noise
reduction. Through frequency response analysis, this was confirmed, demonstrating the filter's
suitability for specific noise reduction. For high-fidelity monitoring or diagnostic applications,
sequential FIR filtering smoothed the Butterworth-filtered signal while maintaining its
structure.
In summary, the combination of the Butterworth and FIR filters worked very well to provide a
clean, dependable ECG signal that could be used for diagnostic purposes. To maintain the
ECG's diagnostic usefulness, filtering intensity and accuracy of signal must be balanced.