简体   繁体   English

在MATLAB上通过FFT查找相位

[英]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). 我知道我的信号的基本频率,因此我也知道谐波的其他频率,我使用FFT命令来计算前5个谐波(我知道它们的频率)。 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)). 因此,如果您想知道某个频率的相位,可以使用tan(ImaginaryPart(Sample)/ RealPart(Sample))进行计算。 This can be done by using angle(). 这可以通过使用angle()完成。 In your case you 就你而言

1- calculate fft() 1-计算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) 2-为FFT的所有样本或您感兴趣的样本(即基频/谐波的样本)计算angle()

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()]. EDIT2:您不应该将实值频谱[基本上是abs(fft())]与复杂的傅立叶变换[只是fft()]混合起来。 But as you wrote that you calculated the fft yourself I guess you have the 'original' FFT with the complex numbers. 但是,正如您所写的那样,您自己计算了fft,我想您具有复数的“原始” FFT。

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. 请注意,如果您的基本频率在fft长度上不是完全周期性的,则由于fft两端之间的不连续性(或由于矩形窗卷积),结果相位(atan2(xi,xr))将在相邻仓之间翻转符号),使相位插值变得有趣。 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. 因此,您可能希望通过执行fftshift(通过fft结果中的前/后/移位/旋转元素或后置,通过翻转符号)来将相位估计重新引用到fft的中心,从而使相位插值看起来更加合理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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