DSPRelated.com
Forums

Unwrapped Phase

Started by norwood_dave April 14, 2009
I have only taken one undergraduate DSP course and have started reading
about unwrapping phase.  

I was told if I had two signals in the time domain, the first signal
consisting of one period of 100Hz (100 points) followed by 100 zeros and
the second signal consisting of 100 zeros followed by one period of 100Hz
(100 points), I could take the FFT of each signal and average them in the
frequency domain.  I could then take the IFFT of this average and obtain a
signal consisting of 50 zeros followed by one period of 100Hz (100 points)
followed by 50 zeros.  If effect, the FFT average will average the time
delay.  HOWEVER, I must unwrap the phase when doing this.  

From my understanding about unwrap, I don't see a difference between phase
unwrapping versus taking the ATAN2(imag,real).  I tried numerous things in
matlab using my example signals above and have come up with nothing.  Is
this even possible?  Or, more likely I'm misunderstanding something.  Any
insight is greatly appreciated.  

 


norwood_dave wrote:
> I have only taken one undergraduate DSP course and have started reading > about unwrapping phase. > > I was told if I had two signals in the time domain, the first signal > consisting of one period of 100Hz (100 points) followed by 100 zeros and > the second signal consisting of 100 zeros followed by one period of 100Hz > (100 points), I could take the FFT of each signal and average them in the > frequency domain. I could then take the IFFT of this average and obtain a > signal consisting of 50 zeros followed by one period of 100Hz (100 points) > followed by 50 zeros. If effect, the FFT average will average the time > delay. HOWEVER, I must unwrap the phase when doing this. > > From my understanding about unwrap, I don't see a difference between phase > unwrapping versus taking the ATAN2(imag,real). I tried numerous things in > matlab using my example signals above and have come up with nothing. Is > this even possible? Or, more likely I'm misunderstanding something. Any > insight is greatly appreciated.
_Somebody_ was confused. If you take the two FFTs and average them 'normally' (i.e. add each complex number to it's fellow in the other FFT and divide by two) then take the IFFT, you should end up with the average of the two signals in the time domain. This is because the FFT is a linear transform, and averaging is a linear operation. If you take the two FFTs _in polar form_, with the phase unwrapped, and find the average of the magnitude and the average of the phase, then take the IFFT of the resulting spectrum, I _think_ that you will get your expected signal-with-average-delay. I'm not sure how useful this latter signal will be. It sounds more like a stupid pet trick with the FFT than something you could get desirable information out of, but who knows? -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
>norwood_dave wrote: >> I have only taken one undergraduate DSP course and have started
reading
>> about unwrapping phase. >> >> I was told if I had two signals in the time domain, the first signal >> consisting of one period of 100Hz (100 points) followed by 100 zeros
and
>> the second signal consisting of 100 zeros followed by one period of
100Hz
>> (100 points), I could take the FFT of each signal and average them in
the
>> frequency domain. I could then take the IFFT of this average and
obtain a
>> signal consisting of 50 zeros followed by one period of 100Hz (100
points)
>> followed by 50 zeros. If effect, the FFT average will average the
time
>> delay. HOWEVER, I must unwrap the phase when doing this. >> >> From my understanding about unwrap, I don't see a difference between
phase
>> unwrapping versus taking the ATAN2(imag,real). I tried numerous things
in
>> matlab using my example signals above and have come up with nothing.
Is
>> this even possible? Or, more likely I'm misunderstanding something.
Any
>> insight is greatly appreciated. > >_Somebody_ was confused. > >If you take the two FFTs and average them 'normally' (i.e. add each >complex number to it's fellow in the other FFT and divide by two) then >take the IFFT, you should end up with the average of the two signals in >the time domain. This is because the FFT is a linear transform, and >averaging is a linear operation. > >If you take the two FFTs _in polar form_, with the phase unwrapped, and >find the average of the magnitude and the average of the phase, then >take the IFFT of the resulting spectrum, I _think_ that you will get >your expected signal-with-average-delay. > >I'm not sure how useful this latter signal will be. It sounds more like
>a stupid pet trick with the FFT than something you could get desirable >information out of, but who knows? > >-- > >Tim Wescott >Wescott Design Services >http://www.wescottdesign.com > >Do you need to implement control loops in software? >"Applied Control Theory for Embedded Systems" was written for you. >See details at http://www.wescottdesign.com/actfes/actfes.html >
Thank you for the reply. I did try this with no luck. Here is my original code (for anyone to look over): %Generate one period of 100Hz t = 0:(1/10000):(1/100); a = sin(2*pi*100*t); %One Period of 100Hz + 100 zeros c = zeros(1,length(a) + 100); c(1:length(a)) = a; %100 zeros + One Period of 100Hz d = zeros(1,length(a) + 100); d(length(a):length(a) + 100) = a; % FFT of each waveform C = fft(c); D = fft(d); % Magnitude of each FFT data Cmag = abs(C); Dmag = abs(D); % Unwrapped Phase of each waveform for i = 1:length(C) CUphase(i) = unwrap(atan(imag(C(i))/real(C(i)))); DUphase(i) = unwrap(atan(imag(D(i))/real(C(i)))); end % Average Phase for i = 1:length(C) AvgUphase(i) = (CUphase(i) + DUphase(i))/2; end % Real and Imaginary for i = 1:length(C) AvgReal(i) = Cmag(i) * cos(AvgUphase(i)); AvgImag(i) = Cmag(i) * sin(AvgUphase(i)); end % Real and Imaginary to Complex and take IFFT AvgCplx = complex(AvgReal,AvgImag); avgcplx = ifft(AvgCplx); I tried both atan and atan2, wrapped and unwrapped, for calculating the phase of each waveform. Using wrapped-atan2 and unwrapped-atan2 to calculate phase produce the same complex IFFT results. And, wrapped-atan and unwrapped-atan produce the same IFFT results. Moreover, the real values from the complex IFFT results (from using wrapped or unwrapped atan2) are the same as the non-complex IFFT results (from using wrapped or unwrapped atan). It seems like they all are essentially producing the same results. I hope this is clear.
>>norwood_dave wrote: >>> I have only taken one undergraduate DSP course and have started >reading >>> about unwrapping phase. >>> >>> I was told if I had two signals in the time domain, the first signal >>> consisting of one period of 100Hz (100 points) followed by 100 zeros >and >>> the second signal consisting of 100 zeros followed by one period of >100Hz >>> (100 points), I could take the FFT of each signal and average them in >the >>> frequency domain. I could then take the IFFT of this average and >obtain a >>> signal consisting of 50 zeros followed by one period of 100Hz (100 >points) >>> followed by 50 zeros. If effect, the FFT average will average the >time >>> delay. HOWEVER, I must unwrap the phase when doing this. >>> >>> From my understanding about unwrap, I don't see a difference between >phase >>> unwrapping versus taking the ATAN2(imag,real). I tried numerous
things
>in >>> matlab using my example signals above and have come up with nothing. >Is >>> this even possible? Or, more likely I'm misunderstanding something. >Any >>> insight is greatly appreciated. >> >>_Somebody_ was confused. >> >>If you take the two FFTs and average them 'normally' (i.e. add each >>complex number to it's fellow in the other FFT and divide by two) then >>take the IFFT, you should end up with the average of the two signals in
>>the time domain. This is because the FFT is a linear transform, and >>averaging is a linear operation. >> >>If you take the two FFTs _in polar form_, with the phase unwrapped, and
>>find the average of the magnitude and the average of the phase, then >>take the IFFT of the resulting spectrum, I _think_ that you will get >>your expected signal-with-average-delay. >> >>I'm not sure how useful this latter signal will be. It sounds more
like
> >>a stupid pet trick with the FFT than something you could get desirable >>information out of, but who knows? >> >>-- >> >>Tim Wescott >>Wescott Design Services >>http://www.wescottdesign.com >> >>Do you need to implement control loops in software? >>"Applied Control Theory for Embedded Systems" was written for you. >>See details at http://www.wescottdesign.com/actfes/actfes.html >> > >Thank you for the reply. I did try this with no luck. Here is my >original code (for anyone to look over): > >%Generate one period of 100Hz >t = 0:(1/10000):(1/100); >a = sin(2*pi*100*t); > >%One Period of 100Hz + 100 zeros >c = zeros(1,length(a) + 100); >c(1:length(a)) = a; > >%100 zeros + One Period of 100Hz >d = zeros(1,length(a) + 100); >d(length(a):length(a) + 100) = a; > >% FFT of each waveform >C = fft(c); >D = fft(d); > >% Magnitude of each FFT data >Cmag = abs(C); >Dmag = abs(D); > >% Unwrapped Phase of each waveform >for i = 1:length(C) >CUphase(i) = unwrap(atan(imag(C(i))/real(C(i)))); >DUphase(i) = unwrap(atan(imag(D(i))/real(C(i)))); >end > >% Average Phase >for i = 1:length(C) >AvgUphase(i) = (CUphase(i) + DUphase(i))/2; >end > >% Real and Imaginary >for i = 1:length(C) >AvgReal(i) = Cmag(i) * cos(AvgUphase(i)); >AvgImag(i) = Cmag(i) * sin(AvgUphase(i)); >end > >% Real and Imaginary to Complex and take IFFT >AvgCplx = complex(AvgReal,AvgImag); >avgcplx = ifft(AvgCplx); > > >I tried both atan and atan2, wrapped and unwrapped, for calculating the >phase of each waveform. Using wrapped-atan2 and unwrapped-atan2 to >calculate phase produce the same complex IFFT results. And,
wrapped-atan
>and unwrapped-atan produce the same IFFT results. Moreover, the real >values from the complex IFFT results (from using wrapped or unwrapped >atan2) are the same as the non-complex IFFT results (from using wrapped
or
>unwrapped atan). > >It seems like they all are essentially producing the same results. > >I hope this is clear. > >
Please note in my code above: % Unwrapped Phase of each waveform for i = 1:length(C) CUphase(i) = unwrap(atan(imag(C(i))/real(C(i)))); DUphase(i) = unwrap(atan(imag(D(i))/real(D(i)))); end DUphase(i) = ... had real(C(i)) as the denom in the atan function. The noted change didn't help.
On Apr 14, 9:20&#4294967295;pm, "norwood_dave" <norwood_d...@yahoo.com> wrote:
> >>norwood_dave wrote: > >>> I have only taken one undergraduate DSP course and have started > >reading > >>> about unwrapping phase. &#4294967295; > > >>> I was told if I had two signals in the time domain, the first signal > >>> consisting of one period of 100Hz (100 points) followed by 100 zeros > >and > >>> the second signal consisting of 100 zeros followed by one period of > >100Hz > >>> (100 points), I could take the FFT of each signal and average them in > >the > >>> frequency domain. &#4294967295;I could then take the IFFT of this average and > >obtain a > >>> signal consisting of 50 zeros followed by one period of 100Hz (100 > >points) > >>> followed by 50 zeros. &#4294967295;If effect, the FFT average will average the > >time > >>> delay. &#4294967295;HOWEVER, I must unwrap the phase when doing this. &#4294967295; > > >>> From my understanding about unwrap, I don't see a difference between > >phase > >>> unwrapping versus taking the ATAN2(imag,real). &#4294967295;I tried numerous > things > >in > >>> matlab using my example signals above and have come up with nothing. > >Is > >>> this even possible? &#4294967295;Or, more likely I'm misunderstanding something. > >Any > >>> insight is greatly appreciated. &#4294967295; > > >>_Somebody_ was confused. > > >>If you take the two FFTs and average them 'normally' (i.e. add each > >>complex number to it's fellow in the other FFT and divide by two) then > >>take the IFFT, you should end up with the average of the two signals in > >>the time domain. &#4294967295;This is because the FFT is a linear transform, and > >>averaging is a linear operation. > > >>If you take the two FFTs _in polar form_, with the phase unwrapped, and > >>find the average of the magnitude and the average of the phase, then > >>take the IFFT of the resulting spectrum, I _think_ that you will get > >>your expected signal-with-average-delay. > > >>I'm not sure how useful this latter signal will be. &#4294967295;It sounds more > like > > >>a stupid pet trick with the FFT than something you could get desirable > >>information out of, but who knows? > > >>-- > > >>Tim Wescott > >>Wescott Design Services > >>http://www.wescottdesign.com > > >>Do you need to implement control loops in software? > >>"Applied Control Theory for Embedded Systems" was written for you. > >>See details athttp://www.wescottdesign.com/actfes/actfes.html > > >Thank you for the reply. &#4294967295;I did try this with no luck. &#4294967295;Here is my > >original code (for anyone to look over): > > >%Generate one period of 100Hz > >t = 0:(1/10000):(1/100); > >a = sin(2*pi*100*t); &#4294967295; &#4294967295; &#4294967295; > > >%One Period of 100Hz + 100 zeros > >c = zeros(1,length(a) + 100); > >c(1:length(a)) = a; > > >%100 zeros + One Period of 100Hz > >d = zeros(1,length(a) + 100); > >d(length(a):length(a) + 100) = a; &#4294967295; > > >% FFT of each waveform > >C = fft(c); > >D = fft(d); > > >% Magnitude of each FFT data > >Cmag = abs(C); > >Dmag = abs(D); > > >% Unwrapped Phase of each waveform > >for i = 1:length(C) > >CUphase(i) = unwrap(atan(imag(C(i))/real(C(i)))); > >DUphase(i) = unwrap(atan(imag(D(i))/real(C(i)))); > >end > > >% Average Phase > >for i = 1:length(C) > >AvgUphase(i) = (CUphase(i) + DUphase(i))/2; > >end > > >% Real and Imaginary > >for i = 1:length(C) > >AvgReal(i) = Cmag(i) * cos(AvgUphase(i)); > >AvgImag(i) = Cmag(i) * sin(AvgUphase(i)); > >end > > >% Real and Imaginary to Complex and take IFFT > >AvgCplx = complex(AvgReal,AvgImag); > >avgcplx = ifft(AvgCplx); > > >I tried both atan and atan2, wrapped and unwrapped, for calculating the > >phase of each waveform. &#4294967295;Using wrapped-atan2 and unwrapped-atan2 to > >calculate phase produce the same complex IFFT results. &#4294967295;And, > wrapped-atan > >and unwrapped-atan produce the same IFFT results. &#4294967295;Moreover, the real > >values from the complex IFFT results (from using wrapped or unwrapped > >atan2) are the same as the non-complex IFFT results (from using wrapped > or > >unwrapped atan). > > >It seems like they all are essentially producing the same results. &#4294967295; > > >I hope this is clear. &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; > > Please note in my code above: > > % Unwrapped Phase of each waveform > for i = 1:length(C) > CUphase(i) = unwrap(atan(imag(C(i))/real(C(i)))); > DUphase(i) = unwrap(atan(imag(D(i))/real(D(i)))); > end > > DUphase(i) = ... had real(C(i)) as the denom in the atan function. &#4294967295;The > noted change didn't help. &#4294967295; &#4294967295;- Hide quoted text - > > - Show quoted text -
If MATLAB is true to its description of atan then it is a 2-quadrant atan and unwrap() should never change anything. Definitely want to use atan2. Next, such a simple phase unwrapping technique requires some reasonable oversampling of the wrapped phase signal. Then remenber you can have both 2*PI and PI discontinuities. You should probably write your own 'unwrap'. SplatSpam
On Apr 14, 1:54 pm, "norwood_dave" <norwood_d...@yahoo.com> wrote:
> I have only taken one undergraduate DSP course and have started reading > about unwrapping phase. > > I was told if I had two signals in the time domain, the first signal > consisting of one period of 100Hz (100 points) followed by 100 zeros and > the second signal consisting of 100 zeros followed by one period of 100Hz > (100 points), I could take the FFT of each signal and average them in the > frequency domain. I could then take the IFFT of this average and obtain a > signal consisting of 50 zeros followed by one period of 100Hz (100 points) > followed by 50 zeros.
Take a rolled newpaper and whack that person upside da head.
> If effect, the FFT average will average the time > delay. HOWEVER, I must unwrap the phase when doing this. > > From my understanding about unwrap, I don't see a difference between phase > unwrapping versus taking the ATAN2(imag,real).
Phase unwrapping yields a monotonic phase that is not bounded to a 2*pi interval. Besides, if you are using MATLAB, use ANGLE instead of ATAN2 doc angle help angle
> I tried numerous things in > matlab using my example signals above and have come up with nothing. Is > this even possible? Or, more likely I'm misunderstanding something. Any > insight is greatly appreciated.
The original conjecture is false. Hope this helps. Greg
On Apr 14, 10:53&#4294967295;pm, splatspaminthe...@gmail.com wrote:
> On Apr 14, 9:20&#4294967295;pm, "norwood_dave" <norwood_d...@yahoo.com> wrote: > > >>norwood_dave wrote:
-----SNIP
> If MATLAB is true to its description of atan then it is a 2-quadrant > atan and unwrap() should never change anything.
Not true.
> Definitely want to use atan2.
ANGLE is prefereable.
> Next, such a simple phase unwrapping technique requires some > reasonable oversampling of the wrapped phase signal.
This can be acomplished by zeropadding the original time signal.
> Then remenber you can have both 2*PI and PI discontinuities.
? With ANGLE or ATAN2 you only get 2*pi discontinuities.
> &#4294967295;You should probably write your own 'unwrap'.
Very, very difficult. Hope this helps. Greg
On Apr 15, 1:36&#4294967295;pm, Greg Heath <he...@alumni.brown.edu> wrote:
> On Apr 14, 1:54 pm, "norwood_dave" <norwood_d...@yahoo.com> wrote: > > > I have only taken one undergraduate DSP course and have started reading > > about unwrapping phase. > > > I was told if I had two signals in the time domain, the first signal > > consisting of one period of 100Hz (100 points) followed by 100 zeros and > > the second signal consisting of 100 zeros followed by one period of 100Hz > > (100 points), I could take the FFT of each signal and average them in the > > frequency domain. &#4294967295;I could then take the IFFT of this average and obtain a > > signal consisting of 50 zeros followed by one period of 100Hz (100 points) > > followed by 50 zeros. > > Take a rolled newpaper and whack that person upside da head. > > > If effect, the FFT average will average the time > > delay. &#4294967295;HOWEVER, I must unwrap the phase when doing this. > > > From my understanding about unwrap, I don't see a difference between phase > > unwrapping versus taking the ATAN2(imag,real). > > Phase unwrapping yields a monotonic phase that is not > bounded to a 2*pi interval. > > Besides, if you are using MATLAB, use ANGLE instead of ATAN2 > > doc angle > help angle > > > I tried numerous things in > > matlab using my example signals above and have come up with nothing. &#4294967295;Is > > this even possible? &#4294967295;Or, more likely I'm misunderstanding something. &#4294967295;Any > > insight is greatly appreciated. > > The original conjecture is false. > > Hope this helps. > > Greg
I do not recall any requirement that the uwrapped phase be monotonic. Or even continuous. splatspam
On Apr 14, 9:04 pm, "norwood_dave" <norwood_d...@yahoo.com> wrote:
> >norwood_dave wrote:
-----SNIP
> Thank you for the reply. I did try this with no luck. Here is my > original code (for anyone to look over): > > %Generate one period of 100Hz
f0 = 100 N = 100 T = 1/f0 % e-2 dt = T/N % e-4 t = 0:dt:T-dt; % dt*(0:N-1);
> a = sin(2*pi*100*t);
> %One Period of 100Hz + 100 zeros
c = [ a, zeros(1, N)];
> %100 zeros + One Period of 100Hz
d = [zeros(1,N), a];
> % FFTs > C = fft(c); > D = fft(d); > > % Magnitudes > Cmag = abs(C); > Dmag = abs(D);
% Wrapped and Unwrapped phases Cphase = angle(C); Dphase = angle(D); CUphase = unwrap(Cphase); DUphase = unwrap(Dphase); checkmag = max(abs(Cmag-Dmag)) % should be 0 checkuphase = minmax(CUphase-DUphase) % should be constant figure(1) subplot(2,3,1) plot(Cmag,'b',Dmag,'r') subplot(2,3,2) plot(Cphase,'b',Dphase,'r') subplot(2,3,3) plot(CUphase,'b',DUphase,'r')
> % Average Phase
AvgUphase = (CUphase+DUphase)/2; E = Cmag*exp(i*AvgUphase); result = ifft(E); figure(2), hold on plot(c,'b') plot(d,'r') plot(result,'g') WARNING: Code is not debugged and has never been run. Hope this helps. Greg
On Apr 15, 1:59 pm, splatspaminthe...@gmail.com wrote:
> On Apr 15, 1:36 pm,Greg Heath<he...@alumni.brown.edu> wrote: > > On Apr 14, 1:54 pm, "norwood_dave" <norwood_d...@yahoo.com> wrote: > > > > I have only taken one undergraduate DSP course and have started reading > > > about unwrapping phase. > > > > I was told if I had two signals in the time domain, the first signal > > > consisting of one period of 100Hz (100 points) followed by 100 zeros and > > > the second signal consisting of 100 zeros followed by one period of 100Hz > > > (100 points), I could take the FFT of each signal and average them in the > > > frequency domain. I could then take the IFFT of this average and obtain a > > > signal consisting of 50 zeros followed by one period of 100Hz (100 points) > > > followed by 50 zeros. > > > Take a rolled newpaper and whack that person upside da head.
That's a little too strong: You don't average the ffts, you average the phases.
> > > If effect, the FFT average will average the time > > > delay. HOWEVER, I must unwrap the phase when doing this.
I don't see why you have to. Averaging the wrapped phase should work. Please try it with the code I posted previously.
> > > From my understanding about unwrap, I don't see a difference between phase > > > unwrapping versus taking the ATAN2(imag,real). > > > Phase unwrapping yields a monotonic phase that is not > > bounded to a 2*pi interval.
-----SNIP
> I do not recall any requirement that the uwrapped phase be monotonic. > Or even continuous.
Correct. It depends on the scenario. Unwrapped phase caused by a continuous physical event (e.g., reflections from a convex shaped radar target) will be continuous. However, it need not be monotonic. For example, the unwrapped phase of a radar reflection from a large moving metallic sphere is ~ 4*pi*R(t)/c where R(t) is the range to the target and c is the speed of light and electromagnetic disturbances in vacuum. Therefore, R and unwrapped phase decrease as the sphere approaches, reach a minimum, then increase as the sphere recedes. A good exercise is to try to unwrap the fft phase corresponding to the time signal x0 = cos( a0 + b0*(t-t0)^2 ) with a0, b0 and t0 unknown. Success will depend on the size of the time sampling frequency Fs with respect to b0. Now if the sphere is spinning fast and the surface has a deep cylindrical hole that periodically faces the radar, the range to the reflection point will APPEAR to be discontinuous causing the unwrapped phase to APPEAR to be discontinuous; e.g., x1 = cos( a0 + b0*(t-t0)^2 +c0*square(2*pi*f0*(t-t1),duty)). Hope this helps. Greg