[sdiy] Digital accumulator VCO core?

Richie Burnett rburnett at richieburnett.co.uk
Mon Feb 15 20:13:15 CET 2021

> Am I right to think that this is an approximation? This looks like the
linear component of some larger formula than that. What are the next
terms? What is the general formula?

The polynomial is exact for the case I showed.  You can calculate the 
equations for the two curved segments, or just look them up in the examples 
of polyBLEP code on the web.  The approximation comes about because a boxcar 
low-pass filter isn't a very good filter.  It is certainly a far stretch 
from what one would call a textbook "brick wall" filter with it's flat 
pass-band, razor-sharp transition-band, and deep stop-band.

Ideally we would use an infinite sinc function as our band-limited impulse, 
and we would integrate this to give a band-limited step.  This would give 
perfect band-limiting right at the Nyquist frequency with no approximations. 
The downside is that we would need to correct and infinite number of samples 
before and after each discontinuity in the sawtooth waveform to achieve 
perfection!  Relaxing our quest for perfection by allowing some 
approximations makes the process realisable.

> It's possible to use any filter you want, and pass the impulse through it
> more times.  The math just gets harder!  And the polynomials for the
> corrections to apply to each sample become longer.  But you can see that 
> the
> example I gave results in simple quadratic functions to modify one sample
> either side of the step discontinuity.

> Am I right to think that if you pass this through a high pass filter
> multiple times, you will recover the aliases?

With polyBLEP using a simple low-order polynomial there are still clearly 
visible aliases at the top end of the audio spectrum.  Even with x2 
oversampling there are still components up between 10kHz to 20kHz that 
aren't more than about 60dB down.  But, perceptually polyBLEP sounds waaaaay 
better than doing nothing at all and just outputting a naive sawtooth 
directly from the NCO accumulator.  Our ears are way more tolerant of a few 
rogue partials up near the limits of human hearing than they are of a single 
harmonic that happens to alias to a frequency below the fundamental of the 
tone we're generating.  An aliased component coming below the fundamental 
pitch of the sawtooth confuses your brain because it expects the lowest 
frequency partial to be the fundamental of the tone.

> In digital a synthesizer
> with multiple high pass filters, do we need to do "a better job" of
> band limiting this?

Maybe.  If you follow the oscillator with a filter capable of doing a lot of 
boosting in a particular region, then you might have to tighten the spec on 
the anti-aliasing in order to ensure that the user can't boost a "just 
inaudible" alias back up to something that is perceptually annoying.  I'm 
not sure about the high-pass filter example you gave, but progressively 
closing a conventional "low-pass filter with resonance" is really good at 
showing up aliases that fall below the fundamental of a high-pitched 
oscillator waveform.  Once the cutoff frequency of a lowpass filter has 
dropped significantly below the fundamental of say a 4kHz "C" note, you 
shouldn't hear very much at all.  But if there's a lot of resonance dialled 
in, it will boost any spectral components that have aliased to low 
frequencies and make them stand out like a sore thumb!

> I understand in an analog synthesizer, after
> you're done outputting this to analog audio, any aliases might be lost
> in the noise, but I'm not convinced that they will be _unrecoverable_.

With polyBLEP you really don't have to look hard to see remaining aliases. 
They're right there in plain sight at the top end of a spectrogram, they 
just don't sound particularly annoying.  However, with a good BLEP 
implementation they should be down in the noise floor.  So they shouldn't be 
"recoverable".  However, subsequent non-linear processing in the digital 
domain like deliberate distortion can easily cause aliasing to re-appear. 
But that's a different issue.

> On a separate note, has anyone come across something that's like a
> spectral "gate"? like a normal time-domain noise gate, but for each
> frequency separately: i.e. a frequency will pass through only if it's
> above a certain threshold.

I believe such things are used for noise reduction, but I don't know.



On Mon, Feb 15, 2021 at 1:11 PM Richie Burnett
<rburnett at richieburnett.co.uk> wrote:
> > If you do a polyblep you correct the sample just before and just after 
> > the
> > transition to "blend" the fractional-sample-position step into whole
> > samples, but I don't get what the curve is supposed to be or how you
> > design it.
> Ok, here goes...  (See attached JPG image.)
> 1. Start with a raw impulse (A).
> 2. Pass this through a boxcar FIR filter to get a band-limited impulse 
> (B).
> 3. Pass this through the same boxcar filter again to get an even more
> band-limited impulse (C).
> 4. Now integrate this band-limited impulse to get a band-limited step (D).
> 5. Finally subtract a naive step from the band-limited step to get (E).
> (E) is the correction that you apply around each step in the waveform 
> you're
> generating.  You pick your points from the two regions between the green
> lines depending on the fractional-sample offset of the reset instant in 
> the
> saw waveform.  These are the modifications to apply to the naive sawtooth
> waveform samples just before and just after the discontinuity.  (Both 
> curve
> sections are fundamentally x^2 in shape.  But one segment is inverted and
> reversed. You can see that they come from integrating the triangle 
> waveform
> C).
> So why did we do this?
> The naive sawtooth waveform has an instantaneous reset, that happens
> somewhere between samples.  It is a pure step shape and is what we would
> have got if we had just integrated the raw impulse (A).  This aliases
> horrendously because the impulse (A) has an infinite spectrum, and so does
> it's integral, the pure step.  So a naive sawtooth waveform aliases 
> because
> it's step discontinuity isn't band-limited at all.  All of it's harmonics
> above the Nyquist frequency folder over and over into the audio band.
> Now if we band-limit the impulse a bit before we integrate it to form a
> step, it will alias less.  A boxcar filter is a pretty crude low-pass 
> filter
> (it has pass-band droop, a sloppy transition band, and ripples in the
> stop-band), but it has one thing going for it...  It is mathematically 
> dead
> simple!  We could have stopped after low-pass filtering the impulse once 
> to
> get (B), then integrated that to get a band-limited step.  What you'd get
> would have been a linear ramp instead of an instantaneous step.  This is
> better than doing nothing, and equates to modifying one sample at each
> discontinuity.  However, one pass through a boxcar IIR filter isn't a 
> great
> lowpass filter, and we can easily do better than that.
> So instead, we low-pass filter the impulse by shoving it through the 
> boxcar
> low-pass filter a couple of times, then integrate it to get a nice smooth
> band-limited step (D.)
> It's possible to use any filter you want, and pass the impulse through it
> more times.  The math just gets harder!  And the polynomials for the
> corrections to apply to each sample become longer.  But you can see that 
> the
> example I gave results in simple quadratic functions to modify one sample
> either side of the step discontinuity.
> It's interesting to note that if we had used just one boxcar filtering 
> step,
> then integrated to get a ramp transition rather than a step, this isn't 
> too
> far away from how a real analogue sawtooth oscillator resets by 
> discharging
> it's integrator capacitor over a finite time period.  However, this 
> doesn't
> give much band-limiting to guard against aliasing.  Although there is now 
> no
> step discontinuity (it ramps linearly) at the reset instant, there is 
> still
> a discontinuity in the gradient!  Two passes through the boxcar filter
> results in a nice smooth S-shaped reset curve with both y and dy/dx being
> continuous.  There's still a discontinuity in the second derivative but
> that's not nearly as bad.
> I hope this helps explain polyBLEP a bit.
> If you're dealing with triangle waveforms, you need to deal with
> band-limited RAMPs as well as band-limited STEPs.  You can see how that is
> generated by stopping at the boxcar filtered impulse (B) and then
> integrating it TWICE to get a band-limited ramp.  Finally you subtract the
> naive ramp from it to get the correction you need to apply around the
> gradient changes in the naive triangle waveform.  (It's possible to get 
> away
> with just one pass through the boxcar filter for triangle waveforms 
> because
> their spectrum rolls off much faster than saw and square, and aliasing 
> isn't
> such a big problem.)  Is anyone actually still following this!?!?
> -Richie,
> --
> This email has been checked for viruses by AVG.
> https://www.avg.com
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at synth-diy.org
> http://synth-diy.org/mailman/listinfo/synth-diy
> Selling or trading? Use marketplace at synth-diy.org 

This email has been checked for viruses by AVG.

More information about the Synth-diy mailing list