我想將exp(-t^2)的FFT與函數的解析傅里葉變換exp( - (w^2)/ 4)/ sqrt(2 ),在-3到3的頻率範圍內。在Matlab中比較FFT函數和分析FT解決方案
我已經寫了下面的matlab代碼,並且現在迭代了很多次,但沒有成功。
fs = 100; %sampling frequency
dt = 1/fs;
t = 0:dt:10-dt; %time vector
L = length(t); %number of sample points
%N = 2^nextpow2(L); %necessary?
y = exp(-(t.^2));
Y=dt*ifftshift(abs(fft(y)));
freq = (-L/2:L/2-1)*fs/L; %freq vector
F = (exp(-(freq.^2)/4))/sqrt(2); %analytical solution
%Y_valid_pts = Y(W>=-3 & W<=3); %compare for freq = -3 to 3
%npts = length(Y_valid_pts);
% w = linspace(-3,3,npts);
% Fe = (exp(-(w.^2)/4))/sqrt(2);
error = norm(Y - F) %L2 Norm for error
hold on;
plot(freq,Y,'r');
plot(freq,F,'b');
xlabel('Frequency, w');
legend('numerical','analytic');
hold off;
你現在可以看到,我只是試圖讓這兩個地塊看起來相似。最終,我想找到一種方法來做兩件事:1)找到最小採樣率, 2)找到最小採樣數, 達到一個誤差(定義爲二者之差的L2範數解決方案)的10^-4。
我覺得這很簡單,但我似乎甚至看不到這兩個圖形在視覺上一致。 如果有人能讓我知道我要出錯的地方以及我如何處理上述兩點(最小採樣頻率和最小採樣數),我會非常感激。
由於