【发布时间】:2013-04-23 10:49:09
【问题描述】:
我想找到原始心电图信号的峰值,以便计算每分钟的心跳次数 (bpm)。 我在 matlab 中编写了一段代码,附在下面。在下面的代码中,我无法正确找到阈值点,这将帮助我找到峰值,从而找到 bpm。
%input the signal into matlab
[x,fs]=wavread('heartbeat.wav');
subplot(2,1,1)
plot(x(1:10000),'r-')
grid on
%lowpass filter the input signal with cutoff at 100hz
h=fir1(30,0.3126); %normalized cutoff freq=0.3126
y=filter(h,1,x);
subplot(2,1,2)
plot(y(1:10000),'b-')
grid on
% peaks are seen as pulses(heart beats)
beat_count=0;
for p=2:length(y)-1
th(p)=abs(max(y(p)));
if(y(p) >y(p-1) && y(p) >y(p+1) && y(p)>th(p))
beat_count=beat_count+1;
end
end
N = length(y);
duration_seconds=N/fs;
duration_minutes=duration_seconds/60;
BPM=beat_count/duration_minutes;
bpm=ceil(BPM);
请帮助我,因为我是 matlab 新手
【问题讨论】:
-
您好,我建议您解释一下您的峰值检测算法背后的逻辑,而不是期望人们仅仅从代码中理解它。另外
abs(max(y(p)))没有多大意义,因为y(p)是一个标量,所以max(y(p))只是y(p),也许你的意思是max(y)? -
@Dan yup...我的意思是 max(y)....通过找到阈值,我可以将 y 的值与其前一个值、下一个值和阈值进行比较。如果该值大于所有 3 个条件,则将其视为峰值点。
-
100 Hz 是从 ECG 数据中过滤 QRS 的疯狂高截止值。您可能需要更多大约 15-30 Hz 的频率。您还需要一个截止频率约为 5 Hz 的高通滤波器来消除基线漂移等。除此之外,您可能应该使用
filtfilt,因此没有相位失真 - 毕竟,在这种情况下您对时间历史的样子感兴趣。你也可以考虑使用the Pan & Tompkins algorithm,效果很好。 -
我也在 ios 中应用了同样的东西我希望你能得到解决方案但是有两种方法可以找到坡度或者你得到从旧坐标到新坐标的距离,我也很高兴如果我在 ios 中获得帮助