ECG
clear all;
load ecg.mat;
wp = 0.2*pi; ws = 0.3*pi;
rp = 1; rs = 15;
% design
[n,wn] = buttord(wp/pi,ws/pi,rp,rs);
[b,a] = butter(n,wn);
[h1,w1] = freqz(b,a,512,1);
H1 = 20*log10(abs(h1));
figure(1);
plot(w1*2,H1);
xlabel('\omega/\pi');
ylabel('|H(e^j^\omega)|/dB');
title('Magnitude and frequency response of butterworth filter(N=6)');
grid on;
%butterworth filter of different orders in time-domain
figure(2);
for m=1:4
switch m
case 1
n = 3;
case 2
n = 6;
case 3
n = 20;
case 4
n = 40;
end
t=0:1:55;
[bm,am] = butter(n,wn);
ym = filter(bm,am,x);
hold on;
subplot(2,2,m)
plot(t,x,'b',t,ym,'r');
xlabel('n');
ylabel('x(n)');
title(['N= ',num2str(n)]);
grid on;
t=0:1:55;
end
%butterworth filter of different orders in frequency-domain
figure(3);
for k=1:4
switch k
case 1
n = 3;
case 2
n = 6;
case 3
n = 20;
case 4
n = 40;
end
t=0:1:55;
[bn,an] = butter(n,wn);
yn = filter(bn,an,x);
X_Fn = fftshift(abs(fft(x)));
Y_Fn = fftshift(abs(fft(yn)));
hold on;
subplot(2,2,k)
plot(t,X_Fn,'b',t,Y_Fn,'r');
xlabel('\omega/2\pi');
ylabel('|X(k)|');
title(['N= ',num2str(n)]);
grid on;
end