Cat admiring an unrelated waveform. Photograph by Yann (@mwyann).

The CPX basic synthesizer uses a small sample made from a list of 12 values to create a low resolution sawtooth wave. This sample is played repeatedly as a loop at a playback rate adjusted to match the desired note frequency. For example, the note A4 (440Hz) would be played at 12 * 440 = 5280 samples per second.

The CPX has an upper playback limit of 350000 samples per second which dictates an upper frequency for this sample of 29167Hz, well into the inaudible, ultrasonic range. This technique to change the audible frequency of a sample clearly has limitations with large samples.

Two cycles of the low resolution, "steppy" sawtooth wave are shown below alongside the maximum resolution equivalent. CircuitPython uses values 0-65535 (16bit) to represent the output value/voltage. The CPX's SAMD21 processor's digital to analogue converter (DAC) is only 10bit, reducing (quantizing) the resolution to 1024 values.

The two different resolution sawtooth waves can be seen decomposed into multiple sine waves of different frequencies on the audio spectra below. This is what would be seen on a spectrum analyzer analysing either the the signal from the DAC output (touchpad A0) or that signal played through a high fidelity sound system. In this case, the bar graph was generated mathematically from the magnitude of the Discrete Fourier Transform (DFT).

The expected highest (loudest) frequency is the fundamental occurring at 440Hz and then extra harmonics at 880Hz (2x) and 1320Hz (3x) and so on. The steppy quality of the low resolution sawtooth removes the 5280Hz, 10560Hz and 15840Hz harmonics, visible as absent red bars in the graph.

The graph stops at 20kHz, an oft-used upper limit for human hearing. The curve suggests the harmonics continue into the ultrasound range. This can be problematic if the audio signal is going to be used (sampled) by another digital device without filtering to remove the higher frequencies.

The actual sound from the CPX is further affected by the characteristics of the onboard (Class D) amplifier and the tiny 7.5mm speaker.

An explanation for why humans perceive sound mostly in terms of the frequencies of the constituent sine waves can be found in Chapter 1 of David Benson's Book, Music: A Mathematical Offering.

Simple Computer Sound Generation

It is trivial for a digital computer to generate square waves where the signal simply rises and falls with the pauses between determining the frequency and duty cycle. These are commonly used for computer clock signals but can also be used for generating audio. This would seem like an obvious, straightforward choice for generating sounds, It was used for:

Waveforms can also be generated by composition. The next two sections compare the square and sawtooth wave to explore how the wave shape develops as more sine waves are added and how the two differ.

Square Wave Construction

The animation below shows construction of a square wave from the addition of 10 sine waves. The overtones of a square wave occur at odd multiples of the fundamental frequency, this makes it less rich in harmonics than the sawtooth wave and gives it a different sound or timbre.

It's interesting to see how the shape of the final waveform becomes more straight/perpendicular as each sine wave is added. This is still far from perfect in terms of shape with ten harmonics but likely to be a better choice for digital audio applications to prevent undesirable aliasing effects.

Sawtooth Wave Construction

A sawtooth wave made from 10 harmonics is shown below for comparison. This one is "upside down" compared to the one that the CPX is generating but this makes no difference to the magnitude of the frequencies of the harmonics.

The wikipedia pages for sawtooth wave and square wave have audio clips allowing for a comparison of the two different timbres.

Jess Swanson's An Interactive Introduction to Fourier Transforms is a fun and interactive way to explore waveforms more.

Analogue Synthesizer Waves

The Korg Volca Bass, part of the 2010s renaissance in analogue synthesizers, offers both sawtooth and square waves as the basis for creating sounds. The dual-purpose keys which allow waveform selection are shown below for the three (voltage controlled) oscillators (VCO). The synthesizer's low-pass filter can be used to reduce higher harmonics, changing the timbre of the sound. This technique is referred to as subtractive synthesis. The opposite approach is additive synthesis which creates sounds by adding sine waves like the animations above.

The low frequency oscillator (LFO) (below, on the left) is used to modulate the volume (amplitude) or pitch or filter cutoff frequency. This is offered in triangle or square waveforms.

Korg Volca Bass wave selection for LFO and VCO. Photograph by Kevin Walters.

The actual sawtooth wave can be seen in an example of the audio output voltage from one oscillator in the service manual, shown below. The slightly steppy quality seen here is due to the resolution of the digital oscilloscope.

Korg Volca Bass service manual showing sawtooth wave output on an oscilloscope.

On an incidental note, the Korg Volca (and Monotron) synthesizers appear to have been designed to be easily modified by their owners - the circuit board has clearly labelled solder points. Hobbyist hardware modification for electronic instruments is referred to as circuit bending.

This guide was first published on May 14, 2019. It was last updated on Nov 27, 2023.

This page (Waveforms) was last updated on Apr 06, 2019.

Text editor powered by tinymce.