vba 帮助 EXCEL 快速傅立叶变换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4502546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Help with EXCEL Fast Fourier Transform
提问by Vinay Pandey
I am trying to use Excel's (2007) built in FFT feature, however, it requires that I have 2^n data points - which I do not have.
我正在尝试使用 Excel (2007) 内置的 FFT 功能,但是,它要求我有 2^n 个数据点 - 而我没有。
I have tried two things, both give different results:
我尝试了两件事,都给出了不同的结果:
- Pad the data values by zeros so that N (the number of data points) reach the closest power of 2
- Use a divide-and-conquer approach i.e. if I have 112 data points, then I do a FFT for 64, then 32, then 16 (112=64+32+16)
- 用零填充数据值,以便 N(数据点的数量)达到最接近的 2 次方
- 使用分而治之的方法,即如果我有 112 个数据点,那么我对 64、32、16 进行 FFT(112=64+32+16)
Which is the better approach? I am comfortable writing VBA macros but I am looking for an algorithm which does not require the constraint of N being power of 2. Can anyone help?
哪种方法更好?我很乐意编写 VBA 宏,但我正在寻找一种不需要 N 为 2 幂的约束的算法。有人可以帮忙吗?
回答by sheepez
Splitting your data into smaller bits will result in erroneous output, especially for smaller numbers of data points.
将您的数据拆分成更小的位会导致错误的输出,尤其是对于较少数量的数据点。
Padding with zeroes is a much better idea, and the general approach for FFTs. If you are interested in an alternative way of doing the FFT, octave will do it for you, and most of the Matlab documentation applies so you should have no trouble with it.
用零填充是一个更好的主意,也是 FFT 的一般方法。如果您对进行 FFT 的替代方法感兴趣,octave 将为您完成,并且大多数 Matlab 文档都适用,因此您应该不会有任何问题。
回答by mtrw
Padding with zeros is the right direction, but keep in mind that if you're doing the transform in order to estimate frequency content, you will need a window function, and that should be applied to the short block (i.e., if you have 2000 points, apply a 2000 point Hann window, then pad to 2048 and calculate the transform).
用零填充是正确的方向,但请记住,如果您正在进行变换以估计频率内容,您将需要一个窗口函数,并且应该将其应用于短块(即,如果您有 2000点,应用 2000 点 Hann 窗口,然后填充到 2048 并计算变换)。
If you're developing an add-in, you might consider using one of the many FFT libraries out there. I'm a big fan of KISS FFTby Marc Borgerding. It offers fast transforms for many blocksizes, essentially any blocksize that can be factored into the numbers 2,3,4, and/or 5. It doesn't handle prime number sized blocks though. It's written in very plain C, so should be easy to port to C#. Or, this SO questionsuggests some libraries that can be used in .NET.
如果您正在开发插件,您可以考虑使用众多 FFT 库之一。我是Marc Borgerding的KISS FFT的忠实粉丝。它为许多块大小提供了快速转换,基本上可以分解为数字 2、3、4 和/或 5 的任何块大小。但它不处理质数大小的块。它是用非常普通的 C 语言编写的,因此应该很容易移植到 C#。或者,这个 SO question建议了一些可以在 .NET 中使用的库。
回答by duffymo
pad out with zeros
用零填充
2^n is a requirement of the FFT algorithm.
2^n 是 FFT 算法的要求。
Maybe a test of a known time series (e.g., simple sine or cosine of a single frequency). When you FFT that, you should get a single frequency (Dirac delta function). Anything else is an error. Do it with an integer power of two, padded with zeroes, etc.
也许是对已知时间序列的测试(例如,单一频率的简单正弦或余弦)。当你对它进行 FFT 时,你应该得到一个单一的频率(Dirac delta 函数)。其他任何事情都是错误。用 2 的整数幂做,用零填充,等等。