Get the position, period and the amplitud of the wave.

조회 수: 8 (최근 30일)
Vicente
Vicente 2023년 4월 24일
댓글: Antoni Garcia-Herreros 2023년 4월 24일
As I wrote in the title I have a wave and I want to get the period of it, the amplitud and the top peack of it. I already got a code that I tried but it does not work to me, do not know why. I upload the matlab data simplify the task. Thank you in advance!

채택된 답변

Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023년 4월 24일
편집: Antoni Garcia-Herreros 2023년 4월 24일
Hello Vicente,
You can try a couple of different approaches:
Option A: Use findpeaks function to get the values of the peaks and compute the differences to obtain the amplitude and the period.
x=Tm(4000:5000);
y=P01m(4000:5000);
[Mpy,Mpx]=findpeaks(y); % Find local maximums
[mpy,mpx]=findpeaks(-y);% Find local minimums
T=mean(diff(x(Mpx))); % Period
A=mean(y(Mpx)-y(mpx(1:end-1)))*0.5; %Amplitude
toppeak=mean(Mpy); %Max peak value
Option B: Fit your data into a sinusoidal and use the parameters to obtain the desired values
fitfun = fittype( @(a,b,x) a*sin(b*x+c)); % Define the sinusoidal
[fitted_curve] = fit(x,y,fitfun,'StartPoint',[5.3,6.97,-7.6])
plot(x,y,'.') %Plot the model to ensure the fit works
hold on
plot(x,fitted_curve(x))
A=fitted_curve.a; % Amplitude of your wave
T=2*pi/fitted_curve.b; % Period = 2pi/f
  댓글 수: 2
Vicente
Vicente 2023년 4월 24일
Hi, thank you for the options, could you tell me which variable is fpx in the first option, it causes error in the code.
Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023년 4월 24일
Sorry, it was a typo, I just eddited the code

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by