Is WAVEFORM_TRIANGLE_VARIABLE antialiased?

tejas

Active member
I noticed the word ‘BANDLIMIT’ in the names of certain waveforms, but not in the triangle ones. Are they anti aliased?
 
If I remember rightly triangle isn't bandlimited, but has much lower spurious tone levels as its not a discontinuous waveform (rather its derivative is discontinuous).
 
Got it. I am using the audio shield with teensy. A google search revealed that the shield performs anti-aliasing during DAC. In that case, what is the purpose of using using band limited waveforms at all?
 
DAC performs antialiasing during conversion to analog but this does not eliminate the need to properly antialias generated waveforms as
once aliasing happens, it can't be "taken back". For example pure "saw" waveshape has infinite harmonics. If you don't apply bandlimiting, those infinite harmonics will fold into audible range (below nyquist/2) and become audible as nasty non-harmonic frequencies.
A 5 kHz sawtooth has harmonic partials at integer multiples of the fundamental:

fn = n * 5 kHz

With a 44.1 kHz sampling rate, the Nyquist limit is 22.05 kHz.
Any harmonic above 22.05 kHz will be reflected (“folded”) back into the 0–22.05 kHz band. A convenient alias-frequency formula is

falias=abs( ( (f + fs/2) mod fs ) ) - fs/2)

Harmonics of a 5 kHz saw and where they land​


Below Nyquist (no aliasing yet):


HarmonicFreqStatus
15 kHzOK
210 kHzOK
315 kHzOK
420 kHzOK

Above Nyquist — these fold back:


HarmonicOriginalFolded toReflection reasoning
525 kHz44.1 − 25 = 19.1 kHzmirror across 22.05
630 kHz44.1 − 30 = 14.1 kHzmirror
735 kHz44.1 − 35 = 9.1 kHzmirror
840 kHz44.1 − 40 = 4.1 kHzmirror
945 kHz45 − 44.1 = 0.9 kHzwrapped past fs
1050 kHz50 − 44.1 = 5.9 kHzwrapped (no mirror needed)
1155 kHz2nd-zone mirror → 44.1 − (55 − 44.1)= 13.2 kHzetc.

You can see the pattern: every harmonic above Nyquist reflects back toward DC, then the process repeats in each band of width 22.05 kHz.


Intuition​


  • Sawtooth harmonics extend indefinitely, so many upper partials fold into the audible band.
  • Their amplitudes still follow 1/n, but after aliasing they appear at unrelated frequencies, giving the “buzzy / digital” character.

Triangle has less energy in higher harmonics but still can alias.

When compared to sawtooth, triangle has only odd harmonics and their amplitude is 1/(n*n) as compared to 1/n for sawtooth.

So you need to bandlimit all generated data (including triangle wave).

See this for detailed explanation why aliasing happens and how to create alias-free equivalents of analog oscillators:
 
Last edited:
Makes sense. What is the easiest way to create an anti-aliased triangle waveform in teensy?
 
The easiest way is to use bandlimited wavetables for each octave.

You can generate bandlimited wavetables programmatically using JScript sample below and store them in C arrays for direct use in your program.

 
Last edited:
Thanks for this! My application however needs a variable frequency and a variable duty cycle triangle. Since the duty cycle is not always 0.5, I can't rely on the inbuilt WAVEFORM_TRIANGLE_VARIABLE, as around 0.0 and 1.0, the aliased frequencies will be quite audible.
 
Back
Top