了解FFT输出 [英] Understanding FFT output

查看:394
本文介绍了了解FFT输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来理解DFT / FFT计算的输出。

I need some help understanding the output of the DFT/FFT computation.

我是一位经验丰富的软件工程师,需要解释一些智能手机加速度计读数,例如找到主要频率。不幸的是,我在十五年前的大部分EE课程中都睡不着觉,但过去几天我一直在阅读DFT和FFT(显然没什么用)。

I'm an experienced software engineer and need to interpret some smartphone accelerometer readings, such as finding the principal frequencies. Unfortunately, I slept through most of my college EE classes fifteen years ago, but I've been reading up on DFT and FFT for the last several days (to little avail, apparently).

请不要回答参加EE课程。如果我的雇主付钱给我,我实际上打算这样做。 :)

Please, no responses of "go take an EE class". I'm actually planning to do that if my employer will pay me. :)

所以这是我的问题:

我已经捕获了32 Hz的信号。这是一个32秒的1秒样本,我在Excel中绘制过。

I've captured a signal at 32 Hz. Here is a 1 second sample of 32 points, which I've charted in Excel.

然后我得到了一些 FFT代码(在关于 Java中可靠而快速的FFT )。

I then got some FFT code written in Java from Columbia University (after following the suggestions in a post on "Reliable and fast FFT in Java").

该程序的输出如下。我相信它正在运行就地FFT,因此它会为输入和输出重复使用相同的缓冲区。

The output of this program is as follows. I believe it is running an in-place FFT, so it re-uses the same buffer for both input and output.

Before: 

Re: [0.887  1.645  2.005  1.069  1.069  0.69  1.046  1.847  0.808  0.617  0.792  1.384  1.782  0.925  0.751  0.858  0.915  1.006  0.985  0.97  1.075  1.183  1.408  1.575  1.556  1.282  1.06  1.061  1.283  1.701  1.101  0.702  ]

Im: [0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ]

After: 

Re: [37.054  1.774  -1.075  1.451  -0.653  -0.253  -1.686  -3.602  0.226  0.374  -0.194  -0.312  -1.432  0.429  0.709  -0.085  0.0090  -0.085  0.709  0.429  -1.432  -0.312  -0.194  0.374  0.226  -3.602  -1.686  -0.253  -0.653  1.451  -1.075  1.774  ]

Im: [0.0  1.474  -0.238  -2.026  -0.22  -0.24  -5.009  -1.398  0.416  -1.251  -0.708  -0.713  0.851  1.882  0.379  0.021  0.0  -0.021  -0.379  -1.882  -0.851  0.713  0.708  1.251  -0.416  1.398  5.009  0.24  0.22  2.026  0.238  -1.474  ]

所以,此时,我无法做出输出的正面或反面。我理解DFT概念,例如真实部分是分量余弦波的幅度,虚部是分量正弦波的幅度。我也可以从伟大的书科学家和工程师的数字信号处理指南中查看这个图表。 :

So, at this point, I can't make heads or tails of the output. I understand the DFT concepts, such as the real portion being the amplitudes of the component cosine waves and the imaginary portion being the amplitudes of the component sine waves. I can also follow this diagram from the great book "The Scientist and Engineer's Guide to Digital Signal Processing":

所以我的具体问题是:


  1. 从FFT的输出中,我如何找到最常出现的频率?这是我对加速度计数据的分析的一部分。我应该读取真实(余弦)或虚数(正弦)数组吗?

  1. From the output of the FFT, how do I find the "most occurring frequencies"? This is part of my analysis of my accelerometer data. Should I read the real (cosine) or imaginary (sine) arrays?

我在时域中有32点输入。 FFT的输出不应该是实数的16元素数组和虚数的16元素数组吗?为什么程序给出了大小为32的实数和虚数阵列输出?

I have a 32-point input in the time domain. Shouldn't the output of the FFT be a 16-element array for reals and a 16-element array for imaginary? Why does the program give me real and imaginary array outputs both of size 32?

与上一个问题相关,我如何解析输出数组中的索引?鉴于我输入的32个样本以32 Hz采样,我的理解是16个元素的阵列输出应该使其索引均匀地扩展到采样率的1/2(32 Hz),所以我理解每个元素是正确的数组表示(32 Hz * 1/2)/ 16 = 1 Hz?

Related to the previous question, how do I parse the indexes in the output arrays? Given my input of 32 samples sampled at 32 Hz, my understanding is that a 16-element array output should have its index uniformly spread up to 1/2 the sampling rate (of 32 Hz), so am I correct in understanding that each element of the array represents (32 Hz * 1/2) / 16 = 1 Hz?

为什么FFT输出具有负值?我认为这些值代表正弦曲线的幅度。例如,对于频率为3的余弦波,Real [3] = -1.075的输出应表示幅度为-1.075。是吗?幅度如何为负?

Why does the FFT output have negative values? I thought the values represent amplitudes of a sinusoid. For example, the output of Real[ 3 ] = -1.075 should mean an amplitude of -1.075 for a cosine wave of frequency 3. Is that right? How can an amplitude be negative?


推荐答案


  1. 你既不应该寻找复数的真实或想象部分(你的实数和想象数是什么)。相反,你想要寻找频率的大小,定义为sqrt(real * real + imag * imag)。这个数字总是积极的。现在你需要搜索的只是最大值(忽略数组中的第一个条目。这是你的DC偏移并且没有频率相关信息)。

  1. You should neither look for the real or imaginative part of a complex number (that what's your real and imaginary array is). Instead you want to look for the magnitude of the frequency which is defined as sqrt (real * real + imag * imag). This number will always be positive. Now all you have to search is for the maximum value (ignore the first entry in your array. That is your DC offset and carries no frequency dependent information).

你得到32个实数和32个虚数输出,因为你正在使用复数到复数FFT。请记住,通过使用零虚部来扩展它,将32个样本转换为64个值(或32个复数值)。这导致对称FFT输出,其中频率结果发生两次。一旦准备好在输出0到N / 2中使用,并且在输出N / 2到N中镜像一次。在你的情况下,最简单地忽略输出N / 2到N.你不需要它们,它们是只是关于如何计算FFT的假象。

You get 32 real and 32 imaginary outputs because you are using a complex to complex FFT. Remember that you've converted your 32 samples into 64 values (or 32 complex values) by extending it with zero imaginary parts. This results in a symetric FFT output where the frequency result occurs twice. Once ready to use in the outputs 0 to N/2, and once mirrored in the outputs N/2 to N. In your case it's easiest to simply ignore the outputs N/2 to N. You don't need them, they are just an artifact on how you calculate your FFT.

fft-bin方程的频率为(bin_id * freq / 2)/(N / 2)其中freq是您的采样频率(又名32 Hz,N是FFT的大小)。在您的情况下,这简化为每箱1 Hz。箱子N / 2到N代表负频率(奇怪的概念,我知道)。对于您的情况,它们不包含任何重要信息,因为它们只是前N / 2频率的镜像。

The frequency to fft-bin equation is (bin_id * freq/2) / (N/2) where freq is your sample-frequency (aka 32 Hz, and N is the size of your FFT). In your case this simplifies to 1 Hz per bin. The bins N/2 to N represent negative frequencies (strange concept, I know). For your case they don't contain any significant information because they are just a mirror of the first N/2 frequencies.

每个部分的实部和虚部bin形成一个复数。如果实部和虚部是负的,而频率本身的幅度是正的,那也没关系(参见我对问题1的回答)。我建议你阅读复杂的数字。解释它们如何工作(以及它们有用的原因)超出了单个stackoverflow问题中可能解释的内容。

Your real and imaginary parts of each bin form a complex number. It is okay if real and imaginary parts are negative while the magnitude of the frequency itself is positive (see my answer to question 1). I suggest that you read up on complex numbers. Explaining how they work (and why they are useful) exceeds what is possible to explain in a single stackoverflow-question.

注意:您可能还想了解自相关是什么,以及如何使用它来查找信号的基频。我觉得这是你真正想要的。

Note: You may also want to read up what autocorrelation is, and how it is used to find the fundamental frequency of a signal. I have a feeling that this is what you really want.

这篇关于了解FFT输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆