我正在尝试在我的一个项目中实现FFT。不幸的是,我觉得我去的每个网站都在解释我的想法。我已经查看了许多不同的网站进行澄清,但到目前为止我还没有找到它。
到目前为止,我所拥有的每个网站都要么编写好的代码,没有对变量或其他解释的评论,要么已经解释了一些我无法理解的事情。
如果有人能够以最具描述性的方式分解此代码的每个部分和过程,我将不胜感激。
首先,我知道FFT的输入是[1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0]。这些数字代表什么?它们是赫兹还是伏特?
最后,我知道FFT的输出是4.000 2.613 0.000 1.082 0.000 1.082 0.000 2.613。这些数字代表什么?单位是什么?它们如何用于从数据集中获得幅度或频率?
同样,我正在寻找要解释的每一步,因此评论以下FFT代码也会非常有帮助。如果你能够很好地解释这个5岁的孩子会理解的话,我将永远感激不尽。 (有时候看文章的时候我觉得这个年龄。)
提前感谢所有帮助。你们这里的人帮了我一个TON。
代码来源:http://rosettacode.org/wiki/Fast_Fourier_transform#Python
CODE:
from cmath import exp, pi
def fft(x):
# I understand that we are taking the length of the array sent
# into the function and assigning it to N. But I do not get why.
N = len(x)
# I get that we are returning itself if it is the only item.
# What does x represent at this point?
if N <= 1: return x
# We are creating an even variable and assigning it to the fft of
# the even terms of x. This is possibly because we can use this
# to take advantage of the symmetry?
even = fft(x[0::2])
# We are now doing the same thing with the odd variable. It is
# going to be the fft of the odd terms of x. Why would we need
# both if we are using it to take advantage of the symmetry?
odd = fft(x[1::2])
T= [exp(-2j*pi*k/N)*odd[k] for k in range(N//2)]
return [even[k] + T[k] for k in range(N//2)] + \
[even[k] - T[k] for k in range(N//2)]
# I understand that we are printing a join formatted as a float
# I get that the float will have 3 numbers after the decimal place and
# will take up a total of 5 spots
# I also understand that the abs(f) is what is being formatted and
# that the absolute value is getting rid of the imaginary portion
# that is often seen returned by the FFT
print( ' '.join("%5.3f" % abs(f)
for f in fft([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0])) )
返回值:
4.000 2.613 0.000 1.082 0.000 1.082 0.000 2.613
答案 0 :(得分:1)
FFT只是计算DFT的一种快速方法(使用分解技巧)。
也许首先要了解DFT的作用,因为FFT因子技巧可能会混淆DFT的作用。 DFT只是基础变换(一种矩阵乘法)。单位可以是完全任意的(毫伏,英寸,加仑,美元等)。任何一组频率结果都取决于输入数据的采样率。