问题描述
通过硬件(主要是放大器和截止频率为100hz的低通滤波器)将使用听诊器测量的心跳信号提供给计算机的声卡.现在,信号以截止100hz进行滤波.下面给出了查找峰值和每分钟心跳的代码.该代码仅在某些情况下有效.请帮助我找到错误clear all
%input the signal into matlab
[x,fs]=wavread('heartbeat.wav');
figure(1)
subplot(2,1,1)
x1=x(:,2);
plot(x1(500:10000),'r-');
title('unfiltered input x(n),cut off frequency 0.0270,passband 60hz,stopband 70hz');
ylabel('amplitude in volts');
xlabel('number of samples')
grid on
%to filter the signal above 50-60 hz
order=4;
h=fir1(4,0.0270,hamming(order+1));
y=filter(h,1,x1);
subplot(2,1,2)
plot(y(500:10000),'b-')
title('filtered output y(n),cut off frequency 0.0270,passband 50hz,stopband 60hz');
ylabel('amplitude in volts');
xlabel('number of samples')
grid on
%sound(y,5000)
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);
Ydiff = diff(Yth);
Ydiff_logical = Ydiff < 0;
Ypeaks = diff(Ydiff_logical) == 1;
p=sum(Ypeaks)
N = length(y);
duration_seconds=N/fs;
duration_minutes=duration_seconds/60;
BPM=p/duration_minutes;
bpm=ceil(BPM)
figure(2)
%frequency response of the filter
freqz(h,1)
title('Frequency response');
xlabel('normalized frequency (X pi) radians per sample');
ylabel('Magnitude');
grid on;
我没有猜测示例数据,但我认为阈值化不会为您提供正确的数据:峰值很可能是不同的每次的身高(每次",我指的是每次跑步和每个单独的跳动).因此,如果您使用的峰太高,由于心跳太低,它将错过一些真实的峰.如果使用太低的峰,则由于每个心跳都包含多个峰,您可能会有重复计算某些心跳的风险(对不起,我不记得这些峰叫什么).事情也可能会随着时间而改变,所以我什至不会尝试设置单个记录的阈值并放任其走,甚至从数据中推导出阈值也可能是有问题的.
使用其他技术(例如互相关或某种修改的过零)或专门针对心跳的独特功能设计的东西,您可能会遇到更好的运气(我想是有些东西.您是否检索过文献?)
Given an heart beat signal measured using a stethoscope to the audio card of the computer through a hardware(mainly amplifier and low pass filter having cutoff frequency 100hz).Now the signal is filtered with cutoff 100hz..the code to find the peak and beats per minute is given below..The code works only for certain cases.Please help me find the mistake
clear all
%input the signal into matlab
[x,fs]=wavread('heartbeat.wav');
figure(1)
subplot(2,1,1)
x1=x(:,2);
plot(x1(500:10000),'r-');
title('unfiltered input x(n),cut off frequency 0.0270,passband 60hz,stopband 70hz');
ylabel('amplitude in volts');
xlabel('number of samples')
grid on
%to filter the signal above 50-60 hz
order=4;
h=fir1(4,0.0270,hamming(order+1));
y=filter(h,1,x1);
subplot(2,1,2)
plot(y(500:10000),'b-')
title('filtered output y(n),cut off frequency 0.0270,passband 50hz,stopband 60hz');
ylabel('amplitude in volts');
xlabel('number of samples')
grid on
%sound(y,5000)
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);
Ydiff = diff(Yth);
Ydiff_logical = Ydiff < 0;
Ypeaks = diff(Ydiff_logical) == 1;
p=sum(Ypeaks)
N = length(y);
duration_seconds=N/fs;
duration_minutes=duration_seconds/60;
BPM=p/duration_minutes;
bpm=ceil(BPM)
figure(2)
%frequency response of the filter
freqz(h,1)
title('Frequency response');
xlabel('normalized frequency (X pi) radians per sample');
ylabel('Magnitude');
grid on;
Without example data I'm just guessing, but I don't think thresholding is going to get you the right data: in all likelihood, the peaks are different height each time (by "each time" I mean both each run and each individual beat). Therefore, if you use too high a peak, it will miss some real peaks because the heartbeat will be too low. If you use too low a peak, you risk double-counting some heartbeats beacuase each heartbeat contains multiple peaks (Sorry I don't remember what these are called). It's likely that things will change over time, as well, so I wouldn't even try to set the threshold for an individual recording and let it go, or even deriving threshold from the data could be problematic.
You will likely have better luck with other techniques such as cross-correlation or some sort of modified zero-crossing, or something specifically designed for the unique features of heartbeats (I imagine there is something. Have you searched the literature?).
这篇关于从听诊器输入的心脏信号中找到R峰值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!