3
$\begingroup$

Long story short, I have a sinusoidal wave with DC offset going in with a given frequency of say 100 Hz and $\phi = 0$ (which I'm guessing is really $\pi/2$ since it is a sine wave not cosine). I get an output of the same frequency and, using FFT, I would like to find the phase between these two. What I did is I found the peak frequencies (-100 and 100 Hz), found their bin and from the same bin I extracted the amplitude and the phase.

Is that correct?

$\endgroup$

3 Answers 3

3
$\begingroup$

The phase is relative to the start of the sample window, and unless the frequency component corresponds exactly with the center frequency of the relevant FFT bin then you also need to apply a correction.

$\endgroup$
7
  • 1
    $\begingroup$ That's a very good point. Any chance that you could add an explanation and/or example? $\endgroup$
    – Jim Clay
    Apr 15, 2013 at 17:29
  • $\begingroup$ Sure - I'll try and find some time to add more detail later today. $\endgroup$
    – Paul R
    Apr 15, 2013 at 18:03
  • 1
    $\begingroup$ The phase is relative to BOTH the start and end of the FFT window. Thus the problem for non-periodic signals unless one applies an fftshift. $\endgroup$
    – hotpaw2
    Apr 15, 2013 at 22:48
  • $\begingroup$ @jimclay : See my answer for a method to get a more correct phase (to a different reference point). $\endgroup$
    – hotpaw2
    Apr 15, 2013 at 22:49
  • $\begingroup$ Yes, the more I think about it the more it seems that using an FFT to extract phase information is the wrong approach - it can only really work if you know the exact frequency of the component of interest, which makes it useless for most practical applications. $\endgroup$
    – Paul R
    Apr 16, 2013 at 6:46
3
$\begingroup$

If you're interested in the time delay between the two signals, it's probably most useful to compute the cross-correlation function of the two signals and find its maximum. The location of the maximum will give you the time lag.

$\endgroup$
2
$\begingroup$

You method will work for frequencies that are exactly periodic in the FFT width. For frequencies that are in between bins, I would first do an fftshift (of both FFTs) to position the 0 phase reference at the window center before interpolating phase and doing the phase subtraction. Otherwise the FFT will flip the phase between alternating FFT result bins making phase interpolation far more non-intuitive. However the evenness/oddness ratio of a sinusoid about the window center does not flip even for FFT result bins of non-periodic-in-aperture sinusoids, allowing a more intuitive phase comparison (after the fftshifts).

$\endgroup$
1
  • 1
    $\begingroup$ Would you please provide any example with code to show how this can be done in R or matlab? Many thanks. $\endgroup$
    – Anusha
    Sep 13, 2014 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.