Detecting maximum with threshold

조회 수: 12 (최근 30일)
Hanna Armstrong
Hanna Armstrong 2022년 11월 28일
댓글: Matt J 2022년 11월 28일
%example threshold detection code
function [MAXES] = identifyMaximums(Avg)
X = Avg;
threshold = 30;
[Xon, Xoff] = detectThreshold(X,threshold);
nSteps = length(Xon);
firstOff = 1;
while Xoff(firstOff) > Xon(1)
firstOff = firstOff+1;
end
lastOn = nSteps;
while Xon(lastOn) > Xoff(end)
lastOn = lastOn-1;
end
%Adjust ons and offs
Xon_align = Xon(1:lastOn);
Xoff_align = Xoff(firstOff:end);
%Count number of steps after aligning
nStepsFinal = length(Xon_align);
%Initialize matrix of maximums
MAXES = NaN(nStepsFinal,1);
for i = 1:nStepsFinal
MAXES(i) = max(X(Xon_align(i):Xoff_align(i)));
end
function [Ons,Offs] = detectThreshold(signal,threshold)
overThreshold = signal>threshold;
onOffs = diff(overThreshold);
Offs = find(onOffs==-1)+1;
Ons = find(onOffs==1);
end
end
Error:
Index exceeds the number of array elements. Index must
not exceed 0.
Error in identifyMaximums (line 14)
while Xoff(firstOff) > Xon(1)
Error in load_data_10_15 (line 119)
[MAXES] = mean(identifyMaximums(Avg));
Data (Avg) that is being processed:attached image
Hello I hope all is well. I am currently working on a side project where I am trying to match data from a sensor to a force plate. At the moment I am trying to linearize the data. To do so, I must collect the peak values. For some reason I am getting this error and I am not sure why. If you have the time, please look over my work and provide some guidence.
Thank you!

채택된 답변

Steven Lord
Steven Lord 2022년 11월 28일
You may want to take a look at the islocalmax function.
  댓글 수: 1
Hanna Armstrong
Hanna Armstrong 2022년 11월 28일
Hi Steven, So I did the localmax function and plotteded it and this is what I am getting, do you have any reccomendations in regards to filtering out the bottom values?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2022년 11월 28일
편집: Matt J 2022년 11월 28일
If you have the time, please look over my work and provide some guidence.
In detectThreshold(), you need to add control logic to handle the case where find() returns empty [].
Offs = find(onOffs==-1)+1;
Ons = find(onOffs==1);
  댓글 수: 2
Hanna Armstrong
Hanna Armstrong 2022년 11월 28일
Hi Matt, thank you for responding!
If you can, may you please elaborate on what you mean by adding control logic? At the moment I don't understand how I am supposed to change it.
Thanks.
Matt J
Matt J 2022년 11월 28일
I left it to you because only you knowwhat's supposed to happen when no peaks are detected.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by