3

波形文件:44100 Hz,16 位,双通道。

我使用 FFT 计算每个输出频率区间的幅度。但我不知道缩放它以绘制(实时)频谱。

任何人都可以帮助我吗?

4

2 回答 2

4

出色地; 有很多方法可以做到这一点......

例如:如果你想要一个 dB 比例,对于每个假想的样本,计算

ymag = (x.real^2 + x.imag^2)

您只想通过一半阵列,因为您想要正频率;后半部分将只是第一部分的重复,将真实数据馈送到 FFT。

在结果值中搜索最小值和最大值并存储它们。如果您的最小值为零,请选择一些非常小的值作为您的最小值。(0.000001 或其他东西)。然后,将最小 dB 值设置为 mindB = 10 * log10(minimum)。

现在,返回的第一个值 (sample[0]) 将是您的 DC 偏移量,您可能希望将其设置为零。

然后,对于每个样本,计算:ydB = 10 * log10(ymag / 最大值)。

这应该为您提供一个数组,该数组表示从每个样本箱的最大值向下的 dB。您可以将其扩展到您需要的任何内容;如果您的绘图区域从 y=5 变为 y=200,您可以使用类似:

yscaled = ((ydB / -mindB) * (200 - 5) + 200)

如果存在 FP 舍入误差,我还将确保缩放值符合界限。

yscaled = min(max(yscaled, 5),200)

自从我这样做以来已经有一段时间了,所以如果有任何数学错误,我深表歉意。:)

于 2011-07-12T16:13:43.530 回答
1

Different FFT implementations have different scale factors, perhaps differing by N, 1/N, or 1/sqrt(N), where N is the length of the FFT. For at least one kind of signed integer input FFT, max scale is around sqrt(2) * N * 2^(b - 1), where b is the number of bits to the left of the decimal point (16 in your case, maybe 17 if you sum the channels into a larger data type before the FFT).

于 2011-07-13T00:19:31.847 回答