简体   繁体   中英

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 .

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.

I see that fft-js expects signal values from -1 to 1 as seen in this example of it's usage:

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?

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:

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

If my uint8Array looks like this:

[ 256, 192, 128, 64, 0]

Then arrForFFT would look like this:

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

Edit: If you're not using ES2015, the code would look like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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