Notch Filter to remove noise from an ECG Signal

This experiment is based on a question at the Lab Exam (EN1093).

According to the following difference equation which relates output (y[n]) and input (x[n]) we were asked to derive the transfer function H(z). This filter removes the 50Hz noise component.

Download the ECG signal distorted with noise (.mat)

Difference equation and transfer function

Taking the Z-transform with zero initial conditions:

Pole-zero plot

MATLAB pole-zero plot of the notch filter, showing poles and zeros near the unit circle.
num=[0.9955 -1.8936 0.9955];
den=[1 -1.8936 0.9911];

zplane(num,den)
grid on;

%freqz(num,den,100);

MATLAB code to implement the notch filter

Place the downloaded noisy_ECG_sig.mat file in the MATLAB working directory before running this code.

close all;
clear all;

load('noisy_ECG_sig.mat')
y=noisy_ECG_sig; %the signal loaded
L=length(y)
sampling_freq = 1000


figure; % plot the original signal
plot([1:2570],y);
title('Original ECG Signal')

% Question 2) plot the frequency response of both the original signal(noisy_ECG_sig) and the filtered signal Yn

%% plot frequency response of the original signal %%
NFFT=2^nextpow2(L);
f = sampling_freq/2*linspace(0,1,NFFT/2+1);
Y=fft(y,NFFT)/L;
figure, plot(f,2*abs(Y(1:NFFT/2+1)));
title('frequency response of the original signal');
ylabel('amplitude');
xlabel('frequency');
%%  %%


num=[0.9955 -1.8936 0.9955];
den=[1 -1.8936 0.9911];
filtered_y = filter(num,den,y);

%% plot frequency response of the filtered signal %%
NFFT=2^nextpow2(L);
f = sampling_freq/2*linspace(0,1,NFFT/2+1);
f_Y=fft(filtered_y,NFFT)/L;
figure, plot(f,2*abs(f_Y(1:NFFT/2+1)));
title('frequency response of the filtered signal');
ylabel('amplitude');
xlabel('frequency');
%% %%


figure;
plot([1:2570],filtered_y); % plot the filtered signal
title('Filtered ECG Signal')

% Question 3) By observing the distinct changes in the frequency components
% in the above frequency plots, predict the nature of the filter

fvtool(num,den)

%q4) verify your results using 'fvtool' matlab function

Implementation output

Figure 1:

For further reading

What do the zeros of a transfer function tell you about a system?

Control Systems: Poles and Zeros (Wikibooks)

MIT handout on poles and zeros (PDF)

Adding noise to an ECG signal

KUDOSDon’t
Move
Thanks!