Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Microphone output driving PWM LED loudness indicator

Status
Not open for further replies.

ccurtis

Well-Known Member
Okay, so I have a PWM generator driving an LED. I also have an amplified voltage from a microphone.

I know that human hearing and vision are logarithmic in response.

I want to control the perceived brightness of the LED using the PWM so that it matches the perceived loudness of the sound picked up by the microphone.

Do I need to do anything to the voltage (DC level directly proportional to microphone voltage) to make that happen, or can I control the PWM linearly from the voltage, since eyes and ears are logarithmic? If I have to condition the voltage through a function, what function and why?
 
Last edited:
Since vision and hearing are both logarithmic then a loud sound will cause a bright or burnt out LED and a faint sound will cause a dim LED.
We hear loud short durations sounds loudly but our vision needs a duration of at least 30ms to see the correct brightness. Then a peak detector with a 30ms discharge time is needed. I use an LM3915 IC in a VU meter with a 30ms peak detector and it works fine.
 
The LM3915 essentially applies a logarithmic function to the voltage applied to its input and, so, if that applied voltage is from a microphone I can only assume that the voltage output level from the microphone does not directly represent what we hear as loudness. In other words, the microphone's voltage output is not logarithmic, like our hearing is, so we need to apply a logarithmic function to that voltage to account for that.

That's good to know about the 30ms duration. Thanks, sir Guru!
 
I get to thinking about this more. There's a difference between using the LM3915 to measure VU and perceiving loudness and brightness.

The voltage output from the mic is linearly proportional to the sound pressure. We perceive that with a logarithmic response as loudness if that output from the mic was applied to a speaker (or even if we just listen to the sound hitting the mic and leave the speaker out). The eye will see that linear voltage from the mic applied to a PWM directly as light, also will perceive that light with a logarithmic response. So, then, maybe I don't have to apply any function? My head is spinning.
 
Last edited:
How many orders of sound magnitude to you need to measure?
Are you measuring a range of sounds from a distant pin drop to a jet engine (10-orders of magnitude)? Or low shippers to a scream (3 to 4 orders of magnitude).
 
Well, a typical electret microphone is followed with an amp with 40dB voltage gain and the output is 1Vp-p max, if that can answer your question. I'm not interested in sounds far below normal speech loudness (like a whisper)., or louder than the amplifier clips, which is not much louder than someone speaking very loud into the mic.

I did some experimentation and applying no function seems to be the best match compared to applying a logarithmic function to the PWM. It's all very subjective, however, and would rather understand a little more analytically what is best.
 
Last edited:
The easiest solution, if you know how to use arduino, would be to use an ESP32 module which can be programmed with the arduino IDE. It has 12-bit ADC input and can do 13-bit PWM output. You can pick the PWM frequency.

The chip runs at 240MHz so you can still run high PWM frequency and still see the full 13-bit of PWM (which could be reduced to 12-bit since the input is limited to 12-bit.

The modules are about $15 when mounted on a board with all the bells and whistles or down to about $6 with limited functionality. Most people think of these chips for their WiFi or Bluetooth capability but it is quite impressive for speed, adc and PWM.

Note that you cannot yet use the analogWrite function but the chip-specific LEDc command is used for PWM instead.

The output pins can directly drive small LEDs with up to 40 mA per pin. The pins are at 3.3V but you can power the board with 5v.
 
My LED Sound Level Indicator uses an LM3915 IC that has a total of 30dB of logarithmic steps of 3dB each which is not enough for conversations, TV and stereo in my family room so I added 20dB with an AGC circuit. Then the total of 50dB shows low sound levels and very loud sound levels but I do not have jet airplanes or motorcycles there. Years ago I added two lM3915 ICs together to make 20 steps of 3dB for a total of 60dB that resulted in a few LEDs at each end doing nothing.
 
I'm running the voltage from the mic through an ADC on a PIC18 and using one of the built in PWMs, but I'm not so much concerned here with the electrical implementation as I am about the system level design.

If my thinking is right, that I can keep it all linear, there is still the issue of the differences in the shape of curvature between the hearing and visual logarithmic responses. I realize I may be overthinking this because this is inherently a subjective process, but, hey, it can't hurt to think about and consider it.
 
So, I found something known as Steven's Power Law. The human response to stimulus is S^0.3 for loudness and S^0.5 for brightness, where S is the stimulus. That is not an insignificant difference, and which probably explains why I am not satisfied with my experimental results. Unfortunately, that also means I have to apply a exponential function to the voltage to get the two different human responses to be perceived to match. Someone can check me, but I figure that means raising the microphone voltage to the 0.8 power. 0.8 is not equal to 1. Now, I have no idea how to do that easily with a stupid 8 bit micro controller.
 
Don't forget that your eyes use the iris to adjust brightness, your hearing don't doo dat.
 
So, I found something known as Steven's Power Law. The human response to stimulus is S^0.3 for loudness and S^0.5 for brightness, where S is the stimulus. That is not an insignificant difference, and which probably explains why I am not satisfied with my experimental results. Unfortunately, that also means I have to apply a exponential function to the voltage to get the two different human responses to be perceived to match. Someone can check me, but I figure that means raising the microphone voltage to the 0.8 power. 0.8 is not equal to 1. Now, I have no idea how to do that easily with a stupid 8 bit micro controller.


That is fine but you are introducing a new variable by using PWM (only varying duty cycle) instead of adjusting the current to achieve your visual output. PWM intricacies persistence of vision time constant and decay of the time constant. At a certain brightness and frequency, it becomes difficult to differentiate duty cycle when your eye is already saturated.
 
Yeah, I guess that explains the greater dynamic range of the eyes and higher exponent. Eyes have an AGC!
 
Don't forget that your eyes use the iris to adjust brightness, your hearing don't doo dat.


Which means the background light is another variable to account for when looking for a transfer function between audio in and PWM out.
 
Which means the background light is another variable to account for when looking for a transfer function between audio in and PWM out.
True, the stuff I looked at give different exponents depending on if the eyes are dark adjusted, what the source is, and other things. Not PWM, but for flashes too.
 
My wife notices that my vision is very acute when there is a pretty young lady fairly far away. She also notice that my hearing misses many requests from her asking me to do chores. Automatic gain controls.
 
My wife notices that my vision is very acute when there is a pretty young lady fairly far away. She also notice that my hearing misses many requests from her asking me to do chores. Automatic gain controls.

On a similar note, my stomach holds very little of my sister's cooking while there is always room for more beer.
 
What I was saying is that our brains control the sensitivity of our vision and hearing.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top