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

조회 수: 35 (최근 30일)
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
Mehmed Saad
Mehmed Saad 2020년 4월 1일
is wave B of same frequency as wave A?
Berke Ogulcan Parlak
Berke Ogulcan Parlak 2020년 4월 1일
Yes, they have same frequencies but B has an additional phase and some gain.

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

채택된 답변

David Goodmanson
David Goodmanson 2020년 4월 1일
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
Berke Ogulcan Parlak
Berke Ogulcan Parlak 2020년 4월 2일
편집: Berke Ogulcan Parlak 2020년 4월 2일
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?
David Goodmanson
David Goodmanson 2020년 4월 2일
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.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by