Question about envelope follower

Post content lost due to vandalism by author

You schematics/images aren't showing-up in my browser... If you are using a passive envelope follower (diode, capacitor, resistor) that could be a big problem!

"Line levels" aren't calibrated and they are somewhat unpredictable unless you're in a pro studio. Usually consumer outputs are a little "hot" and inputs are a little extra-sensitive so you can always get full-volume with the volume control turned-up. The output from your TV is probably different from the output from your CD/DVD player, and there are loud songs/programs and quiet songs/programs, and there is often a volume control.

A little amplification is OK but you don't want to over-do it and clip. You probably don't need the full 0-1023 range, but depending on what you are doing you may want more than 10%.

Inverting or non-inverting doesn't matter with audio (which is AC). Most op-amp circuits are designed to work from dual (plus and minus) power supplies, but the Arduino can be damaged by negative voltages so you have to be careful.

I have the following circuit to analyze the audio signal coming from my PC.

...The Envelope-Follower should work in this way

If you don't already know this - An envelope follower looses any frequency information so you can only "analyze" the volume (or maybe detect the beat, etc.).

If you need the frequency information, please tell us what you're trying to do because there are a couple of options.


I've made a few sound activated lighting effects using an [u]active envelope follower[/u] (AKA "peak detector").

You can add gain to the peak detector/envelop follower, but instead my code switches to the optional 1.1V ADC reference with lower-level signals. And on top of that, I keep a 20-second moving average to adjust the sensitivity in software (which works great in my application).

My peak detector is powered from +/-12V so I can go all the way down to zero and up to +5V (or more), and there is a protection circuit so I don't fry the Arduino (although I should never get even 5V under normal conditions).

I can't see the pics either. Can't even see the link to them that was used.

You still didn't say what kind of "analysis" you want to do so it's not clear if an envelope follower or rectification is acceptable...

The problem with your passive envelope follower is that the diodes don't conduct until you have about 0.6V across them. That means you're "loosing" 0.6V, anything less than 0.6V won't come-through at all, and you're getting non-linear readings.

Also 300 Ohms is fine for a headphone output, but a line-output is usually designed for a 10K (o more) load.

If you are willing to loose the envelope follower there are a couple of simple solutions -

The most common solution is to bias the input at 2.5V. With the bias, your ADC should read about 512 and you can subtract that out in software if you wish. Without the diode loss you should be getting about 2V peak-to-peak (almost half of the 5V range).

The standard bias schematic is at the bottom of my post [u]here[/u]. And, I'm actually doing peak detection in software if you want to borrow that part of the code. That code also has automatic sensitivity adjustment if you want to borrow that too.

If you want to mix left & right, you'd need to add those 330 Ohm resistors. (The "mix" resistors should be low relative to the voltage divider resistance to minimize signal loss.)

Or, you can use a [u]protection circuit[/u] to "kill" the negative voltage. Again, the same basic software peak detection can be used (if that's what you want). I'd increase the resistance to between 1K and 10K and you can simply use two resistors to mix left & right.

The protection circuit method has an advantage that you can use the 1.1V ADC reference for more sensitivity.

In that case, I would recommend the active envelope follower (with an op-amp). If you don't use dual power supplies, get a "rail-to-rail" op-amp.

Sampling the audio waveform and finding the peaks in software requires a "fast loop" and you need processor time for your display.

BTW I believe 20ms is already too much for audio reaction.

Maybe not. You don't want to sample "loudness" much faster than that. At 20Hz a half-cycle is 25ms and if you go any faster you're sampling the waveform instead of the "loudness". (The discharge time of you envelope follower also comes into-play.)

And on the visual side, if an LED is on for less than about 100ms it starts to appear dim (which might be OK depending on what you want). If an LED is on and it blinks-off for 100ms, you might not even notice. I think my VU meter effect steps-up at 50ms per LED (I lost my code and I don't remember) but it decays and steps-down much more slowly.

...I'm not sure if this will work in your application, but you can probably make your program run faster if you make a sin table rather than re-calculating it every time.

You'll have to decide how much resolution you need. All you need is 90 degrees and then you can invert and reverse to get the rest of the sine wave. If you can get-by with 1-degree resolution you just need a table/an array of 90 values.