Question: The code below generates a 3 - beat ECG signal and then adds powerline interference at 6 0 Hz along with its harmonics at 1

The code below generates a 3-beat ECG signal and then adds powerline interference at 60 Hz along with its harmonics at 180 Hz and 300 Hz. Run the code in MATLAB and explain the purpose of the chosen filter.
Then, add an additional harmonic at 400 Hz to the noise signal and modify the filter by adding a zero at this frequency to remove the 400 Hz harmonic from the ECG signal. Include all 5 resulting figures with a brief explanation for each.
MATLAB CODE:
clear all, close all
% Step 1: Define parameters
fs =1000; % Sampling frequency (500 Hz)
T =3; % Duration in seconds for 3 beats
t =0:1/fs:T-(1/fs); % Time vector
% Step 2: Create sine signal (pretend ECG)
single_beat = sin(2* pi *1* t(1:end/3)); % Replace with a sine wave for testing
single_beat = single_beat / max(abs(single_beat)); % Normalize signal
num_beats =3;
ecg_signal = repmat(single_beat, 1, num_beats);
t_ecg =0:1/fs:(length(ecg_signal)-1)/fs;
% Step 3: Add power line interference
f_noise1=60; f_noise2=180; f_noise3=300;
noise =0.2* sin(2* pi * f_noise1* t_ecg)+...
0.1* sin(2* pi * f_noise2* t_ecg)+...
0.05* sin(2* pi * f_noise3* t_ecg);
noisy_ecg = ecg_signal + noise;
% Step 4: Plot noisy ECG signal
figure; plot(t_ecg, noisy_ecg, 'r');
title('Noisy Sine Signal');
xlabel('Time (s)'); ylabel('Amplitude'); grid on;
% Step 5: Power Spectral Density
[psd_values, f]= pwelch(noisy_ecg, [],[],[], fs);
figure; plot(f,10*log10(psd_values));
title('Power Spectral Density'); xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
grid on;
% Step 6: Design comb filter
f0=[f_noise1, f_noise2, f_noise3];
z =[];
for i =1:length(f0)
theta =2* pi * f0(i)/ fs;
z =[z, exp(1j*theta), exp(-1j*theta)];
end
b = poly(z); a =1; % Filter coefficients
% Step 7: Apply comb filter
filtered_ecg = filter(b, a, noisy_ecg);
% Step 8: Plot filtered ECG
figure; plot(t_ecg, filtered_ecg, 'b');
title('Filtered Sine Signal');
xlabel('Time (s)'); ylabel('Amplitude');
grid on;
% Step 9: Frequency Response
figure; freqz(b, a,1024, fs);
title('Frequency Response of Comb Filter');
grid on;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!