在Matlab中将函数的FFT与FT解析解进行比较 [英] Comparing FFT of Function to Analytical FT Solution in Matlab

查看:113
本文介绍了在Matlab中将函数的FFT与FT解析解进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将exp(-t ^ 2)的FFT与函数的解析傅立叶变换exp(-(w ^ 2)/4)/sqrt(2)在-3至3的频率范围内进行比较

I am trying to compare the FFT of exp(-t^2) to the function's analytical fourier transform, exp(-(w^2)/4)/sqrt(2), over the frequency range -3 to 3.

我已经编写了以下matlab代码,并对其进行了很多次迭代,但均未成功.

I have written the following matlab code and have iterated on it MANY times now with no success.

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)找到最小样本数, 达到10 ^ -4的误差(定义为两个解之差的L2范数).

You can see that right now, I am simply trying to get the two plots to look similar. Eventually, I would like to find a way to do two things: 1) find the minimum sampling rate, 2) find the minimum number of samples, to reach an error (defined as the L2 norm of the difference between the two solutions) of 10^-4.

我觉得这很简单,但是我什至无法使两个图表在视觉上达成一致. 如果有人能让我知道我要去哪里,以及如何解决上述两点(最小采样频率和最小采样数),我将非常感激.

I feel that this is pretty simple, but I can't seem to even get the two graphs visually agree. If someone could let me know where I'm going wrong and how I can tackle the two points above (minimum sampling frequency and minimum number of samples) I would be very appreciative.

谢谢

推荐答案

首先要注意的是,函数exp(-t^2)的傅立叶变换对在+/-无限范围内,可以从傅立叶变换表实际上是:

A first thing to note is that the Fourier transform pair for the function exp(-t^2) over the +/- infinity range, as can be derived from tables of Fourier transforms is actually:

最后,在生成函数exp(-t^2)时,您将t的范围限制为正值(而不是整个+/-无穷大范围). 为了保持这种关系,您将必须生成带有以下内容的exp(-t^2):

Finally, as you are generating the function exp(-t^2), you are limiting the range of t to positive values (instead of taking the whole +/- infinity range). For the relationship to hold, you would thus have to generate exp(-t^2) with something such as:

t = 0:dt:10-dt;     %time vector
t = t - 0.5*max(t); %center around t=0
y = exp(-(t.^2));

然后,变量w表示以弧度表示的角频率,该角频率通过以下方式与归一化的频率freq相关:

Then, the variable w represents angular frequency in radians which is related to the normalized frequency freq through:

w = 2*pi*freq;

因此

F = (exp(-((2*pi*freq).^2)/4))*sqrt(pi); %analytical solution

这篇关于在Matlab中将函数的FFT与FT解析解进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆