This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

FFT of phase shifted sinusoidal signal

Other Parts Discussed in Thread: TMS320F2808

Hi,

I am doing fft on TMS320F2808. I observed that for sinusoidal (sinewave) without phase shift, I am getting correct fft result, but with phase shfit in same signal I am getting incorrect result (i.e. fft output strength/amlitude  doesn't match with the signal without phase shift). Please help me to understand why this phase shift should cause ussue.

Thanks,

panshi

  • The output of the real fft is complex with real and imaginary parts representing the scaled amplitude of the cosine and sine waves repectively.

    If you shift the phase, the cosine and sine components will change.

    You probably want to convert the output to polar (magnitude and phase) form.The scaled magnitudes should be the same regardless of the phase shift.

    You may want to confirm your understanding of the FFT and what you're doing with it by first using standard known working fft libraries  in an easier to use environment before trying to debug it on a DSP. It's usually well worth it to have a working floating point model of your signal processing that you can validate before you port over to a fixed point (or even floating point) DSP.

     

     

     

  • Thanks for the reply.

    "You probably want to convert the output to polar (magnitude and phase) form.The scaled magnitudes should be the same regardless of the phase shift."

    I am getting problem with scaled magnitudes.

    I have 64 sample. i.e N = 64.

    Description.

    1) Sample of sine wave without phase shift,

    {409 , 440 , 456 , 472 , 503 , 519 , 546 , 560 , 585 , 596 , 616 , 625 , 633 , 645 , 650 , 656 , 659 , 659 , 657 , 650 , 645 , 639 , 627 , 610 , 600 , 576 , 564 , 536 , 522 , 507 , 475 , 459 , 427 , 411 , 379 , 364 , 333 , 318 , 303 , 276 , 264 , 241 , 230 , 212 , 205 , 193 , 189 , 185 , 181 , 181 , 184 , 188 , 197 , 203 , 219 , 228 , 249 , 260 , 273 , 300 , 315 , 345 , 360 , 392} 

    After doing fft my output array contains,

    {417,0, -5, -116,1 ,4,2,5,2,2,1,3,1,2,2,2,2,2,-1,4,-1,4,1,2,1,2,1,1,3,1,2,2,0,-1,-1,1,0,2,-2,2,-2,1,-2,2,0,4,0,3,-1,2,-1,1,-2,1,-2,4,-2,1,2,6,-3,4,-1,3,}

    Here, real part is -5 and imaginary part is -116., if i calculate magintude it comes to, (sqrt (sqr(5) + sqr(116)) =  116.7

    2) Samples of 90 degree phase shifted sinewave are as below,

    {659 , 659 , 657 , 650 , 645 , 639 , 627 , 610 , 600 , 576 , 564 , 536 , 522 , 507 , 475 , 459 , 427 , 411 , 379 , 364 , 333 , 318 , 303 , 276 , 264 , 241 , 230 , 212 , 205 , 193 , 189 , 185 , 181 , 181 , 184 , 188 , 197 , 203 , 219 , 228 , 249 , 260 , 273 , 300 , 315 , 345 , 360 , 392, 409 , 440 , 456 , 472 , 503 , 519 , 546 , 560 , 585 , 596 , 616 , 625 , 633 , 645 , 650 , 656 } 

    After doing fft on this data my output array contains,

    {417,0,119,-1,2,2,2,2,2,2,1,2,1,2,0,2,2,2,-1,2,0,4,1,1,1,2,-1,4,-1,4,2,1,0,-1,-2,3,0,4,0,4,-2,1,1,-2,1,4,0,5,-1,2,1,5,-2,2,-2,1,-2,1,-2,2,-1,1,-1,5}

    Here my magnitude comes to 119.

    What could be the reason for this difference 116.7 and 119?  Is it due to the fixed point dsp?

  • It is not so much that it is a fixed point dsp but rather that you are using small integers (unsigned at that) where the library is most likely expecting signed fractions .If you loose track of where the decimal point is, you can end up loosing significant portions to rounding errors.

    The FFT does many multiplies involving the sin and cos values in the range of -1.0 to 1.0. Generally, you'll preserve the best precision for these calculations if your data is scaled to the same range.

    You haven't mentioned how you are calculating the fft. I'll assume you are using the TI  FFT32 libraries. I believe these libraries assume that the input data is scaled to Q15 format. So you are passing a signal that is extremely small for the fixed point arithmetic and you are likely  loosing too much to roundoff errors which are accumulating in the calculations of the fft routine. For example, the decimal integer 659 in Q15 format is 0.020111083. If you want to represent the number 659.0 in Q15 format, the equivalent decimal integer value would be 43188224.