更新时间:2022-06-03 06:01:58
问题是由phase
中的舍入误差引起的,因此在计算相位角的正弦和余弦时不要使用它们.而是使用触发身份cos(atan(A))=(1+A^2)^(-1/2)
和sin(atan(A))=A*(1+A^2)^(-1/2)
,依此类推
The problem is caused by round-off errors in phase
, so don't use them when calulating the sine and consine of the phase angles. Instead, use trig identities cos(atan(A))=(1+A^2)^(-1/2)
, and sin(atan(A))=A*(1+A^2)^(-1/2)
, and so
re = mag .* real(F)./sqrt(real(F).^2+imag(F).^2);
im = mag .* imag(F)./sqrt(real(F).^2+imag(F).^2);
我想,如果您想通过S
更改相位角,这将达到目的:
I think that if you want to change the phase angle by S
, this will do the trick:
re = mag .* (real(F)*cos(S)-imag(F)*sin(S))./sqrt(real(F).^2+imag(F).^2);
im = mag .* (real(F)*sin(S)+imag(F)*cos(S))./sqrt(real(F).^2+imag(F).^2);
您有时仍然会得到虚部不为零的不良结果(例如,如果S=pi
),并且您将需要按照路易斯建议的方式绘制stem(real(x_i))
或stem(1:length(x_i),x_i)
.
You will still sometimes get bad results with non-zero imaginary part (e.g. if S=pi
), and you will need to plot either stem(real(x_i))
or stem(1:length(x_i),x_i)
as Luis suggested.