
如何区分双峰和单峰阵列?
另外,如果数组表示一个双峰,如何找到两个峰之间的最小点?在寻找最小值点时,不应考虑峰外的极小点(左峰的左侧和右峰的右侧)。
发布于 2012-01-06 12:04:47
我发现函数是非常可靠和快速的,尽管它是基于循环的。它不需要对有噪声的数据进行预平滑,但可以找到局部最大和最小极值,其差异大于参数delta。
由于PEAKDET从左到右运行,它有时会错过右侧站点上的峰值。为了避免它,我更喜欢运行两次:
%# some data
n = 100;
x = linspace(0,3*pi,n);
y = sin(x) + rand(1,n)/5;
%# run peakdet twice left-to-right and right-to-left
delta = 0.5;
[ymaxtab, ymintab] = peakdet(y, delta, x);
[ymaxtab2, ymintab2] = peakdet(y(end:-1:1), delta, x(end:-1:1));
ymaxtab = unique([ymaxtab; ymaxtab2],'rows');
ymintab = unique([ymintab; ymintab2],'rows');
%# plot the curve and show extreme points based on number of peaks
plot(x,y)
hold on
if size(ymaxtab,1) == 2 && size(ymintab,1) == 1 %# if double peak
plot(ymintab(:,1),ymintab(:,2),'r.','markersize',30)
elseif size(ymaxtab,1) == 1 && size(ymintab,1) == 0 %# if single peak
plot(ymaxtab(:,1),ymaxtab(:,2),'r.','markersize',30)
else %# if more (or less)
plot(ymintab(:,1),ymintab(:,2),'r.','markersize',30)
plot(ymaxtab(:,1),ymaxtab(:,2),'r.','markersize',30)
end
hold off

发布于 2012-01-06 05:24:44
这里有一种算法,它可能会根据你的信号的噪声程度而起作用。在这里,我将峰值定义为大于给定阈值的连接点的集合。
假设您的原始数据在数组A中。首先,找到一个阈值:
t = (max(A)+min(A))/2;接下来,找出所有大于这个阈值t的点
P = A>t;使用计算大于t的连接入口点的数量
L = bwlabel(P);
numberOfPeaks = max(L);现在,numberOfPeaks应该会告诉您数据中有多少个峰值(连接点大于阈值
现在,为了找到两个峰之间的最小点,我们需要使用标签矩阵L来识别分离两个峰的点。
firstPoint = find(L==1,1,'last')+1;
lastPoint = find(L==2,1,'first')-1;因此,前两个峰之间的谷值是指数介于firsPoint和lastPoint之间的点。那么最小值将是
minValue = min(A(firstPoint:lastPoint));不依赖于图像处理工具箱的解决方案
正如@Nzbuu指出的那样,aboth依赖于图像处理工具箱函数bwlabel。所以,这里是避免这种情况的地方。首先,我假设数组P正确地识别出属于峰(P(i)=1)和属于谷(P(i)=-1)的点。如果是这样的话,当dP = P(i+1)-P(i) = 1或-1时,可以识别峰和谷之间的边界。
dP = diff(P);要计算峰值的数量,只需将dP中的1的数量相加
numberOfPeaks = sum(dP==1);并且标识第一个谷地的点位于
firstPoint = find(dP==-1,1,'first')+1 %# the -1 represents the last point of the peak so add 1
lastPoint = find(dP==1,2,'first'); #% Find the start of the second peak
lastPoint = lastPoint(end); #% Keep the last value发布于 2012-01-06 06:58:21
您可以通过如下方式找到本地最小/最大值:
x = 0:.1:4*pi;
y = sin(x);
plot(x,y)
diffy = diff(y);
localMin = find(diffy(1:end-1)<=0 & diffy(2:end) > 0)+1;
localMax = find(diffy(1:end-1)>=0 & diffy(2:end) < 0)+1;
hold on
plot(x(localMin),y(localMin),'dg')
plot(x(localMax),y(localMax),'*r')结果是:

基本上,您可以找到y值之间的增量改变符号的位置。如果您的数据是噪声,这将导致大量的本地最小/最大值,您可能需要过滤您的数据。
要找到两个峰值之间的最小值,可以这样做:
if numel(localMax) == 1
fprintf('The max value is: %f',y(localMax));
elseif numel(localMax > 1)
betweenPeaksIndex = localMin(localMin > localMax(1) & localMin <localMax(2));
fprintf('The min between the first 2 peaks is: %f',y(betweenPeaksIndex));
else
fprintf('The was no local Max ..???');
endhttps://stackoverflow.com/questions/10303968
复制相似问题