0
$\begingroup$

I'm trying to wrap my mind about what happens in Matlab/Octave when you compute the fft of a sine function. Theoretically, the Fourier Transform of a sine is given by two delta functions multiplied by the imaginary unit (one placed at the frequency of the sine and another at minus the frequency). I can see that in the modulus of the FFT (not exactly a delta because of the frequency leakage due to the windowing), but when I check the phase I get a signal that is non-zero over all the support (from 0 to the sampling frequency). I'm playing with this toy example in Octave:

fs = 200,t=-10:(1/fs):10;
x = sin(2*pi*30*t);
f = linspace(0,1,length(x))*fs;
fourierTrans = fft(x);
figure,plot(f,abs(fourierTrans))
figure,plot(f,angle(fourierTrans))

And the picture I get for the phase is: enter image description here

Why is it that I don't see two deltas in the picture for phase of amplitude pi/2 and -pi/2?

Cheers

$\endgroup$
  • $\begingroup$ Remember that even with a "perfect" FFT where the signal only occupies 1 bin, the bins that are not signal will have computation noise in them; they will never be exactly 0. So the phase everywhere will be nonzero, even though it's meaningless. $\endgroup$ – endolith Sep 12 '13 at 20:08
1
$\begingroup$

The phase of a sinewave that is not exactly periodic relative to the FFT aperture length is discontinuous at the edges. If you want a sane/visualizable phase (not the phase of a discontinuity) for non-periodic frequencies, try generating your sinewave with a known phase at the center of the FFT (sin(2*pi*foo*(t-N/2))), and use an fftshift to re-reference the reported phase result of the FFT to the center of the FFT aperture as well. Then the oddness/evenness ratio of your test function, and thus the phase result will remain stable as frequency is swept between FFT bin center frequencies.

The phase of a non-periodic-in-aperture sinewave will contain the phase of the convolution of the signal with the transform of the FFT window (something like a Sinc, which ends up spanning the full width of the FFT), which will also have a phase related to that of the signal. Even a computed FFT of an exactly periodic sinewave will also produce some values that aren't exactly zero in all the other bins due to quantization noise in the computer arithmetic; thus those essentially zero, but not quite zero, magnitudes will have a phase that may or may not be zero. And the phase of an actual zero magnitude vector is indeterminate, not necessarily zero.

$\endgroup$
  • $\begingroup$ I think what he means is why all the phases except that of the sine are all non-zero. He is expecting to see the phase be all zeros, except for the positive and negative frequency of the sine wave. $\endgroup$ – TheGrapeBeyond Sep 6 '13 at 16:49
1
$\begingroup$

For an ideal sine wave the magnitude of the spectrum is zero at all frequencies except the on of the sine wave itself. Since the magnitude at the other frequencies is 0, the phase is undefined (not zero) and could be anything. In practice it will be determined by noise in the signal or the numerical computation.

The effect that you are seeing is related to the fact that your frequency sampling grid (determined by sample rate and FFT length) doesn't line up exactly with the actual sine wave frequency so you have some frequency smearing. Hence the magnitude at the FFT frequencies are not 0 and hence you get a phase. This phase is really just a function of how well (or not) your sine wave lines up with the frequency sampling grid.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.