www.pudn.com > ECG.rar > ecg.m, change:2007-05-28,size:987b


clear all   
fid=fopen('107.dat'); 
ecgdata=fread(fid, 400, 'schar'); 
N=length(ecgdata); 
t=0:1/200:(N-1)*1/200; 
%Band Pass Filter 
B1=[1,0,0,0,0,0,-2,0,0,0,0,0,1]; 
A1=[1,-2,1]; 
y1=filter(B1,A1,ecgdata); 
B2=[-1,zeros(1,15),32,-32,zeros(1,14),1]; 
A2=[32,-32]; 
y2=filter(B2,A2,y1); 
%Differentiator 
B3=[0.2,0.1,0,-0.1,-0.2]; 
A3=1; 
y3=filter(B3,A3,y2); 
%Squaring 
for n=1:N 
    y4(n)=1/100*y3(n)^2; 
end 
%Moving-window integrator 
for n=1:31 
    y5(n)=0; 
end 
for n=32:N 
    temp=0; 
    for m=n-31:n 
        temp=y4(m)+temp; 
    end 
    y5(n)=temp/32; 
end 
 
%for n=1:N 
   % if y5(n)>=8000; 
      %  check(n)=1; 
    %else 
       % check(n)=0 
    %end 
%end 
subplot(5,1,1),plot(t,ecgdata),title('ECG') 
subplot(5,1,2),plot(t,y2),title('Band Pass Filter') 
subplot(5,1,3),plot(t,y3),title('Differentiator') 
subplot(5,1,4),plot(t,y4),title('Squaring') 
subplot(5,1,5),plot(t,y5),title('Moving-window integrator') 
%subplot(6,1,6),plot(t,check),title('')