Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to determine phase diffference between I and Q signals using complex FFT?

Status
Not open for further replies.

Terminator3

Advanced Member level 3
Joined
Feb 25, 2012
Messages
802
Helped
71
Reputation
142
Reaction score
63
Trophy points
1,308
Activity points
9,027
In complex signals negative part of spectrum can be used somehow to determine phase shift. I hope. How?
 

The phase difference between I and Q components is always pi/2 I think
 

The phase difference between I and Q components is always pi/2 I think
yes, in theory. But also it can be +-pi/2 (for higher/lower freqs than LO). Actually i want other angles too, if i put there delayed signal.
Currently i convert 1 complex fft to 2 real FFTs, then calculate phase difference. But the problem is it is difficult to smooth: phase and amplitude need to be converted back to X,Y vector, summed, and atan back to polar Amp and phase...
 

Maybe I dont understand. What do you want to do?
If you have a real signal (vector of samples) and want to find a instant phase for every sample, then read about analytic signal and hilbert transform, or you should have a quadrature receiver.
Or what else?
 

I need to know relative phases of two signals (identical slowly changing frequency). BUT also i want to do smoothing of this phase difference over time.
At the moment i do complex FFT of complex input (two channels), rearrange output and get 2 real spectrums separately for each signal, calculate phases, calculate phase differences, calculate amplitudes. After that i use phase to project amplitude on X and Y plane to do time-smoothing, bacause averaging phase not taking into account amplitude gives bad result. Then, after smoothing, i take smoothed X and Y and calculate atan2 and get smoothed phase difference. So it works this way.

Why i still have this question i because while observing complex FFT output i realized, that it somehow can be directly smoothed, and with trial and error i was able to produce algorithm, that analyses scalar multiplication of complex spectrum vectors. But it works only for signals with similar amplitude:
cfft.jpg
Actually it takes complex spectrum, calculate amplitudes using sqrt for full 1024 spectrum (real 512 and "negative" frequency part from 512 to 1024).
Then i add sign to amplitude spectrum using this way:
mult:=round(specA[maxi]*specB[1024-maxi]+specB[maxi]*specA[1024-maxi]);
if mult<0 then
begin
if specL[maxi]>specR[maxi] then
begin
specR[maxi]:=-specR[maxi]
end else
if specL[maxi]<specR[maxi] then
specL[maxi]:=-specL[maxi];
end;
This thing can be smoothed, because specL and specR is just an vector (X,Y). Again, i realized how to do that only for signals for similar amplitude.

So i now use the old way:
1) take real spectrums of each signal
2) calculate phases
3) calculate amplitudes
4) calculate phase differences
5) project amplitudes using phase on X,Y axis
6) smooth
7) atan of smoothed X,Y to get smoothed amplitude and phase

Another method (code above), that worked only for similar amplitude, is much more effective:
1) calculate complex spectrum
2) calculate amplitudes
3) change sign of amplitudes based on complex spectrum
4) smooth
5) make atan of smoothed data to get smoothed phase and amplitude
it would be faster and less of code.
 

I need to know relative phases of two signals (identical slowly changing frequency). BUT also i want to do smoothing of this phase difference over time.
At the moment i do complex FFT of complex input (two channels), rearrange output and get 2 real spectrums separately for each signal, calculate phases, calculate phase differences, calculate amplitudes. After that i use phase to project amplitude on X and Y plane to do time-smoothing, bacause averaging phase not taking into account amplitude gives bad result. Then, after smoothing, i take smoothed X and Y and calculate atan2 and get smoothed phase difference. So it works this way.

Why i still have this question i because while observing complex FFT output i realized, that it somehow can be directly smoothed, and with trial and error i was able to produce algorithm, that analyses scalar multiplication of complex spectrum vectors. But it works only for signals with similar amplitude:
View attachment 92327
Actually it takes complex spectrum, calculate amplitudes using sqrt for full 1024 spectrum (real 512 and "negative" frequency part from 512 to 1024).
Then i add sign to amplitude spectrum using this way:

This thing can be smoothed, because specL and specR is just an vector (X,Y). Again, i realized how to do that only for signals for similar amplitude.

So i now use the old way:
1) take real spectrums of each signal
2) calculate phases
3) calculate amplitudes
4) calculate phase differences
5) project amplitudes using phase on X,Y axis
6) smooth
7) atan of smoothed X,Y to get smoothed amplitude and phase

Another method (code above), that worked only for similar amplitude, is much more effective:
1) calculate complex spectrum
2) calculate amplitudes
3) change sign of amplitudes based on complex spectrum
4) smooth
5) make atan of smoothed data to get smoothed phase and amplitude
it would be faster and less of code.
I think I see the confusion. The terminology I and Q is usually applied to two signals that are exactly 90 degrees out of phase, and then they are usually added together to make one signal. You have two signals that are not necessarily 90 degrees out of phase, and are not added together. You just want to determine the relative phase of the two. First you have to assume that the relative phase is fairly constant over the length of sample period. If the phase is changing faster than that, you need to use shorter sample periods with fewer samples. So assuming the phase is constant, the angle between the complex numbers near the peak amplitude is the phase relationship you want. And if you want to be more accurate you could interpolate between the nearest two bins to the peak. If you know the exact frequency apriori then you can apply that information to help you interpolate between two frequency bins.
 

Up! Anybody? I want to calculate difference between two signals. Traditional way: real fft1, real fft2, calculate difference.
What do i want: complex fft - then formulas above - and phase is here. But it works only if signals are similar in amplitude. And there is a picture from my program that shows the problem. If you tell that 2 x real fft and 1 complex fft time is similar, and why do i want complex fft: results of complex FFT can be smoothed using faster algorithm. Please review formulas from code above, i have no confusion about FFT or something, i have IQ reciever, and i feed I and Q channels WITH SIGNALS that are NOT 90 deg in phase shift. Shift can be in any range, obtained by phase delay element!
Question is how using method with scalar multiplication of complex spectrum vectors retrieve phase difference for signals with different amplitude. WIth similar amplitude it works, you can check out formulas above!
 

Even if in theory I and Q signal have to be 90 degrees out of phase, real modulators doesn't perfectly preserve this, so you can have slight differences between actual and theoretical phases. This are usual impairement, toghether with amplitude differences between I and Q and different DC offsets.

However, as far as I correctly understood what you want, simply take the fft of signal 1 let's call it ff1=fft(s1) and fft of signal 2: ff2=fft(s2)

The phase of the signal s1 (with respect to the first sample taken into account) is

ph1=atan(imag(ff1)/real(ff1))

the same for the signal 2:

ph2=atan(imag(ff2)/real(ff2))

If s1 and s2 are sampled at the same instant then:

Delta(Phase)=ph1-ph2

take into account that usually the phase is wrapped between -pi/2 and pi/2
 
I currently do as you said, although use four quadrant atan function, because with simple atan obtain some wrong results when using random test data with random phase shifts in both channels. The bad thing is that i can't interpolate phase difference without taking atan for each frequency bin. If using complex fft of this two-channel signal, complex spectrum can be interpolated before, and atan called only in the end for required bins (with high amplitude). So with complex FFT it can be made very fast. With two real FFTs it is impossible to do so fast, as to know phase difference we must first take an atan for both spectrums. And in complex FFT phase difference already encoded in vectors, so they can be interpolated first, and then angle determined using atan.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top