How to determine the lag angle between two snine wave

1 view (last 30 days)
% I need to calculate the angle of the rotational vector B=Bmx+i*Bmy
% wheree Bmx and Bmy are 90 degree outof phase
% here is the code
close all
t=zeros(N,1); Bmx=zeros(N,1); Bmy=zeros(N,1);
for k=1:N+1
%when I use this command the lag angle between Bmx ,,and Bmy is not 90
phase_difB= acos( dot(Bmx,Bmy) / (norm(Bmx)*norm(Bmy)) )*180/pi;
% the result is 94 and the lag angle between is is thetaB=90;
% and if there is another vector H=Hx+i*Hy
%how can I determine the angle between B and H

Answers (2)

the cyclist
the cyclist on 14 Jan 2022
I believe you will only get exactly 90 if you could sample at infinitesimal resolution and/or a signal that extends for infinite time.
Due to the finite resolution and extent, you will only get an approximation.

David Goodmanson
David Goodmanson on 14 Jan 2022
Edited: David Goodmanson on 14 Jan 2022
Hi Hassan
Consider the complex wave
exp(i*(w*t+theta)) = cos(w*t+theta) + i*sin(w*t+theta)
While it's true that the cos and sin terms are 90 degrees out of phase, I think there are better ways to look at things than concentrating on that particular phase shift. It's better to take that phase shift for granted an look at the complex wave as a single entity:
exp(i*(w*t+theta)) = exp(i*w*t)*exp(i*theta)
In a system with several components oscillating at a single frequency, the exp(i*w*t) factor is common to all of them and the exp(i*theta) factor (the phasor) determines the relative phase of the components. For example,
t = (0:.001:1)'; % column vector
f = 10
w = 2*pi*f;
A1 = 5;
A2 = 2;
th1 = 30*(pi/180);
th2 = 175*(pi/180);
sig1 = A1*exp(i*(w*t +th1));
sig2 = A2*exp(i*(w*t +th2)); % the two systems have relative phase of 145 degrees.
% determine the relative angle by similar method to that in the question
relative_angle = angled((sig1'*sig2)/sqrt((sig1'*sig1)*(sig2'*sig2)))
relative_angle = 145.0000
Here angled was used since it converts to degrees
  1 Comment
Hassan Abdelazeem
Hassan Abdelazeem on 20 Jan 2022
Dear David
Thank you for your reply, it is quite useful for me

Sign in to comment.


Find more on Portfolio Optimization and Asset Allocation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!