# Unexpected phase displacement in FFT of a pure sinewave.

1 visualizzazione (ultimi 30 giorni)
Alberto Carboni il 4 Apr 2015
Commentato: Hugo il 4 Apr 2015
Hi all,
I am working on an algorithm and I'm facing this issue, I want to do a dft of a signal, in order to get a phasor representation of it.
I've tried with a simple case to start with, I send it as an input to my Hanning window, then I process the windowed sequence, what I'm expected to get if my signal is
x(t)= 220e3*cos(2*pi*f*t)
it's a phasor module= 220e3 phase=0 but I get module= 219994,133313801 phase= 7,85398163449812.
Both are a big issue, since no leakege or aliasing is present, any suggestion?
thanks
Alberto
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Hugo il 4 Apr 2015
Hi Alberto,
I think your problem is due to your choice of t. Suppose that your frequency is 50Hz. If you choose
t=0:.001:1,
and use
xf=fft(x(t)),
then you will get
xf(51)=199279 < 8.99
The number before "<" is the amplitude and the one after is the phase in degrees.
Notice that in this case, the window is of length 1.001 seconds. Should the signal be made periodic by repeating the windows, the samples at the end of the first window and at the beginning of the second window would be repeated.
To avoid this, I can use instead
t=0:.001:.999
Then, I obtain
xf(51)=220000 < 0
As I expected. The difference is that now the window has exactly 1 second of duration and should the signal be made periodic by repeating windows, the last sample of the first window will be not the same as the first sample of the second window, but the one immediately before.
Notice that you could have employed
t=.001:.001:1,
and then you would have also employed a window of exactly one second, but you would have introduced a delay of 0.001.
In all these calculations I employed no Hamming window. Doing so changes the value of the amplitude, but not the phase when using t=0:.001:.999, that is, a window of exactly one second. I am not sure how you correct for the distortion you get after windowing.
In general, I think the problem is that a distortion is to be expected whenever the size of the window you employ is inconsistent with the periodicity of your signal. Should you have a mixture of pure sine waves, you will need to find that window that is a multiple of all the periodicities of your mixture, and be careful about the limits of the window when you discreticize it.
I hope this helps.
##### 2 CommentiMostra NessunoNascondi Nessuno
Alberto Carboni il 4 Apr 2015
Modificato: Alberto Carboni il 4 Apr 2015
Ok thank you very much indeed, now everything sounds way better!
If I apply a rectangular window evertything is ok as expected, but if I apply a cosine window I can still have some uncertainties on the phase i.e. I get this result
frequency 50
amplitude 220000
phase 2,20937760208141e-16
I think this phase is due to some numerical uncertainties, is there any tool to limit/trigger it in an optimal way?
thanks a lot
alberto
Hugo il 4 Apr 2015
Hi,
Yes, it seems to me the result of round off errors. I've actually got errors of 1E-14, 100 times larger in my calculations. It is certainly an artefact, and it hopefully does not propagate chaotically through your calculations (chaos meaning that small discrepancies in initial values do not yield divergent results). I'm afraid I am not an expert in correcting round off errors, I've only employed strategies I've found in wikipedia for correcting errors in sums. Perhaps the most efficient solution would be to assume some size of round off errors, check how those errors propagate along the calculations, and then establish a threshold up to which you trust in the numbers your calculations yield. I apologise I cannot be of much more help with that.

Accedi per commentare.

### Categorie

Scopri di più su Spectral Measurements in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by