0% found this document useful (0 votes)
7 views

BECE301P: Digital Signal Processing Lab Task 4

The document details applying Butterworth and Chebyshev filters to an ECG signal. It loads an ECG signal, designs the filters, applies them to the signal, and plots the original, filtered signals and filter frequency responses in both the time and frequency domains. The plots show that the filters successfully remove unwanted frequencies while retaining the key features of the ECG signal.

Uploaded by

Aahan Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

BECE301P: Digital Signal Processing Lab Task 4

The document details applying Butterworth and Chebyshev filters to an ECG signal. It loads an ECG signal, designs the filters, applies them to the signal, and plots the original, filtered signals and filter frequency responses in both the time and frequency domains. The plots show that the filters successfully remove unwanted frequencies while retaining the key features of the ECG signal.

Uploaded by

Aahan Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

BECE301P: Digital Signal Processing Lab

TASK 4

Slot: L19+L20
Sai Deekshita Chaganty – 21BML0127
Aahan Jain – 21BML0159
S Padma – 21BML0107
Code:
% Step 1: Load the ECG signal
ecg = load('ecg2.dat');
fs = 1000; % Sampling frequency in Hz
t = (0:length(ecg)-1) / fs;

% Step 2: Design Butterworth and Chebyshev filters


fc_low = 0.5; % Lower cutoff frequency in Hz
fc_high = 275; % Upper cutoff frequency in Hz
fc_high_stop = 300; % Stopband frequency in Hz
order = 6; % Filter order

% Butterworth filter
[b_butter, a_butter] = butter(order, [fc_low/(fs/2), fc_high/(fs/2)],
'bandpass');

% Chebyshev Type I filter


rp = 0.1; % Passband ripple in dB
rs = 60; % Stopband attenuation in dB
[b_cheby, a_cheby] = cheby1(order, rp, [fc_low/(fs/2), fc_high/(fs/2)],
'bandpass');

% Step 3: Apply filters to the ECG signal


ecg_filtered_butter = filtfilt(b_butter, a_butter, ecg);
ecg_filtered_cheby = filtfilt(b_cheby, a_cheby, ecg);

% Step 4: Plot original ECG signal in time domain and frequency domain
figure;
subplot(2,1,1);
plot(t, ecg);
xlabel('Time (s)');
ylabel('Amplitude');
title('Original ECG Signal');

subplot(2,1,2);
NFFT = 2^14;
f = fs/2*linspace(0,1,NFFT/2+1);
ecg_fft = fft(ecg, NFFT);
ecg_fft_mag = abs(ecg_fft(1:NFFT/2+1));
plot(f, 20*log10(ecg_fft_mag));
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
title('Magnitude Spectrum of Original ECG Signal');
xlim([0 fs/2]);

% Step 5: Plot magnitude spectrum of filters and filtered ECG signals


figure;
subplot(2,1,1);
[butter_freq, butter_resp] = freqz(b_butter, a_butter, NFFT, fs);
plot(butter_freq, 20*log10(abs(butter_resp)));
hold on;
[ecg_filtered_butter_fft, f_butter] = pwelch(ecg_filtered_butter, [], [],
NFFT, fs);
plot(f_butter, 20*log10(ecg_filtered_butter_fft), 'r');
hold off;
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
title('Butterworth Filter and Filtered ECG Spectrum');
legend('Butterworth Filter', 'Filtered ECG Signal');
xlim([0 fs/2]);

subplot(2,1,2);
[cheby_freq, cheby_resp] = freqz(b_cheby, a_cheby, NFFT, fs);
plot(cheby_freq, 20*log10(abs(cheby_resp)));
hold on;
[ecg_filtered_cheby_fft, f_cheby] = pwelch(ecg_filtered_cheby, [], [],
NFFT, fs);
plot(f_cheby, 20*log10(ecg_filtered_cheby_fft), 'r');
hold off;
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
title('Chebyshev Filter and Filtered ECG Spectrum');
legend('Chebyshev Filter', 'Filtered ECG Signal');
xlim([0 fs/2]);

% Step 6: Plot time domain representations of original and filtered ECG


signals
figure;
subplot(2,1,1);
plot(t, ecg);
hold on;
plot(t, ecg_filtered_butter, 'r');
hold off;
xlabel('Time (s)');
ylabel('Amplitude');
title('Original and Butterworth Filtered ECG Signals');
legend('Original ECG', 'Filtered ECG');

subplot(2,1,2);
plot(t, ecg);
hold on;
plot(t, ecg_filtered_cheby, 'r');
hold off;
xlabel('Time (s)');
ylabel('Amplitude');
title('Original and Chebyshev Filtered ECG Signals');
legend('Original ECG', 'Filtered ECG');
Output:
Inference:
 In the time domain representation, the ECG signal shows characteristic patterns
associated with cardiac activity, including P waves, QRS complexes, and T waves.
 In the magnitude spectrum, the dominant frequencies correspond to the heart rate
and its harmonics, with higher amplitudes in the low-frequency range.
 The magnitude spectrum of the Butterworth filter shows a clear attenuation in the
stopband region (0-0.5 Hz and 275-300 Hz), indicating effective suppression of
unwanted frequencies.
 The magnitude spectrum of the filtered ECG signal after applying the Butterworth
filter shows reduced power in the stopband region, confirming the successful
removal of unwanted frequencies.
 Comparing the time domain representations of the original and filtered ECG
signals, we observe that the filtered signal retains the overall morphology and
timing of the original signal.
 However, the filtered signal appears smoother, with reduced amplitude
fluctuations, especially in the frequency bands targeted by the filter.
The plots indicate that both the Butterworth and Chebyshev filters effectively remove
unwanted frequencies from the ECG signal while retaining its essential features. The
filtered signals show reduced power in the specified stopband regions, confirming
successful filtering. However, the Chebyshev filter may require additional
optimization to address potential instability issues observed during design.

You might also like