问题描述
我正在研究简单信号,我想计算信号的傅立叶变换,获取幅度和相位,然后从中重建原始信号.
Hi guy's I'm working on simple signals and I want to calculate the Fourier transform of a signal, get the magnitude and phases, then reconstruct the original signal from that.
我将代码基于此线程
代码:
>> n=0:99;
>> N=length(n);
>> x = sin((2*pi/N).*n).*cos((pi/N).*n);
>> F = fft(x);
>> mag = sqrt(real(F).^2 + imag(F).^2);
>> phase = atan2(imag(F),real(F));
>> re = mag .* cos(phase);
>> im = mag .* sin(phase);
>> F_i = re + 1i*im;
>> x_i = ifft(F_i);
>> figure;stem(x);figure;stem(x_i);
我完全得到了不同的图.
I completely get different graphs.
我实际上是在做此操作,以测试如果相位发生变化将对信号产生什么影响.因此,我将需要相位角来再次构建信号.
I'm actually doing this to test what would happen to a signal if the phase changes. So with this I will need the phase angle to construct the signal again.
我对Fourier + Matlab还是陌生的,所以如果我犯了一些随机的愚蠢错误,我深表歉意.如果你们能为我指出正确的方向,我将不胜感激.谢谢.
I'm still new to both Fourier + Matlab so I apologize if I'm making some random stupid mistake. I'll appreciate it if you guys can point me in the right direction. Thank you.
推荐答案
问题是由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.
这篇关于傅立叶变换:获取mag +相位,然后使用其绘制原始信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!