使用 GNU Octave FFT 函数
我正在使用八度的 fft 函数,但我无法真正弄清楚如何缩放它们的输出:我使用以下(非常短的)代码来近似函数:
function y = f(x)
y = x .^ 2;
endfunction;
X=[-4096:4095]/64;
Y = f(X);
# plot(X, Y);
F = fft(Y);
S = [0:2047]/2048;
function points = approximate(input, count)
size = size(input)(2);
fourier = [fft(input)(1:count) zeros(1, size-count)];
points = ifft(fourier);
endfunction;
Y = f(X); plot(X, Y, X, approximate(Y, 10));
基本上,它的作用是采用函数,计算图像一个音程,对其进行 fft,然后保留一些谐波,并对结果进行 ifft。然而我得到了一个垂直压缩的图(输出的垂直比例是错误的)。有什么想法吗?
I'm playing with octave's fft functions, and I can't really figure out how to scale their output: I use the following (very short) code to approximate a function:
function y = f(x)
y = x .^ 2;
endfunction;
X=[-4096:4095]/64;
Y = f(X);
# plot(X, Y);
F = fft(Y);
S = [0:2047]/2048;
function points = approximate(input, count)
size = size(input)(2);
fourier = [fft(input)(1:count) zeros(1, size-count)];
points = ifft(fourier);
endfunction;
Y = f(X); plot(X, Y, X, approximate(Y, 10));
Basically, what it does is take a function, compute the image of an interval, fft-it, then keep a few harmonics, and ifft the result. Yet I get a plot that is vertically compressed (the vertical scale of the output is wrong). Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在放弃转换的后半部分。对于实值输入,变换是埃尔米特对称的,您必须保留这些线。试试这个:
由于数值计算误差,逆变换总是会产生一些微小的虚部,因此是
实数
提取。注意,
input
和size
是Octave中的关键字;用你自己的变量破坏它们是一个很好的方法,可以在路上得到非常奇怪的错误!You are throwing out the second half of the transform. The transform is Hermitian symmetric for real-valued inputs and you have to keep those lines. Try this:
The inverse transform will invariably have some tiny imaginary part due to numerical computation error, hence the
real
extraction.Note that
input
andsize
are keywords in Octave; clobbering them with your own variables is a good way to get really weird bugs down the road!你可能做错了。您删除代码中的所有“负”频率。您应该保留正低频和负低频。这是 python 代码和结果。该情节具有正确的规模。
替代文本 http://files.droplr.com/files/35740123/XUl90。 fft.png
代码:
You are probably doing it wrong. You remove all the "negative" frequencies in your code. You should keep both positive and negative low frequencies. Here is a code in python and the result. The plot has the right scale.
alt text http://files.droplr.com/files/35740123/XUl90.fft.png
The code: