Error when using findpeaks for different limits
古いコメントを表示
Hi
I have a script identifying peaks in a curve (EFFEKT). The following part of the script smoothens out the peaks; if there are several peaks close to each other (not going below the limit (Abonnemang) in between), it displays only the biggest.

Abonnemang=24200;
for x=1:99999 %IF THERE IS SEVERAL PEAKS IN A ROW, TAKE THE BIGGEST
[max_val,locs] = findpeaks(EFFEKT,'MinPeakHeight',Abonnemang,'MinPeakDistance',x); % find the peak and its x axis location
[t0_pos1,s0_pos1,t0_neg1,s0_neg1]= crossing_V7(EFFEKT,t,Abonnemang,'linear'); % positive (pos) and negative (neg) slope crossing points
peak_width = t0_neg1- t0_pos1;
if length(max_val)==length(t0_pos1)
break
end
end
dt = datetime(Q,1,1:1:length(Data{:,1}));
et = hours(0:23)';
t = repmat(dt,length(et),1) + repmat(et,1,length(dt));
t=t(:);
figure(3)
plot(t,EFFEKT)
hold on
plot(t,AB)
ylim([-10000 40000])
ylabel('kW')
title('Effektkurva Konsumtion 2021')
My limit was initially set to 24200. I want to check the peaks for the limit 23200, 22200, 21200 and 20200.
24200, 23200 and 22200 works fine, but when I set Abonnemang=21200 I get the following error:
Error using findpeaks
Expected MinPeakDistance to be a scalar with value < 8759.
Error in findpeaks>parse_inputs (line 330)
validateattributes(Pd,{'numeric'},{'real','scalar','nonempty','nonnegative','<',x(M)-x(1)},'findpeaks','MinPeakDistance');
Error in findpeaks (line 135)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Error in FLEX (line 377)
[max_val,locs] = findpeaks(EFFEKT,'MinPeakHeight',Abonnemang,'MinPeakDistance',x); % find the peak and its x axis location
>>
1 件のコメント
Image Analyst
2023 年 4 月 21 日
You forgot to attach your data. If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
If you just want peaks, or indexes, where your signal is above some threshold, like 24200 then why not just threshold
itsAPeak = signal > threshold;
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Spectral Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!