Matlab信号提取、频谱分析、滤波、阈值设定、寻找极值点

转:http://blog.csdn.net/han____shuai/article/details/50700882

题目

Heart Beat Period Detection
背景交代
In clinic, it is frequently required to detect heart rate. Theheart rate is usually computed from RR-interval, which is obtainedfrom ECG.
However, while ECG measuring, noises are frequentlysuperposed.
任务
Process the noised signal to obtain ECG signal
Propose algorithm to acquire RR intervals
The Heart Rate is calculated from averaging 10RR-intervals
数据
The signal is given in the data file, ‘nNoiseECG.txt’, the samplingfrequency is 500Hz
要求
Finish the tasks individually and independently

Write a project report inEnglish. Give and explain the full processes with Matlabprograms

第一步,产生数据
由于原始数据过大不便粘贴,这里模拟出一组数据,在Matlab命令行输入:
t=[0:0.002:5.998]';      %时间轴
d =0:1/1.8:6;          % 尖峰信号
nNoiseECG=sin(2*pi*0.24*t)+2*pulstran(t,d,'tripuls',0.1,1)+0.1*randn(3000,1);% 叠加正弦漂移和尖峰信号以及随机白噪声
plot(t,nNoiseECG)
xlabel('t(s)')
ylabel('Voltage(v)')
title('Original Signal')

第二步,分析信号中的频率成分
命令行输入:

Y = fft(nNoiseECG,16384);
%进行16384个点的fft变换

Pyy = Y.* conj(Y) /16384;  
%功率谱转换

f = 500*(0:8192)/16384;
plot(f,Pyy(1:8193))
title('Frequency content of y')
xlabel('frequency (Hz)')
axis([0 10 0 1500]);
grid on;
得到功率谱图形,可知原始信号中的低频信号(可以理解为漂移)的频率构成,大约在4Hz以下

第三步,滤掉低频成分
调用fdatool设计高通滤波器(命令行输入fdatool),如图3所示,下限截止频率4Hz,上限20Hz(值越大,滤波后可用的尖峰越多)。

利用M语言进行滤波
在图3所示的fdatool中File->Export,导出到Workspace中。
在命令行输入:
a=filter(Num,1,nNoiseECG);%其中Num即为滤波器的极点参数,1为零点参数,a即滤波后的数据。

plot(t,a)% 滤波后画图
xlabel('t(s)')
ylabel('Voltage(v)')
title('Signal After Filtering'
)

第四步,阈值去噪
设定阈值为0.5,小于0.5的点设置为0
命令行输入:
for i=1:3000
if (a(i)<0.5)
a(i)=0;
end
end

b=find(diff(sign(diff(a)))<0)+1;%求解极值点序号
plot(t, a,t(b), a(b),'r*') %画出去噪声后的波形,由于滤波的关系,前一秒钟的信号异常,因此只画1s以后的数据
xlabel('t(s)')
ylabel('Voltage(v)')
axis([1 6 0 2]);
title('Final Signal')
grid on

第五步,调整阈值去噪
根据图6,可以看到在第5,6个波峰处出现了多个极值点,因此考虑调高阈值进行去噪。设定阈值为0.85,小于0.85的点设置为0
命令行输入:
for i=1:3000
if (a(i)<0.5)
a(i)=0;
end
end

b=find(diff(sign(diff(a)))<0)+1;%求解极值点序号
plot(t, a,t(b), a(b),'r*')%画出去噪声后的波形,由于滤波的关系,前一秒钟的信号异常,因此只画1s以后的数据
xlabel('t(s)')
ylabel('Voltage(v)')
axis([1 6 0 2]);
title('Final Signal')
grid on

第六步,确定RR时间间隔
取最后9个脉冲时间间隔取平均,得到RR时间间隔和频率
命令行输入:
(t(b(9))-t(b(1)))/10
10/(t(b(9))-t(b(1)))

猜你喜欢

转载自blog.csdn.net/csu_guo_liang/article/details/79194935