【发布时间】:2016-04-28 14:54:21
【问题描述】:
我正在尝试在我的一个项目中实施 FFT。不幸的是,我觉得我去的每个网站都在解释我的想法。我查看了许多不同的网站以进行澄清,但可惜到目前为止我还没有找到。
到目前为止,我访问过的每个网站要么代码写得很好,没有关于变量或其他解释的 cmets,要么已经解释了我无法理解的程度。
如果有人能以最具描述性的方式分解此代码的每个部分和过程,我将不胜感激。
首先,我知道 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 岁的孩子能够理解,我将永远感激不尽。 (有时候看文章会觉得那个年纪)。
提前感谢您的所有帮助。你们在这里帮了我很多忙。
代码来源:http://rosettacode.org/wiki/Fast_Fourier_transform#Python
代码:
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
【问题讨论】:
-
这可能有助于您更好地理解算法及其实现:jakevdp.github.io/blog/2013/08/28/understanding-the-fft
-
这将有助于理解一些变量值。如果我发现更多,我会写一个真正有用的答案。 betterexplained.com/articles/…
-
这将有助于理解 DFT。我想在将这里所教的内容应用于您的问题后,我将能够给出一个有用的答案。 practicalcryptography.com/miscellaneous/machine-learning/…
-
非常好的文章。我已经研究了这三个,它们让我更好地了解 FFT 和 DFT 是什么。感谢所有的帮助。
标签: python-3.x signal-processing fft discrete-mathematics