envelope follower for audio metering application

ebeowulf17

Joined Aug 12, 2014
3,282
I'm trying to add microcontroller ADC-based monitoring and metering to an audio project of mine, and I'm finding this to be more difficult than I originally imagined. In this application, I need to be able to capture very fast, short transients, so I really need full audio frequency response, and I need 4 separate channels. So far, most of my microcontroller work with ADCs has been way, way too slow to sample 4 channels at >40kHz, so I was hoping to use an envelope follower so that the ADC sampling could be more like 100Hz or so. So, my basic requirements are peak (not avg or RMS) detection of full audio bandwidth, without requiring the ADC and micro to work at those high frequencies. Also, the incoming signal will be up to +/-12.5V (25V p-p,) but the ADC will be on a 3.3V supply, so the signal needs to be scaled down significantly (about 25% of original scale after rectification.)

First I tried designing my own envelope follower from scratch, just for the fun and challenge. I eventually came up with stuff that works, but it was very cumbersome, although I learned about the downside of saturation and related dependencies on slew rate in the process. Anyway, I finally searched the internet for established answers, added the filter stages I needed for response time and sample rate limits, and ended up with two circuits that basically "work." However, these circuits are so much more complex than I expected. Surely I'm doing something wrong.

Can anyone propose a circuit that does the following:
• accept 25V p-p (+/-12.5V peak) audio band signal
• full wave rectify it
• low pass filter output for slow decay, allowing low ADC sample rates
• scale output envelope to 0-3.3VDC (or a little lower - just have to not clip ADC input)
Here are the two circuits I've tried that seem like they'd work, but also seem overly complex:

Thanks in advance for any help!

Sensacell

Joined Jun 19, 2012
2,917
Looks like you have learned quite a bit, good work.
It's harder than you might think to get this right!

One thought that comes to mind is to make sure that all the diode circuits are placed inside feedback loops to null-out the ~ 0.6V drops.
This trick could reduce the non-linearities created by the diode drops.

Use smaller capacitors for the peak hold circuit to reduce the instantaneous current demand on the opamp outputs.
Use low leakage / low dielectric absorption type caps here.

Joined Mar 10, 2018
4,057
What ADC bit depth are you using ? 12, 16 bits ? Are you open to processor
choices ?

There are processors out there, SAR based, that can do 250K SPS /channel,
4 channels. For a total limit of 1 MSPS.

Regards, Dana.

Last edited:

AnalogKid

Joined Aug 1, 2013
9,494
If you scale the signal after rectification, this effectively scales the diode Vf down to 150 mV in the first circuit, which probably can be ignored. In the second circuit

TS - how much dynamic range do you need for the output signal? Is 26 dB (first circuit) or 20 dB (second circuit) enough? This would mean that any input signal more than 26 dB below the max possible would be seen by the A/D as 0 V. If you need a measurement range greater than this, then the circuit needs "active" rectification (diodes inside feedback loops).

ak

ebeowulf17

Joined Aug 12, 2014
3,282
What ADC bit depth are you using ? 12, 16 bits ? Are you open to processor
choices ?

There are processors out there, SAR based, that can do 250K SPS /channel,
4 channels. For a total limit of 1 MSPS.

Regards, Dana.
Good questions. At the moment, I'm limiting myself to microcontrollers supported by the Arduino IDE, which includes ARM Cortex M0 and M4 processors. I've also limited myself so far to either internal ADC, or external ADCs that already had libraries written for them.

Having said that, I recently did some reading and editing of the Adafruit library for the ADS1115, and it all went pretty well. I'm thinking it might be time for me to try an ADC that doesn't already have an Arduino library. It would be a good learning experience!

I've recently taken some online C courses through edX, and I'll be taking some more very soon which cover embedded systems and introduce JTAG debugging and non-arduino IDEs, so it shouldn't be too much longer before I'm ready to cut the cord and stop depending exclusively on the Arduino environment!

So, ultimately the solution may be different controller and/or ADC. Nevertheless, I'd be very interested in the analog solutions to my original question - I have a lot to learn on the analog side too, and I find this particular problem very interesting.

ebeowulf17

Joined Aug 12, 2014
3,282
@AnalogKid and @Sensacell, I tried including diodes in the feedback loops, but with limited success.

The simplest diode feedback forces the op amp into saturation on negative input signals, which then results in slow recovery and pretty horrific distortion on the next positive signal.

I tried several of the circuits proposed in this link:
https://www.site.uottawa.ca/~rhabash/ELG4135L8.pdf

The inverting half wave rectifier titled "Another Circuit" works beautifully for half wave rectification, but I couldn't figure out how to make a non-inverting equivalent for the other half wave (other than just building the same circuit again with an inverting stage in front of it.)

I also tried this circuit from the same document, but it suffers from the same saturation issues as my first attempts.

I can't seem to get a passable solution, much less a great one, without 3 or 4 op amps per channel. This is more than I expected, but perhaps this is just a more complicated problem than I gave it credit for?

As for the 20-26dB resolution, that's probably ok in this application. This will ultimately be a meter indicating how much clipping is occurring in a psuedo-tape-saturation-emulator circuit I've been playing with. I have no intention of clipping more than 20dB, so it's probably ok!

Joined Mar 10, 2018
4,057
When you get a chance PSOC offers a lot of mixed signal along with
M0, M0+(PSOC 4), M3 (PSOC 5LP) , M4 (PSOC 6) cores, one family
dual core. Attached a component list, a component an onchip resource.
And a link to user created components (users can design their own Verilog
or schematic capture components). Low end families a subset of these
resources.

https://www.cypress.com/validated-components

Just a few of the onchip resources, all routable.

IDE and Compiler free, primary boards with debug of interest from $6 to$ 10. A couple Arduino
compatible pinout. Those boards more like \$25.

Regards, Dana.

Attachments

• 178.5 KB Views: 1
Last edited:

Sensacell

Joined Jun 19, 2012
2,917
Here is a circuit intended for a ranging device, it contains an active rectifier and peak hold.
The design attempts to milk maximum dynamic range from a 5V single supply.

Slew rate problem is somewhat mitigated with additional diodes in the feedback path to keep things out of saturation.

Attachments

• 30 KB Views: 12

AnalogKid

Joined Aug 1, 2013
9,494
Any idea what the output impedance of the audio source is? If it can drive one diode (charging the filter cap) directly, your 26 dB answer reduces things to two opamps, and a single power rail.

All hail the LM358, maybe. The LM358 output is not rail-to-rail, and that might be a problem for low signal values. The circuit should work with any newer opamp with a common mode input voltage range that extends below its negative rail.

ak

Last edited:

ebeowulf17

Joined Aug 12, 2014
3,282
Any idea what the output impedance of the audio source is? If it can drive one diode (charging the filter cap) directly, your 26 dB answer reduces things to two opamps, and a single power rail.

All hail the LM358.

Here is a quick screen grab of my idea. More later.

ak
View attachment 177978
Two of the four channels should have very low output impedance, although I don't have the exact spec at the moment (group outputs from a Yamaha mixing board.) The other two are coming from a passive device I made, with at least 1k of extra impedance, so they'll need an input buffer for sure.

mlsirkis

Joined Aug 11, 2010
32
Two of the four channels should have very low output impedance, although I don't have the exact spec at the moment (group outputs from a Yamaha mixing board.) The other two are coming from a passive device I made, with at least 1k of extra impedance, so they'll need an input buffer for sure.

See LM3916 data sheet page 14
https://cdn.sparkfun.com/datasheets/Components/General IC/lm3916.pdf

AnalogKid

Joined Aug 1, 2013
9,494
You quoted an earlier version. I updated the schematic and text.

ak

Audioguru

Joined Dec 20, 2007
11,249
I have a Sound Level Indicator project with an LM3915 LED driver IC. I used a half-wave peak detector that works perfectly:

Attachments

• 12.5 KB Views: 19

AnalogKid

Joined Aug 1, 2013
9,494
I thought about replacing both diodes with NPN's in my schematic, and was going to ask about it later. I like the current gain, but at his signal levels won't the b-e junctions go into reverse avalanche? Of course he could do the 4:1 attenuation at the input and run the circuit on 5 V, but if that were not an option, then what?

ak

Sensacell

Joined Jun 19, 2012
2,917
I thought about replacing both diodes with NPN's in my schematic, and was going to ask about it later. I like the current gain, but at his signal levels won't the b-e junctions go into reverse avalanche? Of course he could do the 4:1 attenuation at the input and run the circuit on 5 V, but if that were not an option, then what?

ak
That's why diodes are the simpler option here, 1N4184 are good to 100V.

ebeowulf17

Joined Aug 12, 2014
3,282
Sorry I've been slow to respond today. I'm simulating the new suggestions as fast as I can. I really appreciate the collective wisdom here.

The simulation results are interesting, I didn't realize that even just audio frequencies are a little challenging with higher voltage swings - had to choose different op amps with better slew rate, and still had to reduce filter cap size in order to deal with my worst case scenario, 20kHz 12.5V half cycle. I'm learning a lot in the process.

So far I'm leaning towards @AnalogKid's suggestion, albeit with a buffer at the input since two of my sources will have high output impedance. Had to reduce the cap and increase the voltage divider resistances in order to handle my worst case transient, but seems to do the job, cleaner and simpler than my previous attempts.

I'll work through other options as soon as I can and report back. Thanks for all the help!

Audioguru

Joined Dec 20, 2007
11,249
My circuit uses a transistor instead of a diode so that the peak charging capacitor can charge quickly with a high current. For your higher supply voltage a diode will withstand the higher voltage when the capacitor is charged and the diode goes into reverse bias. Then the capacitor value must be less so that it can charge quickly and its discharge resistor value must be higher and the circuit it feeds must have a very high input resistance.
An LM358 is no good for high audio frequencies since it has a slow slew rate.