0

将使用听诊器测量的心跳信号通过硬件(主要是放大器和截止频率为 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;
4

1 回答 1

0

没有示例数据,我只是在猜测,但我认为阈值不会为您提供正确的数据:很可能,峰每次的高度都不同(“每次”我指的是每次运行和每个人打)。因此,如果使用过高的峰值,则会因为心跳太低而错过一些真正的峰值。如果您使用太低的峰值,您可能会重复计算一些心跳,因为每个心跳包含多个峰值(对不起,我不记得这些叫什么了)。事情很可能会随着时间而改变,所以我什至不会尝试为单个记录设置阈值并放手,甚至从数据中得出阈值可能会有问题。

使用其他技术,例如互相关或某种修改过的零交叉,或专门为心跳的独特功能设计的技术(我想有一些东西。你搜索过文献吗?),你可能会有更好的运气。

于 2013-04-25T13:48:58.077 回答