Sound spectrum analysis, adverse harmonic tones, micropython, adafruit, fft

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
Post Reply
olaf123
Posts: 1
Joined: Thu Oct 13, 2016 3:37 am

Sound spectrum analysis, adverse harmonic tones, micropython, adafruit, fft

Post by olaf123 » Thu Oct 13, 2016 7:06 am

In this Micropython project I wanted to build a cheap/small sound spectrum analyser to identify specific tones during testing. Initially I tried to connect the Adafruit sound sensor with an ADC and RPI but then faced a lot of timing problems and therefore went to the ARM-M4 micro-controller which is a pretty good straight forward solution. On git-hub I found an FFT code written in ARM assembler by Peter Hinch, which allowed me to obtain on-board frequency spectrum calculation of an array, based on the Cooley-Tukey algorithm.

http://i.stack.imgur.com/Bxllg.png
The picture below illustrates the spectrum(top) in a silent room, the middle plot shows the calculated gradients of the domain and the last the reactivity of the specific tones. The system is continuously captures 2**10 samples in 0.1s >10Hz-5kHz, calculates the FFT and forwards output array to PC in 15ms.

http://i.stack.imgur.com/KKYHR.png

The problem is found in the harmonic tones that appear at exactly 1,2,3,4,5,.. kHz (graph was taken in silent room). Second problem shows up when there is a little more noise; spikes(bottom graph) appear around the harmonic tones+/-240Hz, aliased?. The bottom plot shows the reactivity of the tones.

Tried:

No power; all frequency zero except a few low freq show minor amplitude.
Settings of the FFT for 0.5s/0.1s/0.05s/0.01s and 512/1024/2048 samples; but show the same peaks at same freq.
Three different ADC channels on the Pyboard.
Both 3V3 and GND connections.
External regulated 2-5V with shared ground (laptop no charge). (makes it worse; more noise)
What is most likely the cause of this behaviour? Board circuit / Electret-Amplifier / FFT-code / USB-power?

Alternatives?

Does someone have experience with, or has a better alternative for a cheap on-board spectrum analysis:

Me Sound sensor (LM386) amplifier.
Grove sound sensor (LM386) amplifier.
Adafruit sound sensor (MAX4466) amplifier.(http://www.kynix.com/Detail/808458/MAX4466EXK%2BT.html)

markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: Sound spectrum analysis, adverse harmonic tones, micropython, adafruit, fft

Post by markxr » Thu Oct 13, 2016 10:45 am

Not exactly, but I did something similar with a Rapsberry Pi and a cheap USB microphone.

The resulting configuration was not pretty, but it worked.

I used Python (obviously) and the Numpy FFT library. I used the "arecord" program to read sound samples from the device in the desired format and pipe it into Python as raw data, then loaded it in chunks into a numpy array.

Anyway, it was completely done with the Pi CPU, but it was fast enough to do it at the speed I wanted (I think 11khz 16-bit mono) using about 10% CPU on a Raspberry Pi 1.

Obviously most microcontrollers have a much slower processor and wouldn't be able to shift the data that fast.

User avatar
pythoncoder
Posts: 1960
Joined: Fri Jul 18, 2014 8:01 am

Re: Sound spectrum analysis, adverse harmonic tones, micropython, adafruit, fft

Post by pythoncoder » Thu Oct 13, 2016 3:27 pm

What is the vertical scale of the top graph? If it's dB where is the 0dB reference - i.e. the response to a full scale sinewave? Have you tried plotting the response with the microphone shorted out? This would eliminate the possibility that the signal is getting picked up by the mic, either acoustically or perhaps inductively.

Is there an anti-aliasing filter in the circuit? If the spikes occur at the same frequencies regardless of the sample rate I suspect the cause is other than aliasing, but there should be some filtering in the analog domain.

Spikes of broadly similar amplitude at 1kHz intervals are suggestive of an impulse function repeated at a 1KHz rate. I'd take a look with an oscilloscope - perhaps these spikes are getting coupled into the amplifier from some source. Although, if the vertical scale is dB they may be hard to see amongst the noise. Screening might help - microphone amplifiers have high gain and are prone to picking up noise.

Just a few random thoughts.
[EDIT]To add to this I suggest reading this thread http://forum.micropython.org/viewtopic. ... 771#p14771 where someone else is experiencing similar problems of signal pickup in a sensitive audio frequency cicuit.
Peter Hinch

Post Reply