此示例显示如何执行基本峰值分析。它将帮助您回答问题:如何在我的信号中找到峰值?如何测量峰之间的距离?如何测量受趋势影响的信号峰的幅度?如何在嘈杂的信号中发现峰值?如何找到当地的最小值?
The Zurich sunspot relative number measures both the number and size of sunspots. Use thefindpeaks.
function to find the locations and the value of the peaks.
加载sunspot.dat年=太阳黑子(:,1);Relnums = Sunspot(:,2);findpeaks(Relnums,年)Xlabel(“年”)ylabel('Sunspot Number') 标题('找到所有山峰')
The above plot shows sunspot numbers tabulated over 300 years and labels the detected peaks. The next section shows how to measure distance between these peaks.
Peaks in the signal seem to appear at regular intervals. However, some of the peaks are very close to each other. TheMINPEAKPROMINENCE.
可以使用Property滤除这些峰值。考虑在遇到更大的值之前将两侧下降至少40个相对太阳黑子数字的峰值。
findpeaks(Relnums,年,'minpeakprominence',40)xlabel(“年”)ylabel('Sunspot Number') 标题('找到突出的山峰')
The following histogram shows the distribution of peak intervals in years:
数字[pks, locs] = findpeaks(relNums,year,'minpeakprominence',40);Peakinterval = Diff(LOC);直方图(Peakinterval)网格在Xlabel('Year Intervals')ylabel('发生频率') 标题('峰值间隔的直方图(年)')
AverageageAstance_Peaks =均值(Diff(LOC))
AverageDistance_Peaks = 10.9600
分布表明,大多数峰间隔位于10到12年之间,表示信号具有循环性质。此外,峰之间的平均间隔为10.96岁与11年的已知循环太阳黑子活动相匹配。
You may want to consider flat peaks as peaks or exclude them. In the latter case, a minimum excursion which is defined as the amplitude difference between a peak and its immediate neighbors is specified using the临界点
property.
加载Clippeaks.mat.数字% Show all peaks in the first plot斧头(1)=子图(2,1,1);findpeaks(sermateddata)xlabel('Samples')ylabel('振幅') 标题('Detecting Saturated Peaks')%在第二个绘图中指定最小偏移斧头(2)=子图(2,1,2);findpeaks(sermateddata,'临界点',5) xlabel('Samples')ylabel('振幅') 标题('过滤饱和峰')% link and zoom in to show the changeslinkaxes(ax(1:2),'xy')轴(AX,[50 70 0 250])
The first subplot shows, that in case of a flat peak, the rising edge is detected as the peak. The second subplot shows that specifying a threshold can help to reject flat peaks.
该示例在ECG(电磁图)信号中显示了峰值分析。ECG是一种衡量心脏的电气活动随着时间的推移。通过连接到皮肤的电极测量信号,并且对由于运动伪像而对诸如电源干扰和噪声的扰动敏感。
加载noisyecg.matt = 1:长度(noisyecg_withtrend);图绘图(t,noisyecg_withtrend)标题(“带有趋势的信号”)Xlabel('Samples'); ylabel('电压(MV)') legend('嘈杂的心电图信号') 网格在
争取数据
上述信号显示基线移位,因此不表示真实幅度。为了去除趋势,将低阶多项式适合信号并使用多项式来贬低它。
[p,s,mu] = polyfit((1:numel(noisyecg_withtrend)',noisyecg_withtrend,6);f_y = polyval(p,(1:numel(noisyecg_withtrend))',[],mu);ECG_DATA = NOISYECG_WITHTREND - F_Y;% Detrend data数字plot(t,ECG_data) grid在ax = axis; axis([ax(1:2) -1.2 1.2]) title('贬低了ECG信号')Xlabel('Samples')ylabel('电压(MV)') legend('贬低了ECG信号')
After detrending, find the QRS complex, which is the most prominent repeating peak in the ECG signal. The QRS complex corresponds to the depolarization of the right and left ventricles of the human heart. It can be used to determine a patient's cardiac rate or predict abnormalities in heart function. The following figure shows the shape of the QRS complex in an ECG signal.
QRS复合体由三个主要组件组成:Q wave, R wave, S wave. The R waves can be detected by thresholding peaks above 0.5 mV. Notice that the R waves are separated by more than 200 samples. Use this information to remove unwanted peaks by specifying a 'MinPeakDistance'.
[〜,locs_rwave] = findpeaks(ECG_DATA,'MinPeakHeight',0.5,...'minpeakdistance',200);
为了检测S波,在信号中找到局部最小值并适当地应用阈值。
在信号中找到当地最小值
Local minima can be detected by finding peaks on an inverted version of the original signal.
ECG_inverted = -ECG_data; [~,locs_Swave] = findpeaks(ECG_inverted,'MinPeakHeight',0.5,...'minpeakdistance',200);
The following plot shows the R waves and S waves detected in the signal.
图持有在plot(t,ECG_data) plot(locs_Rwave,ECG_data(locs_Rwave),'rv','markerfacecolor','r') plot(locs_Swave,ECG_data(locs_Swave),'rs','markerfacecolor','b')轴([0 1850 -1.1 1.1])网格在传奇('ECG信号','R waves',波浪“)Xlabel('Samples')ylabel('电压(MV)') 标题('R wave and S wave in Noisy ECG Signal')
接下来,我们尝试确定Q波的位置。峰值定位峰值的峰值导致检测不需要的峰值,因为Q波被埋入噪声。首先我们过滤信号,然后找到峰值。Savitzky-Golay滤波用于去除信号中的噪声。
smoothECG = sgolayfilt(ECG_data,7,21); figure plot(t,ECG_data,'b',t,smoothECG,'r') 网格在轴紧的Xlabel('Samples')ylabel('电压(MV)') legend('嘈杂的心电图信号','过滤信号') 标题('过滤嘈杂的心电图信号')
我们对平滑信号执行峰值检测,并使用逻辑索引来查找Q波的位置。
[〜,min_locs] = findpeaks(-smoothecg,'minpeakdistance',40);%峰值在-0.2mV和-0.5mv之间locs_Qwave = min_locs(smoothECG(min_locs)>-0.5 & smoothECG(min_locs)<-0.2); figure hold在plot(t,smoothECG); plot(locs_Qwave,smoothECG(locs_Qwave),'rs','markerfacecolor','G') plot(locs_Rwave,smoothECG(locs_Rwave),'rv','markerfacecolor','r')plot(locs_swave,shockecg(locs_swave),'rs','markerfacecolor','b') 网格在标题('信号的阈值峰值')Xlabel('Samples')ylabel('电压(MV)')轴=轴;轴([0 1850 -1.1 1.1])传奇('Smooth ECG signal','Q wave','R wave',浪潮')
The above figure shows that the QRS complex successfully detected in the noisy ECG signal.
嘈杂和平滑信号之间的错误
注意原始QRS复合物之间的平均差异和促进的滤波信号。
极值的%值[val_qwave,val_rwave,val_swave] =交易(Shockcg(locs_qwave),shockecg(locs_rwave),shockecg(locs_swave));MeanError_qwave =均值((noisyecg_withtrend(locs_qwave) - val_qwave))
MEASERROR_QWAVE = 0.2771
MeanError_rwave =均值((noisyecg_withtrend(locs_rwave) - val_rwave))
MeanError_rwave = 0.3476
MeanError_swave =均值((noisyecg_withtrend(locs_swave) - val_swave))
MeanError_swave = 0.1844
这表明对噪声峰值分析进行了噪声的噪声。
峰特性
Some important peak properties involve rise time, fall time, rise level, and fall level. These properties are computed for each of the QRS complexes in the ECG signal. The average values for these properties are displayed on the figure below.
avg_riseTime = mean(locs_Rwave-locs_Qwave);%平均上升时间avg_falltime =均值(locs_swave-locs_rwave);% Average Fall timeavg_riselevel =均值(val_rwave-val_qwave);%平均上升水平avg_fallLevel = mean(val_Rwave-val_Swave);%平均下降水平Helperpeakanalissplot(T,Smoothecg,...locs_qwave,locs_rwave,locs_swave,...val_Qwave,val_Rwave,val_Swave,...avg_risetime,avg_falltime,...avg_riselevel,avg_falllevel)