主要内容

Peak Analysis

此示例显示如何执行基本峰值分析。它将帮助您回答问题:如何在我的信号中找到峰值?如何测量峰之间的距离?如何测量受趋势影响的信号峰的幅度?如何在嘈杂的信号中发现峰值?如何找到当地的最小值?

Finding Maxima or Peaks

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 axes object with title Find All Peaks contains 2 objects of type line.

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.

Measuring Distance Between 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') 标题('找到突出的山峰')

图包含轴对象。具有标题的轴对象查找突出的峰值包含2个类型的2个对象。

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])

图包含2个轴对象。具有标题检测饱和峰的轴对象1包含2个类型的2个物体。带有标题滤波饱和峰的轴对象2包含2个类型的类型。

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('嘈杂的心电图信号') 网格

图包含轴对象。具有趋势标题信号的轴对象包含类型线的对象。该对象表示嘈杂的ECG信号。

争取数据

上述信号显示基线移位,因此不表示真实幅度。为了去除趋势,将低阶多项式适合信号并使用多项式来贬低它。

[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) gridax = axis; axis([ax(1:2) -1.2 1.2]) title('贬低了ECG信号')Xlabel('Samples')ylabel('电压(MV)') legend('贬低了ECG信号')

图包含轴对象。The axes object with title Detrended ECG Signal contains an object of type line. This object represents Detrended ECG Signal.

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.

Thresholding to Find Peaks of Interest

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')

图包含轴对象。The axes object with title R wave and S wave in Noisy ECG Signal contains 3 objects of type line. These objects represent ECG Signal, R waves, S waves.

接下来,我们尝试确定Q波的位置。峰值定位峰值的峰值导致检测不需要的峰值,因为Q波被埋入噪声。首先我们过滤信号,然后找到峰值。Savitzky-Golay滤波用于去除信号中的噪声。

smoothECG = sgolayfilt(ECG_data,7,21); figure plot(t,ECG_data,'b',t,smoothECG,'r') 网格紧的Xlabel('Samples')ylabel('电压(MV)') legend('嘈杂的心电图信号','过滤信号') 标题('过滤嘈杂的心电图信号')

图包含轴对象。具有标题过滤噪声的轴对象噪声的ECG信号包含2个类型的类型。这些对象代表嘈杂的ECG信号,过滤信号。

我们对平滑信号执行峰值检测,并使用逻辑索引来查找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 holdplot(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 axes object with title Thresholding Peaks in Signal contains 4 objects of type line. These objects represent Smooth ECG signal, Q wave, R wave, S 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)

图包含轴对象。带有标题QRS的轴对象在ECG信号中包含11个类型的线条,文本的11个对象。这些对象代表QRS复杂,峰值,最小值。

See Also