Page 1 of 1

### Using the Pi to measure Decibels

Posted: Fri Sep 21, 2012 5:34 pm
I think for my first project I want to create a decibel meter to measure noise level in my school's cafeteria. I am designing the GUI and want to have the noise level shown like a volume meter and have certain pictures shown based on the decibel level. This will be shown on a projector that all could see during lunch. I also want to keep a record of each lunch period to reward the classes that are the quietest for the week or the month.

Does this sound like a project the Raspberry pi could deliver?

I'm a relative noob and was wondering if Python could handle this or maybe even Scratch?

### Re: Using the Pi to measure Decibels

Posted: Fri Sep 21, 2012 5:45 pm
The primary problem is that the PI lacks hardware to measure a sound level, and most hardware ( a codec, or reasonably fast A/D converter) there is will simply sample a sound wave, consisting of thousands of samples a second. from that data you have to take the absolute value, and over many samples calculate the real mean square average, then convert it to decibels (a logarithmic scale). Its do-able, but the first part needs machine language, and the other parts need a fast language like C, perhaps python can do some of the calculations.

It would probably be simpler to build some dedicated hardware to sample, rectify and average the audio to a semblance of a "DC level", then use a much slower A/D converter connected to the I2C bus to take level samples.

To be honest, I think this isn't "beginners level" stuff. But maybe you will come up with a smarter solution, the GUI is the much simpler part.

### Re: Using the Pi to measure Decibels

Posted: Fri Sep 21, 2012 8:58 pm
There was an identical project attempted about three years ago with an Arduino. In the end the experimenter found no correlation between the perceived loudness and the readings taken from a microphone.
The problem is two fold:-
1) Getting the resolution to allow a good dynamic range. I would have though you would need 24 bits.
2) The filtering you have to do to get a noise power reading. That is do you go for peak, RMS or average. Do you weight high frequencies higher or lower. All this needs to match perceived noise.

As was said, it is not a beginners project.

### Re: Using the Pi to measure Decibels

Posted: Sat Sep 22, 2012 3:41 pm
I would be thinking how to do it in the analogue domain, then transfering the method into digital code.

One way is to take the output of the microphone into a variable-gain amplifier (you'll need some sort of amp since mics are generally low-level devices)
If the output of the amp is rectified and used for the gain control input of the amp, then that voltage is just what you want.

There would need to be a method to achieve a decay over time for that voltage, otherwise once a loud sound had been recieved, the gain would be minimum and nothing else would happen. Also it might be useful to have some damping in the response - a short sound should have less effect than a prolonged one.

In the professional world the (BBC-derived) PPM has very closely defined response characteristics, including its attack and decay, frequency response and 'law'. Doubtless that would be possible, but not necessary.

So you could use an ADC, fast enough to do audio so about 50kHz sample-rate.
For each sample, if the top bit is set, then it's negative so you could ignore it, or take the twos-compliment. If the next-to-top bit is set, then increment a counter, otherwise leave it be. Separately over time it can be decremented.
Then that counter can be output as a voltage to drive the amplifier gain, and we already have a PWM on board.

So now we only need some maths to control the 'law' of the system.
If we used a 32-bit counter, then we can just count the leading zeros - a logarithmic 32-step meter output! Either drive an LED bargraph, or put it into a graphic of a meter on a screen.

As for the ADC, do we really need to go further than a simple comparator, with its output connected to a GPIO input? Maybe a diode-capacitor-resistor as a sort of sample-and-hold.

### Re: Using the Pi to measure Decibels

Posted: Sat Sep 14, 2013 8:30 pm
I know it's a bit late since the last reply, but there don't appear to be any other threads which do not refer to this as a duplicate, and I'm planning on doing something similar to this.

What about some sensor like this connected to the Pi through an Arduino (as shown in the example on the page)?

### Re: Using the Pi to measure Decibels

Posted: Sat Sep 14, 2013 10:08 pm
well this module simplifies the task somewhat, as it converts the audio to the positive envelope of the signal, and the resulting signal is thus a positive voltage with a much lower frequency than audio. Still the output is linear to the loudness (envelope) of the signal, and not logarithmic, but in many cases that will do. You will still also need an external A/D converter, to sample the envelope signal, but it can be a slow sampling (few hundred samples per second), so an I2C ADC will work.

### Re: Using the Pi to measure Decibels

Posted: Sun Sep 15, 2013 3:01 pm
I would look at a true RMS to DC converter. LTC makes a chip for this - the LTC1967:http://www.linear.com/product/LTC1967. It appears to be easy to use with few additional components required. The biggest problem might be dealing with the surface mount MSOP package, but it doesn't have a exposed pad so there are probably MSOP to DIP8 converter PCBs available. You will still need to sample with a slow ADC with relatively high resolution, if you want a lot of DBs, then use the Pi for the conversion from linear to decibels.

So the signal chain would be:

### Re: Using the Pi to measure Decibels

Posted: Tue May 12, 2015 10:36 pm
As noone replied, here is my experiment:
[*]Used several Grove Loudness -> connected to analog ports ->GrovePi->Pi 2
Python script to check the loudness level is here http://www.seeedstudio.com/wiki/Grove_-_Loudness_Sensor
Used C# application to run scripts for all the sensors, ran it with mono.
Used Android Sound Meter App to check results

Result:
sensor 1:
50 db (quiet room) -> 45-250 as output.
68-70 db (music) ->130-190 as output
sensor 2: 70-90, 140-170.

Ran test with some more sensors and all got the waive like results but it didn't help much with getting the environmental sound level for me so will be checking mic's.

### Re: Using the Pi to measure Decibels

Posted: Fri Jun 21, 2019 3:24 pm
Hello. I wrote an USB driver for GM3156 sonometer. It's here: https://github.com/ciembor/gm1356.

### Re: Using the Pi to measure Decibels

Posted: Fri Aug 16, 2019 11:16 pm
You can try this python library for the Wensn 1361 Sound Pressure Level Meter:

https://github.com/mepster/wensn

### Re: Using the Pi to measure Decibels

Posted: Thu Jan 16, 2020 8:37 pm
hello,
if you found a working solution for your project please I need some help.
Thank you.