How to develop a spectrum analyzer from real-time audio?

I am developing an application that receives the original sound from the microphone in real time, without storing files. I mainly use:

mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mRecorder.setOutputFile("/dev/null"); 

My question is how can I make spectral graphics from this sound in real time without files. It can be done?

All the messages I read analyze the spooled file.

Thank you and sorry for my english.

+6
source share
3 answers

Yes, it can be done.

All you need is a fast FFT algorithm!

First decide the desired frequency resolution, for example, you can set the sampling frequency from your microphone to 8000 Hz, now select one block size, for example 1024 or 2048, to capture from your microphone.

If you select 2048 points and a sampling frequency of 8000, you will have a resolution of frequency = 3.9063 (8000/2048).

Apply one window function to your 2048 points, then apply FFT and get the value!

Remember the sample rate of Nyquist theorems = 8000/2 = 4000, now you know that your FFT can receive frequencies between 3.9063 Hz at 4000 Hz.

FFT bit of the corresponding frequencies:

 1 -> 3,90625 hz 2 -> 7,8125 hz 3 -> 11,71875 hz ... 1024 -> 4000 hz ... 2048 - > 8000 hz 

To do this, you only need the values โ€‹โ€‹of the first half of the FFT, for this case 1024.

Now, if you build this data from your FFT, you will have a spectrum!

EDIT

Pseudocode:

 #construct one hanning window Function Chunk = 2048; windowed = [Chunk]; hanning = [Chunk]; for i 1:Chunk: hanning[i] = ((1 - cos(i*2*pi/Chunk-1))/2) #start capture from Mic while true: #into values capture 2048 points from your mic values=dataFromMic(Chunk); #Apply Window hanning = multiply window function(hanning) over your 2048 points for i 1:Chunk: windowed[i] = values[i] * hanning[i] #Apply FFT fftData=fft(windowed); #Get Magnitude (linear scale) of first half values Mag=abs(fftData(1:Chunk/2)) # update/show results plot(Mag) end 
+5
source

Github has an open-source Android spectrum analyzer that FFT plays audio from a microphone and displays a 2D spectrogram.

Spectrum analyzer design found in v2.x / display application

You can see a video about this in action https://youtu.be/yU05fsgOYO4

Here you can watch the video with assembly instructions: https://youtu.be/tVgn30uss2k?t=1m37s

enter image description here

The graphic image is provided by the Android SciChart charting library , which is a commercial control, but the source code for reading the microphone, calculates the FFT and the spectrogram are free and open source under the MIT license.

As disclosure: I am the technical project manager for SciChart

+2
source

I developed a spectrum analyzer based on open FFT. Take a look

http://som-itsolutions.blogspot.in/2012/01/fft-based-simple-spectrum-analyzer.html

You can also get the source code.

https://github.com/sommukhopadhyay/FFTBasedSpectrumAnalyzer

Hope this helps you.

+1
source

Source: https://habr.com/ru/post/951943/


All Articles