Calculating Amplitude, Frequency and phase of a sin wave

10 次查看(过去 30 天)
Hello. I have been tasked to create a function that calculates amplitude, frequency and phase of a sin wave. The amplitude and frequency of said function are constantly changing. What I know about the sin:
The function: y(x) = A*sin(B*x + C) + D There are 128 samples, as in x = < 1,128 > C and D are constant values, and A&B are supposed to be changing linerary.
Since I have to generate the function myself, it's pretty obvious that I already know the values of A,B,C and D parameters. The final function, however, has to be able to calculate those parameters for sin waves, where the only known parameters are the wave's sampling frequency, number of samples and the result of the function for each sample.
For the sake of testing I have created the function using the following code:
x1 = 0.04290625:0.0490625:2*pi; %128 samples
A1 = 1:0.2:26.5; %Amplitude varies from 1 to 26.5
B1 = 0.01:0.01:1.28;
C1 = 1;
D1 = 1;
y1 = A1.*sin(x.*B1 + C1) + D1; %the sin wave
plot(y1)
Now, knowing only the values of "x1" and "y1" for each point in time, as well as sampling frequency, I have to calculate A,B,C and D for each point of "y1" in time. After this, I would have to plot "A" and "B" to show how they behave over time.
Since I don't want to abuse Your knowledge for my assigment, I would only like to receive an answer that would lead me on a correct path.
I assume that because of phase shifts in the sin wave, calculating amplitude with the regular (max(y)-min(y))/2 won't work.
For frequency, I belive I'll need to use FFT? I'm sorry if those questions seem trival to You, but sadly I don't really know where to begin.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by