How can I calculate heart rates?
이전 댓글 표시
I have a ".txt" file obtained by an ECG, now I need calculate the cardiac frequencies from that ECG. I've built some code but I'm pretty confused, to be able to do the rest. Someone can help me?
clear all
close all
clc
Fs=1000;
%t=1/Fs;
%N = length (x2)
file =importdata('ecg16.txt');
save('ecg16.mat','-struct','file');
load('ecg16.mat');
file1=importdata('ecg16.mat');
sinal=file1.data(:,4);
ecg16=sinal(60001:70000);
t=1/Fs:1/Fs:length(ecg16)/Fs;
figure;
subplot (2,1,1);
plot(t,ecg16);
xlabel('t/s');
title ('ECG without filter')
y = sgolayfilt(ecg16,3,41);
subplot (2,1,2)
%plot(60000:70000,y(60000:70000));
plot (1: 2000, y (1: 2000))
xlabel('t/s')
title ('ECG with filter')
%eixo ([2000 -4 0 4])
%grade
T=0.001:0.001:10;
figure,
plot(T,ecg16);
xlabel('T');
title ('interval ECG');
F=1./T;
figure,
plot(T,F);
xlabel('T');
ylabel('F');
title ('Frequency do ECG');
n=60;
l=length(ecg16);
if n>=l
r=data-mean(ecg16)*ones(l,1);
else
r=zeros(l,1);
for i=1:1:n+1;
r(i)=ecg16(i)-mean(ecg16(1:n+i));
end
for i=l-n+1:1:l;
r(i)=ecg16(i)-mean(ecg16(i-n:l));
end
for i=n+2:1:l-n;
r(i)=ecg16(i)-mean(ecg16(i-n:i+n));
end
end
figure; plot(t,r);
xlabel('t/s');
title('Alinhamento dos picos')
s=(r>0.7*max(r));
i=1;
picos=[];
while i<=length(s)
if s(i)==0 %ignorar os 0s
i=i+1;
else
v=[];
while s(i)==1
v=[v i];
i=i+1;
end
[y j]=max(r(v));
picos=[picos [y;v(j)]];
end
end
figure; hold on
plot(picos(2,:)/Fs,picos(1,:),'.r');
plot(t,r);
xlabel('t/s'); hold off;
title('')
freq = [];
for i=2:length(picos)
freq = [freq ((picos(2,i)-picos(2,i-1))/Fs)^-1]; %f=1/(T(i)-T(i-1))
end
x=picos(2,2:end);
y=freq;
xi = picos(2,2):picos(2,end);
yi = interp1(x,y,xi,'linear');
figure;
hold on;
plot(x/Fs,y,'or');
plot(xi/Fs,yi);
xlabel('t/s');
ylabel('f/Hz');
title('frequency/ time')
hold off;
soma=zeros(1,600);
amostras=zeros(47,600);
for i=1:length(picos)
soma=soma+r(picos(2,i)-300:picos(2,i)+299)';
amostras(i,:)=r(picos(2,i)-300:picos(2,i)+299)';
end
soma=soma/length(picos);
figure;
plot(1/Fs:1/Fs:length(soma)/Fs,soma);
xlabel('t/s');
title ('Onda PQRST')
댓글 수: 2
Walter Roberson
2015년 12월 27일
You need to indicate what you are confused about, or what in your code is not working the way you expect.
Biza Ferreira
2015년 12월 27일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Applications에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!