Sie sind auf Seite 1von 3

clc;

clearall;
closeall;
ecg=xlsread('C:\Users\saravana\Desktop\project\input data\500sampecg.xlsx');
f_s=250;
w=50/(250/2);
bw=w;
[num,den]=iirnotch(w,bw); % notch filter implementation
ecg_notch=filter(num,den,ecg);
N1=length(ecg_notch);
t1=[0:N1-1]/f_s;
figure(1);
plot(t1,ecg_notch);
title(' ECG signal ')
xlabel('time in sec')
% xlim([0 60])
ylabel('amplitude in mV')
[e,f]=wavedec(ecg_notch,10,'db6');% Wavelet implementation
g=wrcoef('a',e,f,'db6',8);
figure; plot(g),title('checking the recoefficient output')
ecg_wave=ecg_notch-g;
N2=length(ecg_wave);
figure(2);
plot(t1,ecg_wave);
ylabel('amplitude in mV')
ylim([-1 1])
xlabel('time in sec')
% xlim([0 60])
title('Baseline shift Removed Ecg signal');
pfecg=fft(ecg_wave);
pecg=abs(pfecg/N2); % PSD, ML FFT is 2-sided
P3=pecg(1:N2/2+1); % Get the positive one-sided components
P3(2:end-1)=2*P3(2:end-1); % half original energy each half
figure(3);
plot(P3);
ylabel('amplitude')
xlabel('frequency')
title(' psd of ECG signal before filtering ')
y=sgolayfilt(ecg_wave,3,91);
N3=length(y);
figure(4);
plot(t1,y);
axis([0 0.8 -1 1]);
ylabel('amplitude in mV')
xlabel('time in sec')
% xlim([0 60]);
title('smoothened ecg');
qfecg=fft(y);
qecg=abs(qfecg/N3); % PSD, ML FFT is 2-sided
P1=qecg(1:N3/2+1); % Get the positive one-sided components
P1(2:end-1)=2*P1(2:end-1);% half original energy each half
figure(5);
plot(P1);
ylabel('amplitude in mV')
xlabel('frequency in hz')
title(' psd of ECG signal after filtering ')
% Peak detection algorithm
% For more detailsor detailed explanation on this look into
% Matlab for beginers
hh=y;
j=[]; %loop initialing, having all the value zero in the array
time=0; %loop initialing, having all the value zero in the array
th=0.45*max(hh); %thresold setting at 45 percent of maximum value

fori=2:N1-1 % length selected for comparison


% deopping first iei=1:N-1 point because hh(1-1)
% in the next line will be zero which is not appreciable in matlab
if((hh(i)>hh(i+1))&&(hh(i)>hh(i-1))&&(hh(i)>th))
% condition, i should be> then previous(i-1),next(i+1),thrsold point;
j(i)=hh(i);
%if condition satisfy store hh(i)in place of j(i)value whichis initially 0;

time(i)=[i-1]/250; %position stored where peak value met;

end
end
j(j==0)=[]; % neglect all zeros from array;
time(time==0)=[]; % neglect all zeros from array;
m=(time)'; % converting rows in column;
k=length(m);
figure(6);
plot(hh);
xlim([0 60])
%x-axis time, y-smooth signal value;
holdon;
figure(7)
% hold the plot and wait for next instruction;
plot(j,'*r');
% xlim([0 60]);
title('PEAK POINTS DETECTED IN ECG SIGNAL')
%x-axis time, yaxis-peak value,r=marker;
xlabel('time')
ylabel('amplitude')
holdoff% instruction met;
%% Task 4-a
% to remove unwanted zeros from variable j and time
rr2=m(2:k); %second array from 2nd to last point;
rr1=m(1:k-1); %first array from 1st to 2nd last point;
% rr2 & rr1 is of equall length now;
rr3=rr2-rr1;
hr=60./rr3; % computate heart rate variation ;
figure(8);
plot(hr); xlim([0 60])
title(' DISPLAY HRV') % stairs are used to show the variation
rr33=(rr3)';
ki=length(rr33);
rr4=rr33(2:ki);
rr5=rr33(1:ki-1);
figure(9);
plot(rr4,rr5,'r*') %plot R-R(n)(X-Axis) vs R-R(n-1)(Y-Axis)
title('POINCARE PLOT'), xlabel('RR(n+1)') ,ylabel('RR(n)')
%% Task 4-b
ki=length(rr3) ;
ahr=mean(hr); % mean heart rate;
disp(['mean hrv = ' num2str(ahr)]);
% disp is used to display the value(s);
SDNN = std(rr3);
% SDNN, standard deviation for RR interval used in statical analysis;
disp(['SDNN = ' num2str(SDNN)]);
sq = diff(rr3).^2;
rms = sqrt(mean(sq)); % RMSSD,
disp(['RMSSD = ' num2str(rms)]);
% RMS difference for RR interval used in statical analysis;

NN50 = sum(abs(diff(rr3))>.05);
% NN50 no. of pairs of RR that is more than 50, used in statical analysis;
disp(['NN50 = ' num2str(NN50)]);
%% Try 4/3

Das könnte Ihnen auch gefallen