【问题标题】:FFT Code Break DownFFT 代码分解
【发布时间】: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

【问题讨论】:

标签: python-3.x signal-processing fft discrete-mathematics


【解决方案1】:

FFT 只是计算 DFT 的一种快速方法(使用因式分解技巧)。

也许首先要了解 DFT 的作用,因为 FFT 因式分解技巧可能会混淆 DFT 的作用问题。 DFT 只是一个基本变换(一种矩阵乘法)。单位可以是完全任意的(毫伏、英寸、加仑、美元等),任何一组频率结果都取决于输入数据的采样率。

【讨论】:

  • 是否在 fft 内外都进行了维护?如果他把hz放进去,他会把hz拿出来吗?
  • 所以.. 从我正在阅读的内容来看.. 是吗?如果是这样,一个简单的“是”就可以了。
  • 看来你是对的。在我进一步研究之后,我发现只要我正确理解了 DFT,我就能掌握 FFT。对 DFT 有一个简短的概述或一个可以找到简单解释的链接会很有帮助,但@TysonGraham 在上面给了我一个很好的链接。感谢您的时间和精力。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多