Matlab中IFFT的缩放问题 [英] Scaling problems with IFFT in Matlab

查看:344
本文介绍了Matlab中IFFT的缩放问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过将Matlab应用到高斯来研究IFFT.根据 Wikipedia 表,傅里叶变换对将是

I'm studying the IFFT in Matlab by applying it to a Gaussian. According to Wikipedia tables, the Fourier transform pair would be

F(w) = sqrt(pi/a) * exp(-w^2/(4a))

频率和

f(t) = exp(-at^2)

及时.我在上一个问题中修改了代码克里斯·伦戈(Cris Luengo)执行此IFFT的答案.

in time. I modified the code in a previous question plus Cris Luengo's answer to perform this IFFT.

a = 0.333;

ts = 1e4; % time sampling
L = 1000*ts; % no. sample points
ds = 1/ts;
f = -floor(L/2):floor((L-1)/2); % freq vector
f = f/ts;

w = 2*pi*f; % angular freq
Y = sqrt(pi/a)*exp(-w.^2/(4*a));

y = ts*ifftshift(ifft(fftshift(Y)));

t = (-L/2:L/2-1)*ts/L; % time vector

f = exp(-a*t.^2); % analytical solution

figure; subplot(1,2,1); hold on
plot(t,real(y),'.--')
plot(t,real(f),'-')
xlabel('time, t')
title('real')
legend('numerical','analytic')
xlim([-5,5])
subplot(1,2,2); hold on
plot(w,imag(y),'.--')
plot(w,imag(f),'-')
xlabel('time, t')
title('imag')
legend('numerical','analytic')
xlim([-5,5])

当我将IFFT的结果与解析表达式进行比较时,他们似乎不同意:

When I compare the result of IFFT with the analytical expression, they don't seem to agree:

我不确定错误在哪里.我是否已正确缩放IFFT?在定义线性/角频率时是否存在错误?

I'm not sure where the mistake is. Have I scaled the IFFT properly? Is there an error in how I define the linear/angular frequency?

由于某种原因,当我定义L=ts^2时,解析和数值解似乎是一致的(L =采样点数量,ts =时间采样).

For some reason, when I define L=ts^2 the analytical and numerical solutions seem to agree (L = no. sampling points, ts = time sample).

推荐答案

从分析解决方案开始,让我们重新说明一下.您对函数f(t) = exp(-a*t^2)进行了采样,并且以解析方式构建了以Ts=ts/L=1e-3的采样率收集L=1000*ts=1e7样本的分析答案.这意味着您的采样频率为Fs=1/Ts=1e3.

Starting from the analytical solution, let's rephrase things a bit. You have a sampling of the function f(t) = exp(-a*t^2), and the way you've constructed the analytical answer you're collecting L=1000*ts=1e7 samples at a sampling rate of Ts=ts/L=1e-3. This means that your sampling frequency is Fs=1/Ts=1e3.

由于要与使用fft/ifft获得的结果进行比较,因此应考虑使用数字或<离散> em 频率,这意味着您为自己定义的值变换将对应于数字频率

Since you want to compare against results obtained with fft/ifft, you should be considering digital or discrete frequencies, meaning the values you define for your transform will correspond to the digital frequencies

frd = (-L/2:L/2-1)/L;

将其映射到角频率,我们有:

Mapping this to angular frequencies, we have:

w = 2*pi*frd;

但是,当您尝试计算值时,还需要记住,这些频率应代表您期望的连续时间谱的样本.因此,您可以根据采样频率缩放这些值:

But when you're trying to compute the values, you also need to keep in mind that these frequencies should represent samples of the continuous time spectrum you're expecting. So you scale these values by your sampling frequency:

Y = sqrt(pi/a)*exp(-(Fs*w).^2/(4*a));
y = Fs*ifftshift(ifft(fftshift(Y)));

当您比较分析性答案和计算性答案时,它们现已匹配.

When you compare the analytical and computed answers, they now match.

鉴于此,对这个问题的简短回答是,最后您错误地缩放了y.您正在按ts(即1e4)进行缩放,但是您需要按Fs=1e3的采样频率对其进行缩放.这就是为什么您最终损失10倍的原因.

The short answer to your question, given this, is that you are scaling y incorrectly at the end. You're scaling it by ts, which is 1e4, but you need to be scaling it by the sampling frequency which is Fs=1e3. That's why you end up off by a factor of 10.

这篇关于Matlab中IFFT的缩放问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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