Determining the phase shift from the samples of the sinusoidal wave?

Hello, I have two waves like A and B. (A represents the input of the system, B output.) What I know is the frequency and amplitude of the A wave, and what I do not know is the amplitude and phase of the B wave. Can I access phase and amplitude information using the samples of A and B? (The code below is for collecting data, normally I don't know the phase and amplitude of B, I just know samples.)
w = 5;
gain = 2;
phase = pi/2;
A = 5*sin(w*t);
B = 5*gain*sin(w*t + phase);

2 comentarios

is wave B of same frequency as wave A?
Yes, they have same frequencies but B has an additional phase and some gain.

Iniciar sesión para comentar.

 Respuesta aceptada

Assuming that w is known, and that you have an identical time array for each of A and B, and that t and B are column arrays, then
c = [sin(w*t) cos(w*t)]\B
amplitude = norm(c)
phase = atan2(c(2),c(1))
That's the full ampllitude, so in your case gain = amplitude/5.

4 comentarios

Thank you for your response, I think I missed a point because I take the values like 158.0128 for amplitude and 0 for the phase. Here is my code:
w = 5;
gain = 2;
phase = pi/2;
t=0:0.01:5;
A = 5*sin(w*t);
B = 5*gain*sin(w*t + phase);
c = [sin(w*t) cos(w*t)]\B;
amplitude = norm(c)
phase = atan2(c(2),c(1))
Hi Berke,
I had stated that t and B were column arrays, but maybe that point was not emphasized enough. Here is the code, modified so that t and B cannot be rows:
w = 5;
gain = 2;
phase = pi/2;
t=0:0.01:5;
A = 5*sin(w*t);
B = 5*gain*sin(w*t + phase);
t = t(:);
B = B(:);
c = [sin(w*t) cos(w*t)]\B
amplitude = norm(c)
phase = atan2(c(2),c(1))
amplitude =
10.0000
phase =
1.5708
Berke Ogulcan Parlak
Berke Ogulcan Parlak el 2 de Abr. de 2020
Editada: Berke Ogulcan Parlak el 2 de Abr. de 2020
Hi David,
This worked really well for me! But I will have one last question for you. There is something I do not understand in the mathematical background. What is the mathematical meaning of 'c' you calculate here?
HI Berke,
the idea is that you have a column vector B, and m linearly independent column vectors vec1, vec2, ... vecm. All of these vectors are nx1. You want to find m coefficients such that c1*vec1 + c2*vec2 ...+ cm*vecm is the best fit to B. In your case m = 2 so put column vectors sin(w*t) and cos(w*t) side-by-side to form a 2xn matrix M. Then in matrix notation, with time varying down the columns,
[ sin(w*t) cos(w*t) ] [c1] [ B(t) ]
[ . . ] [c2] [ . ]
[ . . ] x = [ . ]
[ . . ] [ . ]
[ . . ] [ . ]
This works since everything in the sine column is mulitplied by c1 and everything in the cos column is mulitplied by c2. As is usually the case there are more equations than unknowns, so this has to be solved approximately. The matrix eqn is M*c = B, and and in Matlab this is solved in the least-squares sense with left divide,
c = M\B
So now
B = c(1)*sin(w*t) + c(2)*cos(w*t) = amplitude*sin(w*t + phase)
and proceed from there.
Easy as it is to use, there is a lot going on behind the scenes with the left divide symbol. Left divide (backslash) is basically how Mathworks got its start. I still think it's the best function in Matlab history, although the way things are going maybe some fabulous neural network function will eventually take the honor.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by