I am trying to visualise the output of an fft. I have taken the microphone output of my Android phone using "audiorecord". The input data is sampled at 32 kHz and I take 128 samples at a time from the record buffer to process.
Each 128 samples is passed to org.apache.commons.maths3.transform.FastFourierTransformer(DftNormalization.STANDARD)and I obtain the real and imaginary parts like this:
val complex = transformer.transform(window, TransformType.FORWARD) for (index in complex.indices) { val rr = complex[index].real val ri = complex[index].imaginary tempConversion[index] = Math.sqrt((rr * rr) + (ri * ri)) } I then take log(10) of the data values (as the range is large) and plot them:
If I play high or low pitched sounds near the microphone, the U shaped plot shape is similar, but the "floor" of the plot rises.
Questions:
- Does the plot of the data appear correct?
- I am trying to create a "graphic equaliser" type visualisation of the audio captured by the microphone, can you suggest how I should process the fft data further so I can show the frequency spectrum of the captured audio data?
Many thanks for the replies, I have understood a lot more about how to proceed, and I think I'm making progress.
Firstly I took the microphone sampling out of the equation, and created a dummy data set to analyse.
val f1:Float = 10000f val f2:Float = 15000f val FFT_N = 1024 val FFT_input = FloatArray(FFT_N) for (i in 0..< FFT_N){ val k = 100 * sin(2*Math.PI*f2*i/(FFT_N-1)) + 100 * sin(2*Math.PI*f1*i/(FFT_N-1)) FFT_input[i] = k.toFloat() } return FFT_inputI upped the fft size to 1024, which surprisingly didn't have an adverse effect on the speed the code runs at.
I created a function to discard the fft bins that correspond to the Nyquist frequency and above, so from an fft of 1024 I'm left with the first 511 bins of data.
I decided not to plot the y axis (bin values) on a logarithmic scale, the dummy data plot looks much better, with 2 clearly discernible peaks.
- I added a Hamming window to the data before calculating the fft, I think it is improving the data plot by reducing spectral leakage but have not spent much time looking at this.
Now I know the data graphing is working reasonably well, I tried putting real microphone data back into the system.
As the existing comments mention (thanks), there appears to be low frequency noise. The screen shot below shows this clearly. Could anyone suggest a way of filtering out this noise, or at least minimising it? My guess is it's being introduced by the microphone preamp circuitry of the phone? One thing to note is it isn't consistent, as in the "noise" fizzes on the graph. It's generally affecting the first 10 bins, with the highest value in bin zero, being at about 10,000 ish.


