简体   繁体   English

在MATLAB中计算相角

[英]Computing phase angle in fft matlab

I am trying to compute the phase angle in the frequency domain (after computing fft) of the second component of the Fourier spectrum of a synthetic signal constructed by me in the workspace of Matlab. 我正在尝试在Matlab的工作空间中计算由我构造的合成信号的傅立叶频谱的第二个分量的频域中的相角(在计算fft之后)。 I am sure that the phase is equal to 0 (as you can see in the code), but the result I get is pi/2. 我确定相位等于0(如代码中所示),但是我得到的结果是pi / 2。 The code is the following: 代码如下:

t = 0:pi / 128:(2 * pi - pi / 128);
V = sin(t);
L = length(V);
n = 2^nextpow2(L);
Y = fft(V, n);
threshold = max(abs(Y))/10000;
Y(abs(Y)<threshold) = 0;
mag = abs(Y/n);
angle = rad2deg(atan2(imag(Y),real(Y)));

I do not see where the error is. 我看不到错误在哪里。

You are mistaken that the phase of a real, periodic sine wave with a frequency that corresponds to the bin center frequency (and no phase offset) is zero. 您会误以为,真实的,周期性的正弦波的频率与箱中心频率相对应(且没有相位偏移),其相位为零。 The basis functions representing the real part of the original sequence are cosine functions. 表示原始序列部的基础函数是余弦函数。

To represent a sine wave with a cosine wave a phase offset of pi/2 has to be subtracted: 为了用余弦波表示正弦波,必须减去pi / 2的相位偏移:

sin(x) = cos(x - pi/2). sin(x)= cos(x-pi / 2)。

Therefore, the phase in bin 2 (corresponding to the frequency of the original sequence), is -pi/2. 因此,bin 2中的相位(对应于原始序列的频率)为-pi / 2。

(For a more thorough explanation see this question on DSP.SE .) (有关更详尽的说明,请参阅DSP.SE上的此问题 。)

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

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