envelope follower

Status
Not open for further replies.

emmanuel63

Well-known member
Hello,

I would like to do an envelope follower. The goal is to get the envelope of an audio signal to modulate filters.

I can't figure out precisely the way to do it. Here are my idea at the moment :
- read the audio input and extract positive peaks
- averaging / filtering
- inject result to modulate a filter

I use Teensy 3.6 + audio shield.
How is it possible to make readings of the audio input ? I know about audio library objects. But how to access directly to audio samples values for your code ?

I think I need some guidance !
Emmanuel
 
Hello, how about using the Peak object to find the amplitude and using this value (multiplied by some constant) to adjust the cutoff frequency? There is a PeakMeterMono example sketch that samples the input several times a second, you could experiment with using the read() value to adjust the filter.
 
Yes, I thought using this object. I wonder if it can be fast enough to detect accurately an envelope. I will try.
 
Have you looked over this explanation of digital envelope detectors: https://www.dsprelated.com/showarticle/938.php

It seems that you just need access to the signal to do a full-wave rectification followed by an appropriate low-pass filter.

Now that I think about it, this sounds a lot like a VU meter. Is there a VU Meter object in the Teensy audio library that you could modify for fast response to better catch peaks?

Oops. I've betrayed my lack of experience with the Teensy Audio Library. It looks like the AudioEffectEnvelope object does what is needed.
 
Last edited:
I haven't used the audio library much... so hopefully I get this correct.

Envelope effect is a generator not a detector/follower.

The RMS or peak objects could be used or you can filter the audio directly after taking absolute value.

There should be an object for this as it's a standard synthesis tool.

Some soft-synth tools have a lowpass with different filter coefficients for attack and fall so the signal generated could be more responsive matching one or the other... typically faster attack and slower decay to smooth out the fall between oscillations in the wave but still capture the attack effectively.
 
Tanks for the thread, that will certainly help me.
Envelope audio effect is an ADSR envelope "shaper" and won't work as a detector.

I have some results using the peak detection object. But even with filter, it produces harshness and glitches when I try to modulate waveforms or filters.
Envelope detection seems easy to do, but getting a musical result is another story...
 
You need a VERY low cutoff as you're effectively trying to get below any fundamental so the corner frequency needs to be 50Hz or lower (and maybe much lower) and that makes the attack pretty unresponsive.

Paul suggests the state variable filter as being best for a low corner needed by this application: https://forum.pjrc.com/threads/2957...-s-Audio-library?p=94859&viewfull=1#post94859

I'd try the RMS signal and a lowpass set lower and lower until the attack becomes unresponsive and then back off a bit.

That said.. if the Audio Library is supposed to be a synthesis tool it should have a module for this.

When researching this be aware that much of the material is for demodulating AM radio signals where the signal is a modulated sinusoidal at very high frequency which means the techniques may not be appropriate for the audio task.
 
I was looking for just such a thing and found the more recent discussion in https://forum.pjrc.com/threads/6138...-are-more-similar-to-modular-synth-components, which lead to the discovery that the latest version of the Audio library includes a vocoder example by boxxofrobots, implemented in the classical method with envelope followers.

The envelope followers are created by chaining the new AudioEffectRectifier module (to move portions of the waveform that are negative to their positive mirror) and a lowpass filter (he uses here an AudioFilterBiquad, to convert to more of a DC signal).

In the example, all four stages of the biquad are configured as lowpass stages, like so:

Code:
    biquad4.setLowpass(0, 200, 0.53);
    biquad4.setLowpass(1, 200, 0.707);
    biquad4.setLowpass(2, 60, 0.53);
    biquad4.setLowpass(3, 160, 0.707);

The output of this can easily feed into AudioEffectMultiply for a VCA, or the second input of AudioFilterStateVariable for frequency control.

(I'm not clear on either why those exact frequencies, or why a biquad is the right filter for those very low corner frequencies, but that's the example. Experiment.)
 
Tanks for the thread, that will certainly help me.
Envelope audio effect is an ADSR envelope "shaper" and won't work as a detector.

I have some results using the peak detection object. But even with filter, it produces harshness and glitches when I try to modulate waveforms or filters.
Envelope detection seems easy to do, but getting a musical result is another story...

I think if you want the best results you have to bite the bullet and use a Hilbert transformer, there's only so
much you can get away with in the real domain. https://www.mathworks.com/help/signal/ug/envelope-extraction-using-the-analytic-signal.html

However that's only going to help for basically sinusoidal tones as only they have constant amplitude across the
cycle as a complex signal.

It may simply be that the modulated waveforms you have don't have a smooth envelope in the first place - in which
case the filter has to work hard to remove the discontinuities - if its cut-off is below 20Hz and its high-order it should
not be able to generate glitches, although it might be somewhat slow to track fast attacks - swings and roundabouts.

Envelope detection is not a trivial operation, its inherently non-linear(*) for a start, and often ill-specified (what should
the envelope of gaussian noise be for instance? Or of a sinusoid added to noise? Or of an asymmetric pulse waveform
of either polarity? Should it be related to the signal power (rms value) or just the peaks?)

(*) the envelope of the sum of two signals is not the sum of their envelopes...
 
The vocoder works great for what it does. The envelope followers work great with the rectifier function, and the biquad filters were chosen because they're lightweight computationally. The coefficients were chosen for performance and stability of the filter while providing great transient response. The bandpass codex filters were simply lifted off the original credited in the file; they're not 100% stable, but again they're lightweight computationally.
 
Status
Not open for further replies.
Back
Top