f



How do I calculate the phase shift between two sinusoidal signals?

Hi,
I have a big problem:
I have 2 arrays "a" and "b" of size [1x1909]. How do I calculate the phase shift between this two signals? there is a .m files ready?
thanks for help
Regards!
0
1/27/2011 1:31:47 PM
comp.soft-sys.matlab 211266 articles. 15 followers. lunamoonmoon (258) is leader. Post Follow

10 Replies
14600 Views

Similar Articles

[PageSpeed] 1

On 27/01/11 12:31 PM, Giuseppe wrote:

> I have a big problem:
> I have 2 arrays "a" and "b" of size [1x1909]. How do I calculate the phase shift between this two signals? there is a .m files ready?

fft(a), drop the first point (the constant term), angle() the result

fft(b), drop the first point, angle() the result

phase shift is then abs() of the difference in angles.

If you have a pure sinusoidal then then angle should be very close to 0 
except at the frequency of the wave. You could probably clip out noise 
via something like

fft_a(abs(fft_a) < threshhold) = 0;

and likewise for the fft of b.
0
Think
1/27/2011 9:46:57 PM
fft (a) I have an array with the first term (real) = 46,1373794890328

fft (b)--> the first term (real) = 804,447713718616

and now how should I proceed?
thanks
regards
-1
Giuseppe
1/28/2011 3:27:09 AM
On 28/01/11 2:27 AM, Giuseppe wrote:
> fft (a) I have an array with the first term (real) = 46,1373794890328
>
> fft (b)-->  the first term (real) = 804,447713718616

I do believe that I said to drop the first term. Drop means "throw it away".

 >
 > and now how should I proceed?

Well, what I wrote before was:

 >> fft(a), drop the first point (the constant term), angle() the result

 >> fft(b), drop the first point, angle() the result

 >> phase shift is then abs() of the difference in angles.

 >> If you have a pure sinusoidal then then angle should be very close
 >> to 0 except at the frequency of the wave. You could probably clip
 >> out noise via something like

 >> fft_a(abs(fft_a) < threshhold) = 0;

 >> and likewise for the fft of b.


fft_a = fft(a);  %fft(a)
fft_a = fft_a(2:end);  %drop the first point
angle_a = angle(fft_a);  %angle() the result
fft_b = fft(b); %fft(b)
fft_b = fft_b(2:end);  %drop the first point
angle_b = angle(fft_b); %angle() the result
phase_shift = abs(angle_a - angle_b);

or with noise reduction,

fft_a = fft(a);  %fft(a)
fft_a = fft_a(2:end);  %drop the first point
fft_a(abs(fft_a) < 1e-10) = 0;  %some threshold
angle_a = angle(fft_a);  %angle() the result
fft_b = fft(b); %fft(b)
fft_b = fft_b(2:end);  %drop the first point
fft_b(abs(fft_b) < 1e-10) = 0;  %some threshold
angle_b = angle(fft_b); %angle() the result
phase_shift = abs(angle_a - angle_b);
3
Think
1/28/2011 11:56:15 AM
Giuseppe <caesar_539@hotmail.it> wrote in message <1875866377.4904.1296153140587.JavaMail.root@gallium.mathforum.org>...
> Hi,
> I have a big problem:
> I have 2 arrays "a" and "b" of size [1x1909]. How do I calculate the phase shift between this two signals? there is a .m files ready?
> thanks for help
> Regards!

You have 2 vectors of samples of the same sinus signal with a different Phase?
The best way to measure the phase would be using inner product.
0
Royi
1/28/2011 12:06:03 PM
On 28/01/11 6:06 AM, Royi Avital wrote:
> Giuseppe <caesar_539@hotmail.it> wrote in message
> <1875866377.4904.1296153140587.JavaMail.root@gallium.mathforum.org>...

>> I have a big problem:
>> I have 2 arrays "a" and "b" of size [1x1909]. How do I calculate the
>> phase shift between this two signals? there is a .m files ready?
>> thanks for help
>> Regards!
>
> You have 2 vectors of samples of the same sinus signal with a different
> Phase?
> The best way to measure the phase would be using inner product.

Or put in to clumsy code,

acos(dot(a,b) ./ (dot(a,a)*dot(b,b)))

This would, though, not be able to handle the situation where the arrays 
contained a mix of frequencies.
0
Think
1/28/2011 12:22:06 PM
Thanks.. But I should get a number and not the array phase_shift! I can make the mean? (mean phase_shift)
0
Giuseppe
1/28/2011 2:36:13 PM
I tried the code acos(dot (a, b). / (dot (a, A) * dot(b,b))) but I do not have the exact result I should have 138° but I have 1.5200, then 180 * 1:52 / pi = 87° .. 
How Could I do?
if you want i can send you the 2 array!
thanks
0
Giuseppe
1/28/2011 4:45:58 PM
On 11-01-28 01:36 PM, Giuseppe wrote:
> Thanks.. But I should get a number and not the array phase_shift! I can make the mean? (mean phase_shift)

No, do *not* take the mean of the array.

The dot product solution proposed by someone else, and which I gave code for 
in response, returns back the single number you are hoping for.

The dot product solution assumes that if there are multiple frequencies 
present, then the phase shift is the same for all of them. The fft solution I 
gave is able to isolate down different phase shifts for different frequencies.
0
Think
1/28/2011 9:01:07 PM
Giuseppe <caesar_539@hotmail.it> wrote in message <711823938.11516.1296251189039.JavaMail.root@gallium.mathforum.org>...
> I tried the code acos(dot (a, b). / (dot (a, A) * dot(b,b))) but I do not have the exact result I should have 138° but I have 1.5200, then 180 * 1:52 / pi = 87° .. 
> How Could I do?
> if you want i can send you the 2 array!
> thanks

Good Morning Guiseppe I also tried the above equation and got similiar results when I google for phase difference this solution comes up time and time again.

I think you want to use
acos(dot(a,b)/(norm(a)*norm(b)))

--Marc

I just stated to work on this issue if I find out that I am incorrect I will eat humble pie and repost a better solution
0
12/31/2012 11:13:20 AM
> acos(dot(a,b) ./ (dot(a,a)*dot(b,b)))
> 
> This would, though, not be able to handle the situation where the arrays 
> contained a mix of frequencies.


I think this code can not approximate if the shift is positive or negative, for example:

w = 2;
t = 0:0.01:10;
Y = -pi/6;
f1 = sin(w*t)+cos(w*t);
u1 = sin(w*t+Y)+cos(w*t+Y);
acos(dot(f1,u1)/(norm(f1)*norm(u1))) 

= pi/6 instead of -pi/6

Is there a way to obtain correct sign? 
0
Baha
1/31/2016 10:56:04 PM
Reply:

Similar Artilces:

Signal Phase Shift (co-phased signals)
I am trying to perform a phase shift based on the information provided in the following URL http://www.dsprelated.com/groups/matlab/show/5198.php However, I am not sure if I follow the instructions precisely since I am getting 'Imaginary parts of complex X and/or Y arguments ignored' warning. I understand this error is generated when in second plot I try to plot S1 signal when its a complex number. I need to plot S1 as without it I cannot visually see if any phase shift of 90 degrees has actually been done. Any help would greatly be appreciated. Any information on signal co-p...

how to find phase shift between two signals
Hi to all, I am presently facing problem with finding the phase shift in two Digital signals in MATLAB. I have two signals one is standard sine wave and other is output of my mechanical system which is again sine wave with some phase shift. can any body tell me how can I find exact phase shift in MATLAB. Thank you in advance with regards suhas deshmukh IIT Bombay India suhas.deshmukh@gmail.com wrote: > Hi to all, > I am presently facing problem with finding the phase shift in two > Digital signals in MATLAB. I have two signals one is standard sine wave > and other is output of...

phase shift between harmonics in two signals
Hello, I have next problem. There are two signals: the original one and the signal which is a system's response on the first one. In a simple case I use a combination (sum) of sine waves with different frequencies as the original signal. Output signal will be a sum of multiple sine waves with the same frequencies; however, on each frequency it will have different phase shift. How can I determine phase shift for each frequency? Thanks. "Ivan Romadanov" <r.ivan@samsung.com> wrote in message <l08pu7$bru$1@newscl01ah.mathworks.com>... > Hello, > > I h...

determining phase lag between two sinusoidal signals
I have two sinusoidal signals that I would like to compare the lag between them. can I use matlab to do it? Is there an option in matlab's fft function to extract the info easily? thanks. On 15 May, 04:33, dean <deanmi2...@yahoo.com> wrote: > I have two sinusoidal signals that I would like to compare the lag > between them. can I use matlab to do it? Certainly. > Is there an option in > matlab's fft function to extract the info easily? thanks. No. You would probably find some sort of cross spectrum more useful. Either use a canned routine lik XCORR in the signal p...

how to send a sinusoidal signal to an AO with a fixed phase difference with aother sinusoidal signal from an AI? Thank you!
In a While Loop, read a sinusoidal signal from an AI, extract frequency, amplitude and phase, and send a sinusoidal signal to an AO with a fixed phase difference and same frequency with the AI signal. &nbsp; Thank you very much! &nbsp; Marlon &nbsp;&nbsp;&nbsp; The simplest way I would do it if the system pemits (without RT, FFT, convolution etc) &nbsp;: Set AO and AI with the same clock, Connect two of AO channels with two of AI channels. Generate AO voltalge ( sin , and cos )&nbsp;near the expected frequency,record it at AI&nbsp;&nbsp;together&nbsp; w...

Guidance in determining phase difference between two sinusoidal signals needed
Hi, I need some guidance in the selection of an algorithm to solve a specific problem. My problem consists of determining the phase difference between two 150Hz (range within 1 Hz) sinusoidal signal with correlated noise between signals but with good signal-to-noise ratio. The estimation must be very precise (within 1x10(-7) rad if possible) and use a limited number of samples to keep latency low - an online algorithm could be the way to go as phase shifts happens slowly. I have been looking at high resolution sub space methods but I'm not sure this is the answer to my problem. My overvie...

How to introduce a phase shift into a signal which is a function of a variable theta either using Simulink /Matlab commands?
Hi.. I have got a signal “psi(theta)”,where theta varies in 2*pi radians. For my further system I need a signal “psi(theta-(2*pi/3))” where psi(theta) is a function of another signal phi(theta) and phi(theta)=integration(B(theta)*S) limits -90+alpha to +90+alpha. How do I get it…? Thanks..!!! Abhijit. ...

How to get the phase shift, the amplitude ratio and cross power spectral density Pxy between two signals?
How to get the phase shift, the amplitude ratio and cross power spectral density Pxy between two signals? Hi, I am new to matlab and signal processing. I have a problem: I have 2 signals, one is regarded to be the input (x) and the other is the output (y). They have the same frequency. The relation between input x and output y is given by the frequency response function H, which is the Fourier transform of the unit impulse response function of the system. And the frequency response function can be calculated optimally from the input power spectral density Pxx and the cross power spectral den...

MATLAB Phase Calculation
Hi everyone, I'm not very used in Matlab and exspecially in Fourier Transforms calculation. My problem is this one: I have to calculate and plot the phase spectrum of a signal that is not centered around zero. I realized that Matlab seems only to make a good calculation for a symmetric signal (odd or even) but it doesn't give any good results if I input a general signal. To perform calculation I used this code function [S_k,a,phi,pw,freq]=serfourier(x,y) T=abs(x(end)-x(1)); N=numel(x); x_l=x; y_l=y; k=N/2; f=1/T; f_max=k/T; l=-fix(k):fix(k); S_k=zeros(1,2*k); % pre-allocation ...

Getting the phase of the original signal from a time shifted version.. phase wrap/unwrap?
Hi, I've been trying to get the phase of the original signal (x) from its time shifted version (y). I first calculate the fft of y. Then I calculate the phase shift for each k as phase shift at k = 2*pi*k*shift/N where N is the total number of fft points and k is the index for each point. Then i just add the phase shift at k to the angle i get from the fft of y at k. I hope this isnt confusing. The problem is though the theory seems to be correct this doesnt really work. looking at the phase i get after the whole process described and the real phase of x ... I can tell that the v...

How do I Phase shift a signal?
Hello, I need to shift the phase of a time-discrete signal by a variable degree (but only one at a time). I tried to do the fft, then multiply with exp(j*phase), then do the ifft. But it didn't work. I didn't even get a sine transformed into a cosine that way... I hope that any of you could help me. On May 30, 9:22 pm, "Christoph Neeb" <christoph_n...@gmx.de> wrote: > Hello, > > I need to shift the phase of a time-discrete signal by a variable > degree (but only one at a time). I tried to do the fft, then multiply > with exp(j*phase), then do the ifft....

How to phase shift a signal
Hi everybody, I'm generating a signal using simulink, but my problem i need to shift it right and left. this is easy by adjusting the parameters when the block diagram is initialised, by during the run-time, how could this be achieved? Imagin the following scenario, if I have a sine generator, and I set the phase shift initially to zero, but a controller decided to shift it to the right by 10 degrees during run-time, the sine wave generator has no input as we all know, so how to keep modifing its phase shift in an on-line fashion??? Thanks a lot in advance... ...

how to calculate the phase difference between two square wave (acquired from two channel in one DAQ)
Hello everyone , &nbsp; &nbsp;I need a quickly help that as below : I am trying use PCI-6220 to acquired six signals from one rotation encoder (channel A, channel B,channel Z ,and their non-signals) .The encoder out signals will be square wave and&nbsp;4000pulses per revolution. I set it rotation at 300rpm speed. I need show every square wave of six out channels in waveform and measure the A-B phase difference to check if the value is correct (designed value should be 90deg)&nbsp;. I have no idea how to measure or calculate the phase difference of two square wave base on synch...

Signal Gain and Phase Calculation
I'd like to determine the signal gain and phase shift for 2 sinusoidal signals that I am acquiring from data acquisition equipment. Are there Matlab commands to do this? Background: I am basically trying to inject a sine wave into a system and capture the sine wave coming out and use those 2 acquired signals in Matlab to calculate the frequency response of the system (Bode plot of the system). Perhaps one of the toolboxes does this? I'm a Matlab beginner so any input will help. Thanks! Mike Fogarty wrote: > > > I'd like to determine the signal gain and phase shift for...

Web resources about - How do I calculate the phase shift between two sinusoidal signals? - comp.soft-sys.matlab

Sinusoidal plane-wave solutions of the electromagnetic wave equation - Wikipedia, the free encyclopedia ...
Sinusoidal plane-wave solutions are particular solutions to the electromagnetic wave equation . The general solution of the electromagnetic ...

Non-sinusoidal waveform - Wikipedia, the free encyclopedia
Non-sinusoidal waveforms are waveforms that are not pure sine waves . They are usually derived from simple math functions. While a pure sine ...

Sinusoidal projection - Wikipedia, the free encyclopedia
The sinusoidal projection is a pseudocylindrical equal-area map projection , sometimes called the Sanson–Flamsteed or the Mercator equal-area ...

Resources last updated: 2/10/2016 7:55:56 PM