[sdiy] Fast envelope follower circuit needed..
Richie Burnett
rburnett at richieburnett.co.uk
Sun Mar 31 01:06:35 CET 2013
The Hilbert transform produces an output where every spectral component of the input is shifted by 90 degrees. (Or more practically produces two new outputs where the spectral components in one output lag the other by 90 degrees over the frequency range of interest.) You then square the value of each output, add them together and take the square-root to get the amplitude envelope. Imagine a continuous sinewave input, phase shifted by 90 degrees to give a cosine wave. If you square the sine, square the cosine, add the squares together, and square-root you get the amplitude envelope. In this case it's a smooth line of unity if the input sinewave isn't modulated.
Provided the phase shift network maintains an accurate 90 degree phase shift over the frequency range of interest, the ripple in the calculated envelope output is very small.
People on this list have previously described various clever optimisations to ease the CPU burden of the magnitude calculation by either estimating the magnitude or speeding up the square-root calculation.
If you're interested in the multi-rate FIR filter stuff do a google search for "multi-rate filter design momentum data systems". If you're into DSP programming it's worth downloading the PDF and keeping these tricks in your back pocket for when you need then most.
-Richie,
Sent from my Sony Ericsson Xperia ray
cheater cheater <cheater00 at gmail.com> wrote:
>Richie,
>
>On Thu, Mar 28, 2013 at 11:22 PM, Richie Burnett
><rburnett at richieburnett.co.uk> wrote:
>> The Hilbert transform is a classic tool for envelope extraction using DSP. Envelope following is really what electrical engineers would call AM demodulation, and has existed in various forms since the dawn of radio.
>
>That's interesting - where can I read up on how this is proven
>mathematically? I've never heard of this property of the Hilbert
>transform. Really interesting to me. And in fact, very surprising,
>since the Hilbert transform is kind of like an all-pass filter.. a
>chorus you might say. Just a bit of conceptual difference and what you
>get is completely different!
>
>> Also, FIR filters with cutoff frequencies which are very low compared to the sample rate and result in really long impulse responses (hundreds or thousands of taps) can be used effectively if implemented as polyphase filters. A 2000 tap FIR filter only requires the same amount of DSP grunt as a 20 tap filter if you can drop the sample rate of the output by a factor of 1/100.
>
>Very smart. I was sure you could do the resampling and enveloping in
>one step - but I wasn't sure if I should recommend it, because I've
>never done this in practice. Thanks for clearing that up!
>
>> cheater cheater <cheater00 at gmail.com> wrote:
>>
>>>Hi Tom,
>>>a few comments:
>>>
>>>On Thu, Mar 28, 2013 at 7:24 PM, Tom Wiltshire <tom at electricdruid.net> wrote:
>>>> Hi Dan,
>>>>
>>>> On 28 Mar 2013, at 13:55, Dan Snazelle <subjectivity at hotmail.com> wrote:
>>>>
>>>>>
>>>>> Though i work with c//arduino/AVRS not pics, this sounds very appealing! Can anyone recommend a place to learn about writing C code for an envelope follower? How do you do it? Shift signal to 0-5, then......
>>>>>
>>>>>
>>>>> Thanks!!!
>>>>
>>>> The first thing after that would be to do the full wave rectification. Either dump the sign bit, if you've got signed data, or invert the data if the highest bit is clear if it's not signed - same thing, different representation.
>>>
>>>I strongly advise against doing this. It will create insane amounts of
>>>aliasing. Do the rectification in analog. In fact full-wave
>>>rectification is the most difficult thing to do when modelling analog
>>>circuits digitally. Doing it anywhere near a level acceptable even for
>>>the non-discriminating musician would require processing power orders
>>>of magnitude larger than what a lowly pic can offer you. And in analog
>>>it's just a few junctions.
>>>
>>>BTW, you can't really rectify a signal that's unipolar already.. just
>>>a minor nitpick ;)
>>>
>>>> For the smoothing, I can imagine a couple of approaches:
>>>>
>>>> 1) Genuine honest-to-goodness digital filtering.
>>>> There's a ton of stuff about this all over the web. But since we're talking about bottom-end chips, most of it is totally out of reach. We're not going to be running long FIR filters. But we could perhaps use an IIR filter, or a FIR with a very low sample rate, to keep it manageable.
>>>
>>>You can't change the sample rate, unless you mean you would downsample
>>>the signal first. But then you'll have to have steep bandwidth
>>>limiting filters and a filter for the down-sampling itself, which
>>>means you do ten times the work you think you're saving by using lower
>>>sampling rates. If you don't downsample you get aliasing, and then
>>>you're detecting the envelope very incorrectly. It can only get you
>>>fairly small speed-ups anyways before it stops being useful at all.
>>>
>>>An FIR with a fairly short impulse is fairly easy to manage, and on
>>>something like a dspic you can do even longer ones. However IIR is the
>>>usual way to go with envelope detectors if I'm not mistaken.
>>>
>>>> 2) Peak detection.
>>>> This might be a good way to go. Keeping track of what the last couple of samples are would be easy, and would allow us to work out the current slope of the waveform. When the current sample is less than the previous one, the waveform has started heading back down, so we'd hold the peak value.
>>>> Obviously we can't hold the highest value for ever, so there needs to be some "decay" parameter that allows it to fall. Multiply by 0.99 every sample, perhaps, or remove some small constant. This is good because the algorithm can respond instantly to peaks, but will smoothly and slowly fall for decays, which naturally tend to be longer. As ever, it won't do everything well - the envelope of short percussion hits might get stretched, for example.
>>>
>>>Depending on how one would fill in the blanks, you've just described
>>>either IIR, or FIR, or a thing that results in loads of zipper noise
>>>and incorrect enveloping. IIR and FIR really are the best approaches
>>>here.
>>>
>>>> There's probably other ways, or combinations of one and the other that would work. The more specific you can be about what inputs you're trying to deal with, the better a job you'll manage to do. If you want to solve the general case, you'll need to make more compromises.
>>>
>>>Or add knobs :-)
>>>
>>>Cheers,
>>>D.
>>>_______________________________________________
>>>Synth-diy mailing list
>>>Synth-diy at dropmix.xs4all.nl
>>>http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
>_______________________________________________
>Synth-diy mailing list
>Synth-diy at dropmix.xs4all.nl
>http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
More information about the Synth-diy
mailing list