Let's Design and Build a (mostly) Digital Theremin!

Posted: 6/11/2018 11:31:35 PM

From: Northern NJ, USA

Joined: 2/17/2012

Anti-Aliasing ~= 1/x

It's fascinating reading recent papers on anti-aliasing oscillators.  Some of the best ones are written (or co-written) by Vesa Valimakai, and Jussi Pekonen shows up in many of the best as well.  Both sharp persons who write very clear papers and slides on the subject.

Unfortunately, it seems division, or reciprocal, shows up just about everywhere, regardless of method.  BLIT & BLEP rely on fractional delay filtering, and this requires the magnification of the error to fit the sampling period (1/F).  FIR & IIR comb filtering the aliasing away also require fractional delay.  DPW requires 1/F scaling to compensate for the differential gain.

Posted: 6/14/2018 3:02:42 PM

From: Northern NJ, USA

Joined: 2/17/2012


This has been a test of the TW twit filter.  All of my posts for the past month or so have been blocked and flagged for moderation.  Jason fixed it.

Free at last!

Posted: 6/14/2018 4:58:27 PM

From: Northern NJ, USA

Joined: 2/17/2012

TANH Soft-Clipping

Found this quite fantastic paper: "New Perspectives on Distortion Synthesis for Virtual Analog Oscillators" by Victor Lazzarini and Joseph Timoney, published in Computer Music Journal, 34:1, pp. 28–40, Spring 2010.  One approach detailed in it soft-clips a sine wave via the tanh (hyperbolic tangent) function, which gives odd harmonics with two different roll-offs, the usual 1/f up to a point, then 1/(f^2) above that.  If you control the amplitude of the sine wave going into the clipper you can place this transition point around 10kHz, the effect of which is inaudible, and which nicely limits aliasing due to the 1/(f^2) roll-off up to Nyquist.  This gives odd harmonics - for all harmonics they mix the result with a cosine, which accentuates the second harmonic a bit.  By controlling the cosine mix they can conveniently control the odd / all harmonics ratio.

Difficulties with this approach are:
1. You need a high quality tanh function, which is difficult to do.
2. The sine gain function is 12000/(x * log(x)), which is difficult to do.
3. Reducing the sine gain below 1 to lower the harmonic content will significantly lower the output amplitude.
4. Reducing the sine gain below 1 to lower the harmonic content gives poor results when the output is mixed with cosine.

tanh(x) = (e^2x - 1) / (e^2x + 1) = (1 - e^-2x) / (1 + e^-2x)

This would take one exponentiation and one division, probably float, both of which are expensive.

Looked for papers on calculating tanh, none provided simpler solutions.  Tried polynomial fitting, which doesn't directly work well at all.  For 16 bit precision the input can be clipped to +/-6, for 32 bits +/-12, which reduces the solution space somewhat.  One approach I discovered via spreadsheet is to divide the input by a small constant, subtract it from 1, raise it to an integer power, then subtract this from 1.  Unfortunately this isn't accurate enough to avoid alias products.

Anyway, this has given me a new appreciation for "knee" type harmonic roll-off.  And I wonder if noise mixing pre-clipping would approximate the onset of vocalization better?  Something to try.  It wouldn't have occurred to me to attempt vocal dynamics via clipping, as the physics seem quite different.  And I'm not sure I want harmonic content so closely tied to amplitude, though it often is in nature.

Posted: 6/20/2018 7:25:45 PM

From: Northern NJ, USA

Joined: 2/17/2012

Aliasing Effectively Vanquished! (way back in 1978 : US4249447)

I don't know why I keep thinking I can add anything fundamentally new to the research that's already been done regarding waveform generation.  People who had almost nothing in the way of processing horsepower wracked their brains and long ago mined out all of the simplest and most efficient and direct discoveries.  Spent a couple of weeks looking into soft clipping, tried many things, sadly with nothing of interest to report.  On Monday I was casting about listlessly on the old music DSP website (link) and encountered some code describing an old patented oscillator.  Found the patent and simulated three different forms detailed there (link).  Coded it up and have it running on the prototype.  WOW!  Pretty much exactly what I was looking for, a quasi band-limited version of my power-based phase modulation glottal generator.  Here is a diagram of what I've got running:

The phase increment value ("frequency") comes in at the upper left and gets routed two ways.  The lower way is fed to a second order polynomial, which gives us smaller numbers for smaller phase increments.  The upper way is scaled to give C8 maximum and accumulated in the normal NCO fashion.  The accumulated phase forms a sawtooth, which is optionally modulo multiplied by 2 to double the frequency, and fed to two summing nodes, which in turn feed sine wave functions.  The lower sine wave is averaged for stability reasons (and to give a zero at Nyquist, or 24kHz), combined with a fraction (beta) of the polynomial result, and fed back to the phase inputs of the sine functions.

Beta controls the harmonic content, with 0 giving a pure sine wave, and 1 giving a 1/f harmonic roll-off (~sawtooth equivalent of 6dB / octave) and numbers in-between giving steeper slopes (we want ~12dB / octave nominal for vocal stuff).  If we do the frequency multiplication for the lower sine generator we get odd harmonics at the output (~square wave) with similarly variable harmonic content.  If you don't want just odd harmonics you can use a single sine function.  The above consumes 62 cycles max. on my Hive processor.

The beauty part though is the spectra have the secondary steeper "knee" heading into Nyquist, which really tames aliasing.  Here are some results from simulation which make that evident:

When beta = 1 there is a bit of ringing and rounding, but otherwise the waveform looks like a sawtooth.  The spectra shows a secondary steeper roll-off above 10kHz which massively controls aliasing fold-back.

Using the output sinewave itself as a feedback phase modifier is super simple and quite ingenious!  I've been avoiding all of these FM type solutions figuring they produced inferior spectra, were difficult to control, etc. but it doesn't really get much better or easier than this, particularly if you're looking for continuously variable harmonic content.

Is the knee audible?  When beta is dialed back I would say yes to some small degree as muffledness, though the knee ends up being many tens of dB below the fundamental, which masks it a lot.  At very low frequencies there is a bit of digital "burbling" going on, but it's pretty low level, and it seems all methods do this somewhat.  It's more noticeable when pitch correction / quantization is applied.

[EDIT] Here's a sample of the new oscillator in the prototype: (link).  Other than the marked lack of aliasing, and a more linear dynamic curve to the harmonic modulation input, I honestly can't tell any difference between it and the old oscillator.  My ears are kinda old, let me know if you hear any aliasing, the polynomial can be easily adjusted to fix various frequency bands.

The last main brick in the DSP wall!  (Leave those kids alone...)

You must be logged in to post a reply. Please log in or register for a new account.