简体   繁体   中英

Finding the phase from FFT on MATLAB

I know the fundamental frequency of my signal and therefore I also know the other frequencies for the harmonics, I have used the FFT command to compute the first 5 harmonics (for which I know their frequencies). Is it possible for me to find the phase with this available information?

Please note I cant be sure my signal is only one period and therefore need to calculate the phase via the known frequency values.


Code seems to be working:

 L = length(te(1,:));               % Length of signal
 x = te(1,:); 
 NFFT = 2^nextpow2(L);              % Next power of 2 from length of y
 Y = fft(x,NFFT)/L;
 f = linspace(1,5,5);   
 Y(1) = [];                          % First Value is a sum of all harmonics
 figure(1);
 bar(f,2*abs(Y(1:5)), 'red') 
 title('Transmission Error Harmonics')
 xlabel('Harmonic')
 ylabel('|Y(f)|')
 figure(2);
 bar(f,(angle(Y(1:5))))
 title('Transmission Error Phase')
 xlabel('Harminic')
 ylabel('Angle (radians)')

In general your Fourier transformed is complex. So if you want to know the phase of a certain frequency you calculate it with tan(ImaginaryPart(Sample)/RealPart(Sample)). This can be done by using angle(). In your case you

1- calculate fft()

2- calculate angle() for all samples of the FFT or for the samples you are interested in (ie the sample at your fundamental frequency/harmonic)

EDIT: an example would be

t = [0 0 0 1 0 0 0];
f = fft(t);
phase = angle(f);
phase = angle(f(3)); % If you are interested in the phase of only one frequency

EDIT2: You should not mix up a real valued spectrum [which is basically abs(fft())] with a complex fourier transformed [which is only fft()]. But as you wrote that you calculated the fft yourself I guess you have the 'original' FFT with the complex numbers.

Note that if your fundamental frequency is not exactly periodic in the fft length, then the resulting phase (atan2(xi,xr)) will be flipping signs between adjacent bins due to the discontinuity between the fft ends (or due to the rectangular window convolution), making phase interpolation interesting. So you may want to re-reference the phase estimation to the center of the fft by doing an fftshift (pre, by shift/rotating elements, or post, by flipping signs in the fft result), making phase interpolation look more reasonable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM