实时进行FFT [英] Doing FFT in realtime

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

问题描述

我想实时进行音频信号的FFT,这意味着当人在麦克风中讲话时.我将获取数据(我将使用portaudio进行此操作,如果使用wavein会更简单,那么我很乐意使用它-如果您能告诉我怎么做的话).接下来,我正在使用FFTW库-我知道如何执行1D,2D(真实和复杂)FFT,但是我不确定如何执行此操作,因为我必须进行3D FFT才能获得频率,幅度(这将确定颜色渐变)和时间.还是仅仅是2D FFT,我得到了幅度和频率?

I want to do the FFT of an audio signal in real time, meaning while the person is speaking in the microphone. I will fetch the data (I do this with portaudio, if it would be easier with wavein I would be happy to use that - if you can tell me how). Next I am using the FFTW library - I know how to perform 1D, 2D (real&complex) FFT, but I am not so sure how to do this, since I would have to do a 3D FFT to get frequency, amplitude (this would determine the color gradient) and time. Or is it just a 2D FFT, and I get amplitude and frequency?

推荐答案

如果在一张图中需要幅度,频率和时间,则该变换称为时频分解.最受欢迎的一种称为短时傅立叶变换.它的工作方式如下:
1.取一小部分信号(例如1秒钟)
2.用一个小窗口(例如5毫秒)将其打开窗口
3.计算加窗信号的一维傅立叶变换.
4.将窗口移动一小段时间(2.5毫秒)
5.重复上述步骤,直到信号结束.
6.将所有这些数据输入一个矩阵,然后使用该矩阵创建信号的3D表示形式,以表示其沿频率,幅度和时间的分解.

If you need amplitude, frequency and time in one graph, then the transform is known as a Time-Frequency decomposition. The most popular one is called the Short Time Fourier Transform. It works as follows:
1. Take a small portion of the signal (say 1 second)
2. Window it with a small window (say 5 ms)
3. Compute the 1D fourier transform of the windowed signal.
4. Move the window by a small amount (2.5 ms)
5. Repeat above steps until end of signal.
6. All of this data is entered into a matrix that is then used to create the kind of 3D representation of the signal that shows its decomposition along frequency, amplitude and time.

窗口的长度将决定您能够在频域和时域中获得的分辨率.检查此处,以获取有关STFT的更多详细信息,并搜索关于小波的"Robi Polikar"教程转换为外行对上述内容的介绍.

The length of the window will decide the resolution you are able to obtain in frequency and time domains. Check here for more details on STFT and search for "Robi Polikar"'s tutorials on wavelet transforms for a layman's introduction to the above.


您可以使用窗口功能(那里有无数的功能-这是一个列表.大多数直观"是一个矩形窗口,但最常用的是汉明/汉宁"窗口功能.如果手边有铅笔并随手绘制,则可以按照以下步骤操作.

Edit 1:
You take a windowing function (there are innumerable functions out there - here is a list. Most intuitive is a rectangular window but the most commonly used are the Hamming/Hanning window functions. You can follow the steps below if you have a paper-pencil in hand and draw it along.

假定您获得的信号为1秒长,并命名为x[n].窗口函数的长度为5毫秒,并命名为w[n].将窗口放置在信号的开始处(因此窗口的结束与信号的5ms点重合),然后像下面这样乘以x[n]w[n]:
y[n] = x[n] * w[n]-信号的逐点乘法.
进行y[n]的FFT.

Assume that the signal that you have obtained is 1 sec long and is named x[n]. The windowing function is 5 msec long and is named w[n]. Place the window at the start of the signal (so the end of the window coincides with the 5ms point of the signal) and multiply the x[n] and w[n] like so:
y[n] = x[n] * w[n] - point by point multiplication of the signals.
Take an FFT of y[n].

然后,您将窗口移动一小段时间(例如2.5毫秒).因此,现在窗口从信号x[n]的2.5ms扩展到7.5ms.重复乘法和FFT生成步骤.换句话说,您有2.5毫秒的重叠.您会看到,更改窗口的长度和重叠部分会在时间和频率轴上为您提供不同的分辨率.

Then you shift the window by a small amount (say 2.5 msec). So now the window stretches from 2.5ms to 7.5 ms of the signal x[n]. Repeat the multiplication and FFT generation steps. In other words, you have an overlap of 2.5 msec. You will see that changing the length of the window and the overlap gives you different resolutions on the time and Frequency axis.

执行此操作后,需要将所有数据输入矩阵,然后显示出来.重叠是为了最小化边界处可能出现的误差,并且还可以在如此短的时间范围内获得更一致的测量结果.

Once you do this, you need to feed all the data into a matrix and then have it displayed. The overlap is for minimising the errors that might arise at boundaries and also to get more consistent measurements over such short time frames.

PS:如果您了解信号的STFT和其他时频分解,那么步骤2和步骤4应该没有问题.您还不了解上述步骤,这让我觉得您应该重温时间频率分解.

P.S: If you had understood STFT and other time-frequency decompositions of a signal, then you should have had no problems with steps 2 and 4. That you have not understood the above mentioned steps makes me feel like you should revisit time-frequency decompositions also.

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

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