Skip to content

Instantly share code, notes, and snippets.

@ramithuh
Created November 10, 2018 18:05
Show Gist options
  • Save ramithuh/6484cf73d26228f81182622a761b348c to your computer and use it in GitHub Desktop.
Save ramithuh/6484cf73d26228f81182622a761b348c to your computer and use it in GitHub Desktop.
Notch Filter
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
@MuhammmadUsman
Copy link

Where is .mat file? In your blog it is not downloadable and not even able to save this .mat file.

@ramithuh
Copy link
Author

Hey, apologies for the broken link.
I uploaded it now, https://blog.ramith.fyi/static/math_embed/noisy_ECG_sig.mat

@MuhammmadUsman
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment