[sdiy] How I organize, was: Fast envelope follower circuit needed..

cheater cheater cheater00 at gmail.com
Sun Mar 31 11:51:04 CEST 2013

On Sun, Mar 31, 2013 at 1:06 AM, Richie Burnett
<rburnett at richieburnett.co.uk> wrote:
> it's worth downloading the PDF and keeping these tricks in your back pocket for when you need then most.
> -Richie,

Yeah, I keep all my data in a fairly structured manner.. it's become
quite a lot by now..

$ find Documents/topics/ -type f | wc -l

$ find Documents/topics/ -type d | wc -l

Mind you, every saved web page adds a directory and all its assets in
a subdir that ends with _files, so there's actually quite a few less
directories. There are also source checkouts and website spiders on
there. With those retracted you're left with this many topics of

$ find Documents/topics/ -type d | grep -v _files\\\|\.hg\\\|Think\
| wc -l


with this distribution of nesting level (after adjusting for from
where I'm running find):

$ find ........\\\|Documents\/topics\/\$ | while read line; do (grep
-o \/ <<< "$line") | wc -l | while read count; do expr "$count" - 1;
done; done | sort -n | uniq -c
     39 1
    441 2
    115 3
     50 4
     34 5
      1 6

and with this many actual files:

$ find ...... | while read line; do find "$line" -type f -maxdepth 1;
done | wc -l

In parallel, I keep a moodboard. It's mostly images (anything that
creates an emotional response), videos, and poetry. There are this
many files in it currently:
$ find Documents/creative/ -type f | wc -l

this many top-level "emotion" or "style" directories:
$ find Documents/creative/  -maxdepth 1 -type d | wc -l

and this many in total after all the bogus dirs are removed:
$ find .... | wc -l

with this distribution of nesting level:
$ find .... | while read line; do (grep -o \/ <<< "$line") | wc -l;
done | sort -n | uniq -c
     10 2
     88 3
     61 4
      3 5
      5 6

and this many files sorted according to the emotion they evoke:

$ find .... | while read line; do find "$line" -type f -maxdepth 1; done | wc -l

I also keep a mood board on youtube where i sort all sorts of
different tracks into moods/styles/emotion, each has its own (private)
playlist. I've built a small python tool that backs up the names
(because the tracks like to disappear from the cloud).

It contains this many playlists (playlist names start with ----------):
$ cat 2013-03-31\ 11\:21\:10+02\:00.log | grep
\\\-\\\-\\\-\\\-\\\-\\\-\\\-\\\- | wc -l

and, after you remove empty lines that separate playlists, and the
playlist names, you get this many songs:
$ cat 2013-03-31\ 11\:21\:10+02\:00.log | grep -v
\\\-\\\-\\\-\\\-\\\-\\\-\\\-\\\-\\\|^\$ | wc -l

most songs show up only once, many are duplicated across up to 6
playlists, one song is there 15 times:
$ cat 2013-03-31\ 11\:21\:10+02\:00.log | grep -v
\\\-\\\-\\\-\\\-\\\-\\\-\\\-\\\-\\\|^\$ | sort -n | uniq -c | cut
-c1-7 | sort -n | uniq -c
    823       1
    192       2
     87       3
     73       4
     40       5
     29       6
      5       7
      9       8
      3       9
      4      10
      4      11
      2      12
      2      13
      1      15

many moods/emotions/styles contain only one song, some contain quite a
few (the largest ones are usually collections by style rather than
emotion). I really wish Youtube allowed playlists longer than 200

$ cat 2013-03-31\ 11\:21\:10+02\:00.log | awk 'BEGIN{count = 0} /./ &&
!/----/{ count += 1; } /------/{if (count != 0) { print count }; count
= 0} END{ print count; }' | sort -n | tr '\n' ' ' | sed 's/\ /,\ /g';
1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7,
8, 8, 8, 8, 8, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 12, 12, 13, 13,
14, 14, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 19, 20, 21,
23, 24, 26, 27, 27, 30, 30, 30, 33, 34, 34, 36, 37, 39, 40, 42, 42,
42, 43, 43, 43, 43, 44, 44, 44, 45, 46, 49, 65, 71, 99, 133, 190, 191,

Hope this helps anyone who's looking to maximize their work output, be
it creative or not...

On Sun, Mar 31, 2013 at 1:06 AM, Richie Burnett
<rburnett at richieburnett.co.uk> wrote:
> 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:
>>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
>>>>> 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 :-)
>>>>Synth-diy mailing list
>>>>Synth-diy at dropmix.xs4all.nl
>>Synth-diy mailing list
>>Synth-diy at dropmix.xs4all.nl

More information about the Synth-diy mailing list