Android 2.3 Visualizer - 无法理解 getFft()

发布于 2024-10-12 05:47:18 字数 1709 浏览 7 评论 0原文

第一次来这里,对于任何被破坏的格式提前表示歉意。

所以我对 DSP 完全陌生,所以我对傅立叶变换只有非常一般的了解。我正在尝试为 Android SDK 9 构建一个可视化应用程序,其中包含 android.media.audiofx.Visualizer 中的 Visualizer 类 http://developer.android.com /reference/android/media/audiofx/Visualizer.html

方法 getFft() 的 javadoc(我正在使用的状态):

“返回频率捕获 当前正在播放音频内容。这 捕获是 8 位幅度的 FFT。笔记 FFT 的大小是一半 指定的捕获大小,但两者 返回频谱的两侧 产生的字节数等于 捕获大小。”

首先,“频谱的两侧”是什么意思?此输出与标准 FFT 有何不同?

是字节数组的一些示例输出,getFft() 被赋予 124 个点来保留它简单,我抓住了前 31 个垃圾箱。以下是前 31 个垃圾箱的大小:

{123, -2, -23, -3, 6, -16, 15, -10, -8, -12, 9, -9, 17, -6, -18, -22, -8, 4, -5, -2, 10, -3, -11, 3, -4, -11, -8, 15, 16, 11, -12, 12}

任何帮助或解释将不胜感激

编辑:所以在看了一堆图表之后,它看起来我的问题的一部分是谷歌没有指定使用什么单位,几乎所有其他测量都是以 mHz 为单位,假设 FTT 输出也是以 mHz 为单位是否公平? Visualizer 类的代码,所以也许我可以弄清楚幕后到底发生了什么?

我继续获取 getFft() 的所有输出,

93, -2, -28, -16, -21, 19, 44, -16, 3, 16, -9, -4, 0, -2, 21, 16, -3, 1, 2, 4, -3, 5, 5, 10, 6, 4, -9, 7, -2, -1, 2, 11, -1, 5, -8, -2, -1, 4, -5, 5, 1, 3, -6, -1, -5, 0, 0, 0, -3, 5, -4, -6, -2, -2, -1, 2, -3, 0, 1, -3, -4, -3, 1, 1, 0, -2, -1, -1, 0, -5, 0, 4, -1, 1, 1, -1, 1, -1, -3, 2, 1, 2, -2, 1, 0, -1, -2, 2, -3, 4, -2, -2, 0, 1, -4, 0, -4, 2, -1, 0, -3, -1, -1, -1, -5, 2, -2, -2, 0, -3, -2, 1, -5, -2, 0, 0, 0, -2, -2, -1, -1, -1, -2, 0, 3, -3, -1, 0

所以如果我理解正确,我这里的输出应该从-N到0到N。-N到0应该看起来就像0到N。但是当我查看这些幅度时,我没有看到任何镜像数据。谷歌似乎表明输出应该是从 0 到 N 正好在频谱的两侧。所以我应该能够将数据从 (output.length-1)/2 获取到 output.length-1 。负幅度的移动速度快于采样率,正幅度的移动速度慢于采样率。我理解正确吗?

First time here so sorry in advance for any butchered formatting.

So I am completely new to DSP so I have only a very general understanding of the Fourier Transform. I am trying to build a visualizer app for Android SDK 9, which includes a Visualizer class in android.media.audiofx.Visualizer
http://developer.android.com/reference/android/media/audiofx/Visualizer.html

The javadoc for the method getFft(), which is what I am using states:

"Returns a frequency capture of
currently playing audio content. The
capture is a 8-bit magnitude FFT. Note
that the size of the FFT is half of
the specified capture size but both
sides of the spectrum are returned
yielding in a number of bytes equal to
the capture size."

First of all, what does "both sides of the spectrum" mean? How does this output differ from a standard FFT?

Here is some sample output of the byte array, getFft() was given 124 points to keep it simple and I grabbed the first 31 bins. Here are the magnitudes of the first 31 bins:

{123, -2, -23, -3, 6, -16, 15, -10, -8, -12, 9, -9, 17, -6, -18, -22, -8, 4, -5, -2, 10, -3, -11, 3, -4, -11, -8, 15, 16, 11, -12, 12}

Any help or explanation would be greatly appreciated!

Edit: So after staring at a bunch of graphs it looks like part of my problem is Google does not specify what unit is being used. Almost all other measurements are done in mHz, would it be fair to assume that the FTT output is also in mHz? Is there a place where I can see the source code of the Visualizer class so maybe I can figure out what the hell is actually going on under the hood?

I went ahead and grabbed all of the output of getFft()

93, -2, -28, -16, -21, 19, 44, -16, 3, 16, -9, -4, 0, -2, 21, 16, -3, 1, 2, 4, -3, 5, 5, 10, 6, 4, -9, 7, -2, -1, 2, 11, -1, 5, -8, -2, -1, 4, -5, 5, 1, 3, -6, -1, -5, 0, 0, 0, -3, 5, -4, -6, -2, -2, -1, 2, -3, 0, 1, -3, -4, -3, 1, 1, 0, -2, -1, -1, 0, -5, 0, 4, -1, 1, 1, -1, 1, -1, -3, 2, 1, 2, -2, 1, 0, -1, -2, 2, -3, 4, -2, -2, 0, 1, -4, 0, -4, 2, -1, 0, -3, -1, -1, -1, -5, 2, -2, -2, 0, -3, -2, 1, -5, -2, 0, 0, 0, -2, -2, -1, -1, -1, -2, 0, 3, -3, -1, 0

So if I understand this correctly, my output here should be from -N to 0 to N. -N to 0 should look just like 0 to N. But when I look at these amplitudes, I don't see any mirrored data. Google seems to indicate that the output should be from 0 to N just on both sides of the spectrum. So I should be able to take the data from (output.length-1)/2 to output.length-1. The negative amplitudes are moving faster than the sample rate and the positive amplitudes are moving slower than the sample rate. Did I understand this correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉月流沐 2024-10-19 05:47:18

如果它对任何人有帮助,我创建了一个可视化工具,它获取 MediaPlayer 的输出并显示可视化效果。它适用于正常波形和 FFT 数据:

https://github.com/felixpalmer/android-visualizer

它包含代码用于将 getFft() 的输出转换为具有视觉意义的内容。

In case it helps anyone, I've created a Visualizer which takes the output from the MediaPlayer and displays a visualization. It works with both normal waveform and FFT data:

https://github.com/felixpalmer/android-visualizer

It includes code for converting the output of getFft() into something visually meaningful.

负佳期 2024-10-19 05:47:18

FFT 输出样本 k 的频率由下式给出:

Fk = k * Fs / N,    k = 0,1,...,N-1 

其中

  • Fs 是时间序列输入的采样频率
  • N 是用于计算 FFT 的样本数

两侧频谱的频率是指 FFT 输出中的正频率和负频率。 FFT 强制频率输出周期为 Fs。如果查看 FFT 输出,它涵盖了从 0 到 Fs 的频率。通过将 FFT 输出从 0.5*Fs → 0.5*Fs 移动来查看 -0.5*Fs 至 0.5*Fs 范围内的频谱通常是有利的。 Fs 至 -0.5*Fs -> 0 因为它们由于周期性而相等。

对于实值信号,例如音频处理中的信号,负频率输出将是正频率的镜像。因此,在分析实际信号时通常只使用频谱的一侧。

另一个重要的一点是 0.5*Fs 的重要性,它被称为奈奎斯特频率。信号只能准确地表示高达奈奎斯特频率的频率,高于该频率的任何频率都会混叠(折叠)回频谱上,从而导致失真。

因此,出于可视化目的,实际上您应该担心的是与 0 到 Fs/2 频率范围相对应的 FFT 输出样本,因为这些样本对于采样率为 Fs 的真实信号来说是有意义的样本。

The frequency at FFT output sample k is given by:

Fk = k * Fs / N,    k = 0,1,...,N-1 

where

  • Fs is the sampling frequency of the time series input
  • N is the number of samples used to compute the FFT

The two sides of the spectrum refers to the positive and negative frequencies in the output of the FFT. The FFT forces the frequency output to be periodic with a period of Fs. If you look at the FFT output, it covers the frequencies from 0 to Fs. It is often advantageous to view the spectrum over the range of -0.5*Fs to 0.5*Fs instead by shifting the FFT output from 0.5*Fs -> Fs to -0.5*Fs -> 0 since they are equal because of the periodicity.

For real-valued signals, like the ones you have in audio processing, the negative frequency output will be a mirror image of the positive frequencies. Because of this, often only one side of the spectrum is used when analyzing real signals.

Another important point is the significance of 0.5*Fs which is known as the Nyquist Frequency. A signal can only accurately represent frequencies up to the Nyquist frequency and anything above it will be aliased (folded) back onto the spectrum causing distortion.

So really all you should worry about for visualization purposes are the FFT output samples corresponding to the range of frequencies from 0 to Fs/2 since those are the meaningful samples for a real signal with sampling rate Fs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文