Audio Envelope Follower for Arduino

Berzerker

Joined Jul 29, 2018
621
I for one think it's great djs. Seems the more I read here the more screwed up I get. What I wouldn't give to be able to do/think of the things that come from your minds. Not saying I don't have the vision but the know how to implement it. Been thinking about one of those Arduino starter packs and learning some code myself..... Also found out it was not pronounced Ar-do-ee-no it's Ar-dween-o, so I did learn something! Anyway I thought I would let you know "Good job" and I'll keep an eye on this thread for updates.
Brzrkr
 

Thread Starter

djsfantasi

Joined Apr 11, 2010
7,913
When the audio is clipping then many amplitude fluctuations will be missing and your robot's mouth will appear to be frozen.
Your simple passive envelope detector's voltage loss also covers up minor amplitude fluctuations that would be fixed by using an ACTIVE envelope detector (the diode's voltage loss is cancelled because the diode is inside the negative feedback loop of the opamp).
Missed this earlier. The software divides the output of this circuit into 4 windows of about 1V range (I.e., 0-1V, 1-2V, 2-3V, and 3-4V).

So many of these points are irrelevant within the application. When the animatronic speaks (or you speak for example) the mouth opens depending on the general amplitude, not any specific amplitude.

I could have just processed the line output, but the voltage ranges are more difficult to set properly. By amplifying the signal, it’s much easier to define the ranges.

My last problem is confirming that the new input circuitry (the serial 0.1μF cap and the Schottky diode and 20Ω resistor to ground), will not damage the VS1053 codec chip output.

E936D8EC-3507-45A0-AB44-D4624AD568EE.jpeg
 
Last edited:

Audioguru

Joined Dec 20, 2007
11,249
The input bias current of the opamp causes its (+) input to float up as high as it can go, causing the output of the opamp to be clamped as high as it can go.The Schottky diode isolates the opamp (+) input from the 20 ohms resistor (the schematic does not show Megohms). Your 20M resistor value is much too high to bias the opamp input anyway.
 

Audioguru

Joined Dec 20, 2007
11,249
The Schottky diode is preventing the opamp (+) input to be biased at any voltage since the input bias current of the input pulls it positively.
Why is the diode there?
Why do you use such a low value of 20 ohms?
The 0.1uf capacitor feeding 20 ohms forms a highpass filter that cuts frequencies below 80kHz (all audio frequencies are cut and frequencies are reduced at -6dB per octave).
 

Thread Starter

djsfantasi

Joined Apr 11, 2010
7,913
The Schottky diode is preventing the opamp (+) input to be biased at any voltage since the input bias current of the input pulls it positively.
Why is the diode there?
Why do you use such a low value of 20 ohms?
The 0.1uf capacitor feeding 20 ohms forms a highpass filter that cuts frequencies below 80kHz (all audio frequencies are cut and frequencies are reduced at -6dB per octave).
I put the diode there as a half wave rectifier to prevent negative voltages reaching the op amp + input. My earlier circuit didn’t have this diode and appeared to work fine, but I received many comments that configuration would damage the op amp.

I used 20Ω to reduce the lag between the original audio signal and the processed envelope signal.

The circuit input is all audio. So the bandpass filter is a concern. Except that with the diode in series with the resistor, the filter will not be in effect on the positive side of the signal, n’est pas?

To be honest, I used another circuit as a model, for both versions of this circuit. I’m not confident why the 0.1μf is there. I assumed it was to remove any DC bias from the codec.
 

Audioguru

Joined Dec 20, 2007
11,249
Your diode does not rectify the input signal. Its polarity allows the opamp (+) input to float high without any bias reference voltage causing the opamp output to go as high as it canl.

A rectifier is a series diode feeding a resistor to ground parallel with the opamp input, or is a series resistor feeding a diode to ground parallel to the opamp input.

If the signal source can drive 20 ohms then your input coupling capacitor charges quickly when the input signal goes negative.
When the input signal goes positive then the charge on the capacitor is added and drives the opamp input much higher than the supply voltage, damaging it.

You need an active envelope detector circuit instead.
 

Thread Starter

djsfantasi

Joined Apr 11, 2010
7,913
I trust and appreciate your input. But I don’t understand it in the context of the simulation results in post #2.

I’m also confused that I’ve been told many times that the predecessor circuit will damage the op amp, but it’s been working for ten years and is based on a popular circuit in wide use.

While I believe it had flaws, I am getting the feeling that none of us using this circuit should be working.

With regard to the LTSpice simulation...

It shows that the + input only goes negative by the diode voltage drop (acceptable as an input to the TL1013). Also, the highest voltage peak is far below the supply voltage.

Can you explain to me why this is the case? I really don’t want to be stubborn. I really want to understand.
 

Audioguru

Joined Dec 20, 2007
11,249
A simulation is not real. Things like the input bias current is missing and it is extremely important and causes your simple circuit to fail at working properly.

Also the simulation shows but does not know if your signal source goes negative below ground.

Your schematic in post #2 correctly shows the envelope detector opamp with an input resistor to ground but the feedback resistors are connected before the diode causing the detector to have a diode voltage drop because it is not "active".
 

Thread Starter

djsfantasi

Joined Apr 11, 2010
7,913
So, here's a sneak preview... I decided to start over from scratch. The circuit I had modified had one op amp amplifying and detecting the envelope. As I tried to improve it, bettering one function came at the expense of the other. Since the DIP-8 LT1013 has two op amps in the package, I used one as an envelope detector. Then, the second op amp was used as an amplifier to boost the audio signal to as close to the Vcc rail as the op amp would allow.

Audioguru provided the important piece of information that I had missed. The audio signal from the Arduino Music Maker MP3 shield was NOT w.r.t. circuit ground, but to an analog ground created within the shield circuitry. All of the concerns about feeding a negative voltage, from here and StackExchange, weren’t valid! In fact, since that was the major reason for the redesign, I could stop! The need was not real, due to my misunderstanding.

But of course, I had to keep on going.

Audioguru provided an envelope detector circuit, which actually I had seen and used before. But his contribution contained some suggested components values.

I used that circuit, but wasn’t satisfied with the waveform when C2 was 0.1uf and R4 was 100k, audioguru’s suggested values. I modified their values to those I had determined experimentally, as described below.

This is my latest schematic
AAEF_New_Schematic.JPG

And here are the plots of the various test points from the simulation of this circuit
AAEF_New.JPG

I also ran the simulation with the capacitor/resistor on the envelope detector with values of 0.1uf and 100K ohms. I combined the Vout plots on one graph to show what I meant when I said I wasn't satisfied with the waveform resultant from that combination. The two different sets of values being compared in the plots below result from my component values versus the component values suggested by Audioguru.
AAEF_New_compare 2.2-0.1.jpg

You can see there is a large difference in the output...

I’m soliciting comments from the membership at large. Thanks.
 
Last edited:

Thread Starter

djsfantasi

Joined Apr 11, 2010
7,913
Anyone else cannot see the images?

I can see them fine. And I’ve edited the post so I can see the actual link, in case they were linked off-site and somehow blocked. But they are all hosted on AAC.

Wendy and I are looking into this via PM. But y’alls input may be useful.
 

JohnInTX

Joined Jun 26, 2012
4,596
Can't see them. Extracting the links and clicking on them returns 'not authorized to view this page'.
Try editing your post, deleting and using UPLOAD FILE again?
Sorry you're having trouble. Frustrating.
 

Thread Starter

djsfantasi

Joined Apr 11, 2010
7,913
Can't see them. Extracting the links and clicking on them returns 'not authorized to view this page'.
Try editing your post, deleting and using UPLOAD FILE again?
Sorry you're having trouble. Frustrating.
Thanks for the feedback and the error message. I have an idea as to what’s happening. I’ve edited the post and re-uploaded the images,

Can you see me now?
 

Thread Starter

djsfantasi

Joined Apr 11, 2010
7,913
The issue I believe was that the content was copied from a PM and carried security settings associated with a PM.
 
Last edited:

Thread Starter

djsfantasi

Joined Apr 11, 2010
7,913
Back to my thread. I’ve been doing a lot of reading and following recent posts that are looking to solve a similar problem.

As part of my efforts, I’ve been simulating many of the proposed circuits. What this has resulted in has been a better understanding of my goal. There are three functions of my desired circuit. I desire to use single supply rail to rail op amps. I have been working with LT1013 op amps and investigating the use of TLV2462 op amps. The three functions are:
  1. Processing an audio signal such that it’s negative component when input to an op amp, does not harm it.
  2. Implement an envelope detector or follower.
  3. Amplify the signal so that it’s full range of the op amp used.
Ive simulated circuits that do 2 before 3 and 3 before 2

The problem I am facing is how to implement these three functions with as few op amps as possible. Three is the obvious number, but can I do it with two?

The problem confounding me, with my attempts as well as the proposed circuits, is that the op amps are configured differently in the circuits and seemingly cannot be combined. My latest attempt did not come close to what I wanted and caused me to close LTSpice for the first time in several days.

Processing an audio signal for an arduino
7CB77D58-C1EC-45A9-A51F-6605DBCF272A.jpeg Or
2E2745C0-3267-4627-93B2-7DD7D7D34AB7.jpeg
Envelope detector
E0A0306F-A8A9-4DDB-ABFA-C51DBB11EFE2.png
Signal amplification
D6F08E39-9CB8-43ED-9A1A-CBADF6BE8B28.jpeg

How should I approach combining these three functions?
 
Top