问题
I am getting an array of bytes (size 64) from an audio input stream (from a camera with sampling rate Fs = 44100Hz, in java). And then I convert this array into an array of doubles (the size of this array becomes 8) and perform FFT with jtransforms library:
DoubleFFT_1D fft = new DoubleFFT_1D(8);
fft.realForward(doubles);
And then I calculate frequencies: freq = i*Fs/N. My question is, N=8 or N=64? If N=8, should I somehow correct the value of rate sampling Fs? Would be very grateful for clarification.
EDITED: I figured that when I combine pairs of bytes, the size of the array will become 64/2=32. Will do it like this for each pair:
ByteBuffer bb = ByteBuffer.allocate(2);
bb.order(ByteOrder.LITTLE_ENDIAN);
bb.put(firstByte);
bb.put(secondByte);
double val = bb.getDouble(0);
The result is an array of doubles, exactly what I need. Now, when I calculate the frequencies (after normalization) freq = i*Fs/N, N = 32. Is it correct?
Also, as I am using fft.realForward(doubles) and not fft.realForwardFull(doubles), should I devide Fs by 2? That is, Fs = Fs/2?
Thank you again for your help and time..
回答1:
Before performing the FFT of the data you have to know the bit depth of the audio ( this is usually 16bits or 32Bits) so you can re-assemble the samples.
If for instance the bit depth is 16Bits ( 2 bytes) then we know that one byte only contains the first 8 bits of the sample and another byte will contain the last 8 bits so we combine ( not add ) the bytes to form a sample.After this we will divide this sample by 2^(BitDepth - 1) = 2^15 = 32678 to get the actual normalised sample which will be a sample between -1 and 1.After doing this we can proceed to perform an FFT on the data.
You might want to look at the answer to this question to see code showing how the actual casting and normalisation can be done.
来源:https://stackoverflow.com/questions/24403764/audio-sampling-rate-of-an-ip-camera-and-fft