clc;
close all;
clear;
load 101.mat;
x=D101(:,1);
y=D101(:,2);
subplot(6,1,1);
plot(x,y);
axis([0 60 -1 2]);
fft(y);
plot(fft(y,1024));
% X=hilbert(y);
% subplot(6,1,2);
% plot(x,X);
% axis([0 60 -1 2]);
% number1=0;
% T1=0.5*max(X);
% T2=0.1*max(X);
% k=-100;
% for n=1:1:21500%7201%14401%
% if X(n)>=T1&(n-k)>100
% number1=number1+1;
% k=n;
% end
% end
% HR=number1
% above original ECG signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=0;
E101=D101;
F101=D101;
for n=2:1:21599
E101(n,2)=(F101(n-1,2)+2*F101(n,2)+F101(n+1,2))/4;
end
y0=E101(:,2);
subplot(6,1,2);
plot(x,y0);
axis([0 10 -1 2]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=0;
E101=E101;
F101=E101;
for n=2:1:21599
E101(n,2)=(F101(n,2)-F101(n-1,2));
end
E101(1)=0;
E101(21600)=-0.0050;
y1=E101(:,2);
subplot(6,1,3);
plot(x,y1);
axis([0 10 -0.4 0.5]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y2=fft(y1);
subplot(6,1,4);
plot(x,y2);
axis([0 10 -20 20]);
E(:,2)=y2;
for n=1
E(n,2)=0;
end
for n=2:1:10801
E(n,2)=-i*E(n,2);
end
for n=10802:1:21600
E(n,2)=i*E(n,2);
end
y3=E(:,2);
subplot(6,1,5);
plot(x,y3);
axis([0 10 -20 20]);
y4=ifft(y3);
subplot(6,1,6);
plot(x,y4);
axis([0 10 -0.4 0.5]);
B=y4;
for n=1:1:21600
B(n)=sqrt(y1(n)^2+y4(n)*y4(n));
end
figure;
plot(x,B);
axis([0 60 -0.4 0.5]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
number1=0;
T1=0.6*max(B);
T2=0.1*max(B);
k=-100;
for n=1:1:21500%7201%14401%
if B(n)>=T1&(n-k)>100
number1=number1+1;
k=n;
end
end
HR=number1
%Deciosion rules
% figure;
% subplot(5,1,2)
% plot(x,y);
% axis([0 20 -1 2]);
% subplot(5,1,3)
% plot(x,yy1);
% axis([0 20 -1 2]);
% subplot(5,1,4)
% plot(x,yy2);
% axis([0 20 -1 2]);
% subplot(5,1,5)
% plot(x,yy);
% axis([0 20 -0.1 0.5]);