Search code examples
matlabfftphase

Matlab fft on one period of sinewave returns phase of -pi/2. Why?


While trying to understand Fast Fourier Transform I encountered a problem with the phase. I have broken it down to the simple code below. Calculating one period of a 50Hz sinewave, and applying an fft algorithm:

    fs = 1600;
    dt = 1/fs;
    L  = 32;      
    t=(0:L-1)*dt; 
    signal  = sin(t/0.02*2*pi); 

    Y = fft(signal);
    myAmplitude = abs(Y)/L *2 ;
    myAngle     = angle(Y);

    Amplitude_at_50Hz = myAmplitude(2);
    Phase_at_50Hz     = myAngle(2);

While the amplitude is ok, I don't understand the phase result. Why do I get -pi/2 ? As there is only one pure sinewave, I expected the phase to be 0. Either my math is wrong, or my use of Matlab, or both of them... (A homemade fft gives me the same result. So I guess I am stumbling over my math.)

There is a similar post here: MATLAB FFT Phase plot. However, the suggested 'unwrap' command doesn't solve my problem.

Thanks and best regards,

DanK


Solution

  • The default waveform for an FFT phase angle of zero is a cosine wave which starts and ends in the FFT window at 1.0 (not a sinewave which starts and ends in the FFT window at 0.0, or at its zero crossings.) This is because the common nomenclature is to call the cosine function components of the FFT basis vectors (the complex exponentials) the "real" components. The sine function basis components are called "imaginary", and thus infer a non-zero complex phase.