fft matlab 时间到频率和返回

fft matlab time to freq and back

我正在尝试一个简单的(快速傅立叶变换)fft 并将其转换回来,但它不起作用。 我需要从这个开始,以便继续为每个组件添加阶段。能否请您看一下,看看我哪里出了问题?

fun_cos=@(t) cos(1.5e12*t)
nttf=2^17;
t=linspace(-3*t_signal_pulse/2,3*t_signal_pulse/2,nttf);
dni_ni=(1/(t(2)-t(1)));
ni=-dni_ni/2:dni_ni/(nttf):dni_ni/2-dni_ni/(nttf);
w=ni.*2*pi;
figure(1)
plot(t,fun_cos(t))
FFt_cos=fftshift(fft(fun_cos(t),nttf))/length(t);
figure(2);
plot(w,abs(FFt_cos))
fft_back=ifft(ifftshift(FFt_cos));
figure(1)
hold on
plot(t,abs(fft_back),'.r')

Freq domain. you can see here two freq even though I only need one

Final result. The blue is the original cosine and the red is the one that I would expected to be the same

此外,如果我想分别向时域和频域添加相位(请注意,我只知道频域相位的一侧,而不是两者,所以不知道如何进行还)

您忘记使用 'length(t)' 重新缩放:

fft_back=ifft(ifftshift(FFt_cos*length(t)));

MaxError=max(abs(fun_cos(t)-fft_back)) %reconstruction error