# phase angle of harmonic

I have generated sinsuoids containing fundamental with harmonics using C++. Fundamental frequency is 50 Hz and each of the harmonic has phase offset of 60 degrees. I have applied flattop window before performing and N point FFT. Magnitude repose is correct. Phase reponse is wrong. I should expect 60 degree in all 100,150,200,250 Hz. I have attached the results.

Sampling rate : 40000 Timeduration : 1s Maximim amplitude of each of the harmonic : 1

Any help would be highly appreciated.

Regards, Faisal

## 2 Answers

Your window is centered around the middle of the time window. This corresponds (roughly speaking) to a delay of half the window size and corresponding additional phase of $e^{-j \cdot \omega \cdot t}$

The "wiggles" that you see is a steep linear phase that wraps around 2*pi occasionally. There a few ways to fix this.

1. circularly shift the time domain signal so that the max of the window is at 0. This will be better but still isn't great since the windowing will significantly impact the phase.
2. Make sure that the fundamental fits into your time window and integer amount of times. Then do an FFT without windowing. This should give you an exact result.

If you reference phase to the beginning of your FFT aperture, then any sinusoid that is not exactly integer periodic within that window width will be discontinuous across the two window edges, thus providing a phase (phase of a discontinuity?) that doesn't really make much intuitive sense at that measurement point, as well as alternating in phase between successive FFT result bins. Also, most common "hump" shaped windows reduce the signal to nothing, or nearly so, at the window edges, which again doesn't make much sense, as the measurement of the phase of almost nothing at the reference point can be quite noisy.

To prevent this seeming nonsense, do an FFTshift, which moves the phase reference to the center of your signal window. You can so this by rotating the data (and window) so that the peak of the window hump is at the FFT's phase measurement point (time index 0), and the discontinuity and/or window-edge-attenuation is far from the phase reference measurement point. This FFTshift or data rotation will also prevent the phase of a non-integer-periodic sinusoid from alternating between FFT result bins, thus allowing simpler phase interpolation between FFT result bins.