How to plot a restoration-based envelope in matlab

조회 수: 1 (최근 30일)
Proman
Proman 2020년 9월 5일
댓글: Proman 2020년 9월 6일
Hello greetings to everyone
I have a damping sine curve (code and data attached) as the following
and I intend to do the following action on it, and make an envelope like the dashed curve:
How can I plot these max and min and plot a fit envelope like the dashed curve as above in MATLAB (The crosses are the midpoint of each line on which they are located)
Thanks in advance for your time given on this question and stay healthy

채택된 답변

Alan Stevens
Alan Stevens 2020년 9월 6일
Here's a "starter for ten"! I've used approximate time intervals:
T = t(end)/10; % period - there seem to be 10 periods in the range
it = t(t<=T); % times up to one period
dt = numel(it)/2; % number of time points in a half period
n = 20; % total number of half periods
mn = zeros(n,1); % store for minima
mn(end) = min(R1); % last minimum
mx = mn; % store for maxima
mx(1) = 1; % first maximum
% Find sizes of minima and maxima
for i = 2:n
tspan = (i-1)*dt:i*dt;
mn(i-1) = min(R1(tspan));
mx(i) = max(R1(tspan));
end
% Assume "restoration" times occur at half period intervals
% starting at T/4 (an approximation)
Ravpts = (mn+mx)/2;
tavpts = (T/4:T/2:n*T/2);
% Interpolate for "restoration" plot
tav = T/4:t(end);
Rav = interp1(tavpts,Ravpts,tav,'pchip');
% Plots
plot(t,R1,tavpts,Ravpts,'o',tav,Rav,'k--'), grid
xlabel('t'),ylabel('damped sinusoid')
legend('data','restoration points','interpolated restoration')
This is the result:
  댓글 수: 1
Proman
Proman 2020년 9월 6일
A million thanks my friend! That's exactly what I wanted *_*

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by