Average of a each vertical section of a stepped sawtooth wave

조회 수: 2 (최근 30일)
Raj
Raj 2021년 3월 24일
댓글: Raj 2021년 3월 28일
Hello everyone. I need a help to find the average of each vertical steps in a stepped sawtooth wave. For clarity, I have attached the figure of sawtooth wave. Just to reiterate how can I find the average of each small vertical steps in the attached stepped sawtooth wave? Thank you for the help in advance.

채택된 답변

Matt J
Matt J 2021년 3월 25일
I would fit a line to the steps with polyfit, then find the intersections of the line fit with the vertical edges.
  댓글 수: 3
Matt J
Matt J 2021년 3월 25일
편집: Matt J 2021년 3월 25일
x=linspace(0,10,1000); %Example staircase data
y=round(x);
p=polyfit(x,y,1);
yl=polyval(p,x);
idx=diff(sign(yl-y))<0;
xs=x(idx); ys=yl(idx);
plot(x,y,xs,ys,'ro')
Raj
Raj 2021년 3월 28일
Thank you so much for your clear explanation.

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

추가 답변 (1개)

Greg Dionne
Greg Dionne 2021년 3월 25일
If you have the Signal Processing Toolbox, FINDCHANGEPTS is worth a look (it will give you the indices of each step of which you can take the average later -- see https://www.mathworks.com/matlabcentral/answers/313651-additional-findchangepts-function-output?s_tid=srchtitle for an example on how to extract each mean).
Otherwise see if you can get ISCHANGE to work.
  댓글 수: 2
Raj
Raj 2021년 3월 25일
Thank you so much for your response. I have that tool box. However, I am not sure how to start with a code for my case. Could you please give me some pseudocode type sketch. I will attach a sample data if you need for this.
Greg Dionne
Greg Dionne 2021년 3월 25일
The example in "help findchangepts" should hopefully get you started.
If you post your data though, maybe another volunteer can come up with something even better!

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by