BECE301P: Digital Signal Processing Lab Task 4
BECE301P: Digital Signal Processing Lab Task 4
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;
% Butterworth filter
[b_butter, a_butter] = butter(order, [fc_low/(fs/2), fc_high/(fs/2)],
'bandpass');
% 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]);
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]);
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.