Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Simple envelope detector

Status
Not open for further replies.

gonadgranny

Member level 4
Joined
Feb 23, 2011
Messages
68
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,930
Hello folks.
I have an audio signal which has its mid voltage at 2.5v and oscillates through to 5 and 0v. I would like to sample this signal on an Arduino and use PWM on an led to react to it. I made a piece of software a while back and it worked but I had to set the sample rate at a very high frequency so that I could “catch” the voltage fluctuations.
I read that one can make an envelope detector which would make it unnecessary for me to set the sample rate so high so I can reduce cpu time on the Arduino.
With the setup I described would anyone be kind enough to suggest a circuit which I could use? Its mainly the capacitor and resistor size which I am unsure about as I have only a rudimentary knowledge of electronics.
Many thanks,
Danny.
 

Can you elaborate a bit on what you're trying to do?

For example, what frequency range - the full audio spectrum?
What exactly do you mean by having the LED react to it? Is it to indicate the strength (amplitude) of the audio signal by modulating the brightness of the LED?

Envelope detectors come in different levels of sophistication. If you can post the circuit you read about, it will be easier for others to help you with the component values.
 

Can you elaborate a bit on what you're trying to do?

For example, what frequency range - the full audio spectrum?
What exactly do you mean by having the LED react to it? Is it to indicate the strength (amplitude) of the audio signal by modulating the brightness of the LED?

Envelope detectors come in different levels of sophistication. If you can post the circuit you read about, it will be easier for others to help you with the component values.

Yes the full audio spectrum within hearing range.
The audio will be a voice and the led will act as a means of giving some visual feedback to the audio (I'm making a talking character).
The amplitude is not too much of a problem as I think I want the led at full intensity at the beginning of the spoken words. I will then implement a fade down function when there is no longer a signal.
The one I saw was the one on this website
I tried it with a 0.22 uF capacitor and a bunch of resistors and noticed very little difference in the waveform on my (very primitive) oscilloscope.
I then tried it with a 220 uF capacitor and it massively "smoothed out" the signal, that was without a resistor too so I'm not sure whats happening there.
These capacitors have a polarity. Is this advised? The diagram on the website suggests no polarity, I dont have any of those lying around at the moment however.
Hope that clears things up a bit...?Thanks.
 

The circuit in the link has one major difference from your intended application: It's for filtering out a very narrow range of frequencies. I started out typing an explanation of the principles involved, but it quickly became unwieldy. So I've abandoned that for the moment.

Basically the time constant of the filter R*C has to be much larger than 1/f of the lowest audio frequency of interest. For speech, this will be higher than 100 Hz and 1/f will be lower than 10 milliseconds (msec). On the other hand, the time constant has to be shorter than the fastest change in amplitude which may be up to several times a second. So a time constant of roughly 100 msec or so may be a good starting point.

I suggest you start with a 1uF capacitor and a 100k resistor, or a 10uF cap and a 10k resistor. If the capacitor is polarized, the + side should be at the upper side in the circuit.
 

Hi,

I assume this is no very sophisticated application....
Therefore... just lower your sample rate .....then rectify the signal and do the average...
There is a good chance that it gives about the same result as a true envelope detector.

Klaus
 

Thanks very much for this folks.
I'm going to jump to KlausST due to it being more within my current scope of understanding, I hope that does not appear rude Pjdd....
It is not a sophisticated application indeed, it is purely aesthetic...
Therefore... just lower your sample rate .....then rectify the signal and do the average...
The rectifying "smoothes out" the signal, stopping it from dropping so fast and allows me to sample at a lower rate. I think...What would this "averaging" accomplish?
Thanks
 

You have to distinguish between samples taken quickly but at long intervals and samples accumulated over a long period. The first gives an instantaneous values and you then have to average them mathematically, the second tends to even out the readings even if they change during the conversion cycle. There is a catch with slow ADC conversion though, most MCUs use a sample and hold circuit which freezes the voltage no matter how slowly you covert it to digital and even if you can avoid that, they tend to use successive approximation techniques which give more weighting to the earlier part of the measurement and less toward the end.

It really depends on the exact frequency range you want to sample and how rapidly you want the measurement to reflect changes in the amplitude. You need a better specification to get better advice. From your original post it seems the optimum solution is probably a comparator and shunt attenuator which is easiest implemented using analog circuits.

Brian.
 

I'm going to jump to KlausST due to it being more within my current scope of understanding, I hope that does not appear rude Pjdd....
Not at all. Go with whatever you feel comfortable with.

When I try to help others in electronics within the limits of my own knowledge and experience, I try to make them understand the principles too. To do that, there's often a limit to how much the explanation can be simplified.

Have fun and good luck with your project.
 

Hi,

rectifying:
An audio signal consits of positive and negative voltages. A rectifier just makes the negative voltages positive. So you only have positive signals.

averaging:
Calculates the mean of a signal over time. It could be a low pass filter... maybe with 10Hz or so. Whatever is useful for your application.

Klaus
 

Im not quite sure why the average needs to be calculated; My aim was to adjust the PWM output on the fly depending on whether the ADC sample registered as above a base level or not(2.5v). In terms of rectification, the signal is already only positive. it is 0-5v with 2.5 being the base level. there is a name for this type of amplifier but I have forgotten it. My original thought was to use the envelope detector circuit to "smooth out" the oscillation so that so long as there is "sound", I will get a reading above the base level rather than rapid oscillations above and below the base level . In terms of the frequency range, as long as i can register the frequencies within the spectrum of a mans voice then im golden. Im not sure if that has made myself any clearer?
Thanks again though folks.
Danny
 

It's a bit clearer. You have an AC signal (the voice waveform) which you are sitting on a 2.5V DC level so is 'mid way' on the ADC range and it's peaks do not exceed 5V or 0V. The technical term is 'level shifted'. What isn't clear yet is what the PWM does. You can use PWM to control the brightness of your LED but the relationship between PWM ratio and the signal level is not explained. From what you describe, a comparator and monostable would do the job, just detecting waveform above a threshold and using it it to time how long an LED lights up.

If you want to track the envelope of the audio, in other words extract the volume level without the individual waveform cycles, you need to determine a filter characteristic that minimizes the envelope ripple at lowest speech frequencies (say 100Hz) but is still fast enough to reach to sudden volume changes. You need a low pass filter with a cut-off of say 10Hz, that can be done by sampling the ADC and averaging or by electronic means. The puzzle if you want to do it with a simple RC network is why you start with the 2.5V offset. It makes more sense to remove the DC offset and rectify the AC component of the waveform as it uses a simpler circuit and makes the filtering simple.

If you really want to keep the 2.5V offset and use the ADC you need fast sampling (> ~5KHz) so the individual cycles are measured, then accumulate and average the absolute differences from 2.5V over a period of about 0.1 seconds.

Brian.
 

Hi,

I agree with Brian..

If you don't use an average filter, then you rely on a single ADConversion value. This is not good, because any transient spike, noise and so on ... will be taken with 100% into account. The PWM value will be quite unstable.

A good averaging filter attenuates noise and emphases audio signal, the PWM signal becomes more stable.

*******
"Zero" is when there is no audio signal, absolute silence, and no noise...in your case it is about 2.5V at the ADC input..about 512 as digital value of a 10 bit ADC.
With an audio signal .. the signal will become higher than 512 and lower than 512.
(You have to determine what exact "zero" level you have. But I'm calculating with 512..)
So 532 (512 +20) will represent the same loudness like 492 (512 -20).

Here is where the rectifier comes into play. There are several ways to do this.
I'd first subtract the 512 and get a signed result.
532 becomes 20
492 becomes -20

Then I'd rectify the result. In other words calculate the absolute value
20 stays 20
-20 becomes 20

Then do the averaging on these values to get the "envelope"

*****
With optimal noise free silence you gaet a value of 0
Realistic silence level..I expect about 3...5
The louder the audio signal, the higher the value.
An unclipped sine wave will give about "325" as max envelope value. (From 10 bit ADC values)
Even a clipped audio signal will never reach 512.
I expect an about linear range with values 0...256 (because audio isn't pure sine waveform)

Klaus
 

I see how you are digitally rectifying using the microcontroller but this would require a high sample rate which i dont want to use. my thought were that by using a half bridge rectifier one could get a very crude approximation of when there is an isnt sound by charging up a capacitor when the signal reaches its highest(relative to base level) and allowing that voltage to "bleed" through a resistor meaning that it circumvents the swing back through 2.5 and to wherever the amplitude sits on the other side of 2.5v. we seem to have moved back into the territory of taking many samples and calculating the envelope mathematically. i have drawn an image of how i understand the concept of an RC circuit. Im not sure if it is correct but it if is it hopefully illustrates how i really only need a circuit which will keep the voltage reading as above baseline for as long as there is sound playing.
Thanks again for these detailed explanations. they are much appreciated although they are causing the vein on my head to begin pulsating :)


IMG_0055.jpg
 

The waveform illustrates the behavior of an envelope detector as linked in post #3. Time constant may be varied, there's also the option to use a negative resistor bias for constant discharge rate instead of exponential discharge with grounded resistor.
 

Hi,

I see how you are digitally rectifying using the microcontroller but this would require a high sample rate
No.
Not for a low performance envelope detector.

Rectifying has nothing to do with sample rate.

Klaus
 

I'm still puzzled by the 2.5V level shift. If you just rectify and filter the audio you get a value of zero with no input and a progressively increasing positive voltage as the volume increases. Basically, you are replicating an AC voltmeter - so why is the the offset needed?

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top