Wavetable Synthesis Simplified

I developed a presentation as part of my Sprockit workshop. I think it’s a pretty clear presentation of wavetable synthesis and that it clearly shows how aliasing happens and how to avoid it. I’ve often found that it is difficult to find this type of clear and simple explanation of fundamental synthesis concepts that is particularly useful for the DIY Synth community. So, click through for some learning…

Let’s start with the basics. Here we have the humble Sine wave. This is a continuous analog signal. Let’s say it’s a 1Hz signal, meaning it goes through one cycle per second. It is an endlessly repetitive signal.

In order to do digital synthesis, we have to sample this sine wave. To sample it, we read its value at a regular interval and record it.

Our sample rate is 8Hz, or 8 times per second. We could sample a sine wave from a signal generator.  However, when we make a wavetable, we generally just calculate the value, which yields the same result as a pure perfect sampling of an analog signal. If we calculate the values of sin for these samples, using the formula:

x = sin(2*pi*y/8)

with y being the sample number. Calculating it this way, we end up with a wavetable like this:

wavetable = {0,.707,1,.707,0,-.707,-1,-.707}

So, if our synthesizer has the same sample rate of 8Hz, we could play back this wavetable and generate the same 1Hz sine wave. There are some messy details like digital-to-analog conversion and low-pass filtering, but that’s a story for another day.

Of course, we’d like our synthesizer to be able to make a variety of different frequencies though. So, let’s try making a 2Hz sine wave. We do this by maintaining an accumulator to store our math and tell us which sample to play. If we want a 2Hz wave, we add +2 to our accumulator each time we want a sample. The first sample would be 1. Then, we add 2 and play the 3rd. 

We add 2 more and and play the 5th.

We add 2 more and play the 7th.

The 9th sample then wraps around and we play the 1st sample again. And then the process repeats. At the end of 1 second, our original time frame, we have this:

When we reconstruct the signal from digital to analog, we have this:

Take away the digital sampling markers and:

Voila! We have a 2Hz sine wave. That’s pretty easy! Ah, but there are hidden dangers, especially dangerous to those uninitiated in digital signal processing. Let’s encounter them.

What if we want to make a 6Hz sine wave? If we follow the same process as we did for 2Hz, but now our accumulator adder is 6. We take the first sample, and then the 7th.

Then we add 6, and it wraps around to get the 5th sample.

Then, 6 more and we get the 2nd sample.

And the process continues and after 1 second, we have:

 This looks kind of familiar. It’s another 2Hz sine wave. But, we were trying to make a 6Hz sine wave. So what went wrong?

This is aliasing. Our sample rate is 8Hz. In digital signal processing, it is impossible to generate a signal which is greater than half our sample rate, also called the Nyquist Rate. When you try to create a signal above the Nyquist Rate, you get aliasing. It’s called aliasing because the result is an alias of the signal you’re trying to generate. Let’s visualize. In digital signal processing and in electronics in general, we often look at things in the frequency domain. Simply, this charts the frequency along the x-axis and amplitude along the y-axis. If we do that for our signal of interest, it looks like this:

Our sample rate is 8Hz. Our Nyquist Rate is half of that, 4Hz. The signal we were trying to generate was 6Hz. The alias is a mirror image of the 6Hz signal, and the Nyquist Rate is the mirror point. 6Hz – 4Hz = 2Hz. If we tried to make 7Hz, we would get 1Hz, 5Hz would make 3Hz. And so on. It ends up being messier in practice. The higher you try to go, the worse the problem gets. I’ve caused this problem and you’ll still actually hear some of the higher frequency, but the higher you try to go, the less of it you’ll hear and the more of the aliasing you’ll hear.

What’s to be done about it? You need to have a high enough sample rate that any signal you want to generate will be below the Nyquist Rate. This is a big part of the reason for having absurdly high sample rates. There are other reasons, like reducing noise, particularly quantization noise and other non-linearities caused by the transition from digital to analog.

I hope this simple explanation makes something which can be rather dense a little bit clearer for you. If you have questions or comments, please feel free to lob them my way.

Posted in Synthesis Fundamentals, Wavetable Synthesis and tagged , , , , , , , , , , .

2 Comments

  1. I don’t remember seeing such a simple and concise explanation of aliasing on the digital domain. Very good!

  2. Pingback: JZ (jzirkle) | Pearltrees

Leave a Reply