简体   繁体   English

对8位PCM信号进行FFT

[英]FFT on the 8 bit PCM signal

I'm using this fast fourier transform implementation in node-js: https://www.npmjs.com/package/fft-js . 我在node-js中使用这种快速傅立叶变换实现: https : //www.npmjs.com/package/fft-js

I am using wav reader which reads my wav file which is encoded as 8 bit PCM and outputs data as an array of 8 bit unsigned integers. 我正在使用wav阅读器,它读取我的wav文件,该文件被编码为8位PCM,并以8位无符号整数的数组形式输出数据。

I see that fft-js expects signal values from -1 to 1 as seen in this example of it's usage: 我看到fft-js期望信号值从-1到1,如本例用法所示:

var fft = require('fft-js').fft,
    signal = [1,0,1,0];

var phasors = fft(signal);

console.log(phasors);

What should I do? 我该怎么办? Should I convert my 8 bit pcm representation of the wav file to values between -1 and 1, and if so how? 我应该将wav文件的8位pcm表示形式转换为-1和1之间的值吗?

According to this article on Wikipedia, you should be able to take the 8bit uint data and map it to a number between -1 and 1 with something similar to this: 根据Wikipedia上的这篇文章 ,您应该能够获取8位uint数据并将其映射到-1和1之间的数字,类似于以下内容:

let arrForFFT = uint8Array.map(num => (num - 128) / 128)

If my uint8Array looks like this: 如果我的uint8Array看起来像这样:

[ 256, 192, 128, 64, 0]

Then arrForFFT would look like this: 然后arrForFFT看起来像这样:

[ 1, 0.5, 0, -0.5, -1]

Edit: If you're not using ES2015, the code would look like this: 编辑:如果您不使用ES2015,代码将如下所示:

var arrForFFT = uint8Array.map(function(num) {
  return (num - 128) / 128
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM