Saturday 5 August 2023

Sample and Hold

 I have had a Sample and Hold for a long time...

It is, as you see above, a homemade module, built around five years ago to the design published by the late, great Ray Wilson of 'Music from Outer Space'. 

I decided - for reasons I'll explain in a moment - that I need a new Sample & Hold. 

There are a number of reasons why you might want a Sample and Hold ('S&H') in a synthesiser, of which the two most common seem to be:

    1) the generation of random sequences by sampling noise (or some other varying signal)


    2) "bitcrushing"

The generation of random sequences is a nice problem, which we'll look at first, by a practical example:

In the oscilloscope screen grab above, you see some random noise, ranging from 0 to 5V (on the channel 3 trace in magenta) and samples of that noise, captured (sampled) at a regular rate and held between these sampling points (seen on the channel 4 trace in light blue). These values constitute a random sequence.

"Bitcrushing" is an audio effect that produces distortion by reducing the resolution or bandwidth of a signal. 

The name might imply that the technique works only by reducing the resolution of amplitude quantisation (i.e. the number of bits used to represent the instantaneous amplitude of the signal). However, as the definition above confirms, the effect actually speaks of the overall bit rate, so sample rate is involved as well. A sample and hold alone can't implement resolution reduction but it certainly can demonstrate sample rate reduction, as we shall now see:

In the oscilloscope screen grabs above, you see a triangular wave, again ranging from 0 to 5V (on the channel 3 traces in magenta) and samples of that triangular wave, captured (sampled) at a regular rate and held between the sampling points (seen on the channel 4 traces in light blue). Various cases are shown, indexed by the yellow integers.

In case 1 the sample rate is so high that you can hardly see discrete 'samples'; channels 3 and 4 pretty much overlay each other.

In case 2, the individual 'samples' are just becoming visible and there is a clear step-wise sequence in channel 4.

By case 3 (where there are approximately 11 samples per period of the triangle), the steps are clearly visible, but there is enough information retained to be confident that the underlying signal is a triangular wave.

By case 4 (where there are now only around 6 samples per period of the triangular wave) the blatant step-wise nature of the signal is such that you have now insufficient information to reconstruct the triangular wave (as opposed - for example - to supposing it to be equally possible that it was a sine-wave of the same frequency). The sampling has lost the early harmonics of the triangle wave.

You could take this further, of course - right up to cases where you start to push Shannon's limit for the fundamental of the triangle wave itself.

In case 5 above, we're still not at the Nyquist rate (we still have around 3 samples per period), but there's nothing of the original signal left, except its fundamental frequency.

The Sample and Hold system certainly has bitcrushed the nice triangular signal of case 1 by the time it gets to case 5, whatever you take bitcrushing to mean!

There's another reason I like using sample and hold devices, different from the two "standard" examples above. It is to extract notes from sequences. To extract -  if you will - a sub-set from a set. 

Here's the example:

In the oscilloscope screen grab above, you see part of a pitch sequence coming from one of my sequencers, (and so ranging between 0 and 5V, seen on the channel 3 trace in magenta) and samples of that signal, captured (sampled) at a regular rate and held between these sampling points (seen on the channel 4 trace in light blue). These channel 4 values are individual 'notes' from the channel 3 pitch sequence, selected at the times the sample and hold is triggered.  In this case, channel 4 is sampling one in four of the 'notes' on channel 3.

I like to use these notes as "pedal notes" or notes for bass voices to play whilst other voices play the faster sequence (in a higher octave). It is an easy way to build harmony.

I have been using my old MFOS S&H module to do this for many years, but was irritated by two of its  "features".

Firstly, it has front panel adjustments which allow you to apply gain and offset to the sampling process. These are controlled by the two knobs closest to the array of sockets (see the photo at the head of this post). To use the device in my "pick a note out of a sequence" application, it is critical that the sample and hold has exactly unit gain and no offset. 

But every time I plugged something it, I couldn't help touch the knobs that displaced both these settings. This meant that every time I used it I had to re-set, costing time and irritation! 

Also - to be honest - my MFOS sample and hold module does suffer a little 'droop' in its hold phase, as charge on the hold capacitor leaks away over time. 

So - my plan was to address these issues in a new unit, with NO FRONT PANEL ADJUSTMENT for gain or offset, and better hold performance.

I started off with a re-spin of Ray's MFOS unit, which uses a C-MOS 4066 analog switch to switch charge onto the hold capacitor. I had a prototype of this new circuit working pretty quickly and quite well enough to "go to production", but my attention was caught by the simplicity of Moritz Klein's S&H. This design, which features both in Moritz' YouTube video and in the Erica Synths ".edu" module, uses a FET to switch charge. I felt I ought to give this approach a whirl too.

As readers already know, I am a big fan of Moritz Klein, having used his VCO core in the SubHarmonics module and identifying his important pedagogy in synth DIY. Moritz is explicit in calling out the limitations of the FET in this application, but he surprised me by saying:

“If you want to sample a tuned sequence for your VCO for example, you’d absolutely need precision,    otherwise it would sound way out of tune. But that’s a very specific and, frankly, not that practical use case, at least from my perspective.”
                (M Klein, Designing a sample and hold circuit from scratch, 16:31) 

So - Moritz thinks that my application is a very specific and not that practical use-case, which would absolutely need precision!

Hearing that, I felt it was OK to give up on the FET (which at that point I had working as well as the analog multiplexer) and look elsewhere. I needed to look no further than Eddy Bergman's site, where a recent post described a sample and hold derived from a design by Rene Schmitz. These used the LF398 device - an application-specific S&H chip.

The LF398 sounded way too expensive for somebody like me -  a cheapskate who had been messing around with CD4066s and J113s. But I took a look on our favourite auction site and found some LF398s for about £1 each. I set one up in the same breadboard I'd been using with the analog switch and the JFET and suddenly everything got a lot easier!

So - a new sample and hold module is born...

You can get all the design information on my github. And you can tell it works, because all the examples I showed above were generated by this new S&H module. 

I need never worry about knocking knobs again!

No comments:

Post a Comment