Matlab中原始心电信号的QRS检测(峰值) [英] QRS detection(peaks) of a raw ecg signal in matlab

查看:550
本文介绍了Matlab中原始心电信号的QRS检测(峰值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到原始心电信号的峰值,以便可以计算每分钟的心跳数(bpm). 我已经在下面的matlab中编写了代码.在下面的代码中,我无法正确找到阈值点,这将有助于我找到峰值,从而找到bpm.

I want to find the peaks of the raw ecg signal so that I can calculate the beats per minute(bpm). I Have written a code in matlab which I have attached below.In the code below I am unable to find threshold point correctly which will help me in finding the peaks and hence the 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的新手,请帮助我

Please help me as I am new to matlab

推荐答案

我建议更改代码的这一部分

I suggest changing this section of your code

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

这肯定是有缺陷的.我不确定您的逻辑,但那又如何呢?我们正在寻找峰值,但只寻找高峰值,因此首先让我们设置一个阈值(您必须将其调整为一个合理的数字),然后剔除该值以下的所有内容以摆脱较小的峰值:

This is definitely flawed. I'm not sure of your logic here but what about this. We are looking for peaks, but only the high peaks, so first lets set a threshold value (you'll have to tweak this to a sensible number) and cull everything below that value to get rid of the smaller peaks:

th = max(y) * 0.9; %So here I'm considering anything less than 90% of the max as not a real peak... this bit really depends on your logic of finding peaks though which you haven't explained
Yth = zeros(length(y), 1);
Yth(y > th) = y(y > th);

好的,所以我建议您现在绘制y和Yth来查看该代码的作用.现在找到峰是我的逻辑,我们正在寻找局部最大值,即函数的一阶导数从正变为负的点.因此,我将通过找到信号上每个连续点之间的差异来找到与一阶导数非常简单的数值近似值:

OK so I suggest you now plot y and Yth to see what that code did. Now to find the peaks my logic is we are looking for local maxima i.e. points at which the first derivative of the function change from being positive to being negative. So I'm going to find a very simple numerical approximation to the first derivative by finding the difference between each consecutive point on the signal:

Ydiff = diff(Yth);

否,我想找到信号从正变为负的位置.因此,我将使所有正值均等于零,并使所有负值均等于1:

No I want to find where the signal goes from being positive to being negative. So I'm going to make all the positive values equal zero, and all the negative values equal one:

Ydiff_logical = Ydiff < 0;

最后,我想找到此信号从零到一个变化的位置(但不是相反)

finally I want to find where this signal changes from a zero to a one (but not the other way around)

Ypeaks = diff(Ydiff_logical) == 1;

现在计算峰值:

sum(Ypeaks)

请注意,由于使用了diff来绘制文字,我们应该在Ypeaks的任何一侧都填充一个False,这样

note that for plotting purpouse because of the use of diff we should pad a false to either side of Ypeaks so

Ypeaks = [false; Ypeaks; false];

好的,那里有很多matlab,建议您逐行运行每一行,并通过绘制每行的结果以及双击matlab工作区中的变量来检查变量,以了解什么每个步骤都在发生.

OK so there is quite a lot of matlab there, I suggest you run each line, one by one and inspect the variable by both plotting the result of each line and also by double clicking the variable in the matlab workspace to understand what is happening at each step.

示例 :(信号PeakSig来自 http://www.mathworks.com/help/signal/ref/findpeaks.html ),并使用以下方式进行绘制:

Example: (signal PeakSig taken from http://www.mathworks.com/help/signal/ref/findpeaks.html) and plotting with:

plot(x(Ypeaks),PeakSig(Ypeaks),'k^','markerfacecolor',[1 0 0]);

这篇关于Matlab中原始心电信号的QRS检测(峰值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆