FFT Phase Spectra Question

Greetings,

I have a couple of what may be relatively naive questions.

I have data from which I would like to extract the phase however when performing an FFT, the x-values of the resultant phase spectrum do not include the frequency of the sine wave. If I effectively average the two data points around the frequency, I obtain the correct phase. I haven't had this problem with my magnitude spectra and I am not certain if this is typical. The following is an example:
Make/O/N=10000 w0 SetScale/I x 0,10,"s", w0 w0 = sin(4*pi*x+pi/2) FFT/OUT=5/DEST=w0_FFT/RP=[0,4749] w0;DelayUpdate display w0 display w0_FFT

In the above example, the resultant phase spectrum has data points with x-values of 1.8945 and 2.1051 (on either side of the sine wave frequency of 2 Hz). When I average the phases at these two x-values (-1.5733 and 1.5673, respectively), I obtain the expected phase of zero for this sine wave. Is it typical to need to find a midpoint to obtain my phase?

My second question is whether I can unwrap the phase spectrum I've generated. I haven't had luck using the command "Unwrap 2*pi, w0_FFT", which I've used successfully with the Hilbert Transform.

Thank you in advance for your help!

There are a few issues one can comment on regarding your setup. The first is that your are using /RP yet your range does not describe full cycles. I suggest you start by changing the FFT command to:
 FFT/DEST=w0_FFT/rp=[0,4749] w0


Now plot the real and imaginary parts of w0_fft

Next, replace your /RP range so that it covers full cycles, e.g.,

FFT/DEST=w0_FFT/rp=[0,4999] w0

and observe the differences in the calculated phase. In general, when you encounter edge effects you should think of window functions so see /WINF flag of FFT.

I'm not clear about the pi/2 phase. Why not use a cosine instead?

Finally, if you are going to look for accuracy, especially when adding pi/2, it might help to use a DP wave so change your Make to Make/D.

A.G.
WaveMetrics, Inc.
Igor wrote:
There are a few issues one can comment on regarding your setup. The first is that your are using /RP yet your range does not describe full cycles. I suggest you start by changing the FFT command to:
 FFT/DEST=w0_FFT/rp=[0,4749] w0


Now plot the real and imaginary parts of w0_fft

Next, replace your /RP range so that it covers full cycles, e.g.,

FFT/DEST=w0_FFT/rp=[0,4999] w0

and observe the differences in the calculated phase. In general, when you encounter edge effects you should think of window functions so see /WINF flag of FFT.

I'm not clear about the pi/2 phase. Why not use a cosine instead?

Finally, if you are going to look for accuracy, especially when adding pi/2, it might help to use a DP wave so change your Make to Make/D.

A.G.
WaveMetrics, Inc.



Thank you so much for your reply. You were indeed correct that the FFT range was causing my problem with the phase spectrum matching the sine wave frequency. When I corrected that, I was able to obtain the correct phase at the corresponding frequency. As for why I used a sine wave or added pi/2, I was just trying a few sample calculations to ensure I could determine the appropriate phase using the FFT (so not something I'll be using later).

Is there a benefit to calculating the phase manually, rather than using the FFT phase spectrum output (/OUT=5)?

With respect to the second question about unwrapping the result, do you know how this could be best achieved? I'm interested in the phase shift between a stimulus wave and a response wave and the 'lagging' response wave may fall sufficiently behind to cause the wrapping to underestimate the shift.

Thank you once again and hope to hear from you soon.
notsoslick wrote:

Is there a benefit to calculating the phase manually, rather than using the FFT phase spectrum output (/OUT=5)?


I calculated the complex FFT so I can look at both real and imaginary components. In this application I prefer to look at complex numbers this way. The phase (being mod 2*pi) is less helpful.

Quote:
With respect to the second question about unwrapping the result, do you know how this could be best achieved? I'm interested in the phase shift between a stimulus wave and a response wave and the 'lagging' response wave may fall sufficiently behind to cause the wrapping to underestimate the shift.


I am not following the details of your application. In your example I only saw FFT of one wave so I do not immediately see how that relates to computing a response time from two separate waves. There are infinitely many ways you can have a "response" to a "stimulus" and in each case you would have to write different code to extract the time difference. Since I do not know anything about the shapes of your stimulus wave or response wave I can't really comment any further.

I think it would be best if you would post a new thread that focuses on that issue. Describing your two waves (or even plotting an example) might also be good.

A.G.
WaveMetrics, Inc.