Finding index (x value) of noisy data crossing a threshold value

조회 수: 41 (최근 30일)
Jason
Jason 2019년 12월 4일
댓글: ME 2019년 12월 4일
Hello, I have some "noisy" data (xth_col) as shown by the red curve. I smooth this (black curve) first using:
win=200
d1=smooth(double(xth_col(:)),win);
I want to find out the width of this smoothed data by finding the x value where it crosses the horizontal red dotted line (=d80)
I have used:
xData=d1;
Value=d80
diff=abs(xData(:))-Value
[xshift, ind] = min(abs(diff(:)));
But this doesn't always work (as shown by the green data) . im going to need the first crossing coming from either end of the data. so I thought If I just list the diff, I can then find out where this swaps sign (i.e. crosses the horizontal line).
Not sure how to do this or if this is the best approach.
Thanks for any help
Jason

채택된 답변

Jakob B. Nielsen
Jakob B. Nielsen 2019년 12월 4일
편집: Jakob B. Nielsen 2019년 12월 4일
Have you considered the find function? It will give you every index of the input array that meets a certain condition.
cross=find(d1 > yourthreshhold);
cross(1) %yields the first index of xth_col which is above your threshhold
cross(end) %yields the last index of xth_col which is above your threshhold
  댓글 수: 2
Jason
Jason 2019년 12월 4일
Thanks to both of you. I've accepted this answer only because it was first
ME
ME 2019년 12월 4일
No Worries! I'm glad you got the answer you wanted.

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

추가 답변 (1개)

ME
ME 2019년 12월 4일
편집: ME 2019년 12월 4일
idx = find(SmoothedData > Threshold);
Width = Xdata(max(idx)) - Xdata(min(idx));
Here the first line finds all indices of points above some threshold value. Then the second line calculates the time spent above this threshold by finding the difference between the X data points associated with the maximum and minimum indices.
Obviously, you'll need to adjust this to match your particular variable names, etc.
Is that what you wanted?

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by