2017-07-28 171 views
0

我想要一個簡單的(快速傅立葉變換)FFT並將其轉換回,但它不工作。 我需要從這開始才能繼續爲每個組件添加階段。你可以看一下,看看我哪裏出了問題嗎?FFT MATLAB時間頻率和背部

[email protected](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

另外,如果我想相同時添加到單獨的時域和頻域(請注意,我只知道頻率的一側。區域相和不能同時所以不知道如何與這個尚未進行)

+0

請提供一個[mcve],並且包括可能有用的結果。 – m7913d

+0

剛剛添加了一張照片和結果。藍色是最初的功能。紅色是我認爲會一樣,但你可以告訴,這不是 – elis02

回答

2

您忘記了與重新調整「長度(T)」:

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

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

謝謝。 這是有效的。 – elis02