DSP: Aliasing and Synthesis

In a previous post, I discussed how in setting up my oscillators, how I made a proper demonstration of aliasing. I have yet to find a clear description of the problem as it relates to digital synthesis.  There are many sites which define aliasing in engineering terms but don’t make it as easy a thing to understand as it can be.  Follow along as I give it a shot.

The Frequency Domain

Frequency Domains of Three Time Domain Signals

In Digital Signal Processing, or DSP, we often hear the term frequency domain.  In the frequency domain, we are talking about a signal, in or case a sound, in terms of its frequency composition.  A sound could be a pure signal, like a pure sine wave at one frequency, say 10 Hz.  A sound could be a more complicated sound made up of a number of frequencies, say 10, 20, and 30 Hz each with an amplitude.  In the simplest possible terms, aliasing is the presence of frequencies that we did not intend to be present in the frequency composition of a signal.  The unwanted frequencies in the signal are caused by errors in the system.  In my case, I caused them by not taking into account some fundamental aspects of digital signal processing.  There is a pretty deep and not altogether common sense reason for this in the frequency domain that can be derived through trigonometry.  I don’t want to drag you through that.  There are many sources if you’re really curious.  I think there’s an easier way to understand it.

It’s Easier to Understand in the Time Domain

If we just talk about the time domain, where we’re just talking about what sample and when, you can see how I caused this aliasing problem.  I have been making a wavetable synthesizer.  This means fundamentally that I’m playing back a short sample, or waveshape, over and over again.  Hypothetically, let’s say my synthesizer is designed to operate with a sample frequency of 10Hz.  That means my synthesizer needs to put out one sample 10 times per second.  Let’s also say that my wavetable has 10 samples in it. Each sample is just a number. Let’s make samples 1-5 equal to 0 and 6-10 equal to 1. This will make a square wave.

Wavetable Playback

In the software, there is a device called a phase accumulator.  The phase accumulator keeps track of which sample to play.  The value stored in the phase accumulator is updated every time a sample is output.  There is another related device, the phase accumulator increment, which is how much we add to the phase accumulator every time we update it.  So, if the phase accumulator increment is 1, we add 1 to the phase accumulator every time a sample is output.  So the steps are:

  • 1. The phase accumulator starts at 1 and the synthesizer puts out the first sample.
  • 2. The phase accumulator is incremented by the phase accumulator increment, which is 1.  Now, the phase accumulator has 2 stored in it.
  • 3.The synthesizer puts out the second sample.  The process repeats.
  • 4. When the phase accumulator gets to 10, it resets back to 1 and the process repeats, or loops.

So, the synthesizer puts out the values 0,0,0,0,0,1,1,1,1,1….. and reapeat.  That’s all well and good. Everything is even and if this process continues, the synthesizer will put out a 1Hz version of our wavetable.  

So, what’s the problem?

There’s no problem if we want to make a 1Hz output.  Even 2Hz is fine.  The problem happens when we want a 3Hz output. Can you figure out why?  If we want a 3Hz output, we simply make the phase accumulator increment 3.  We need to play the

  • 1. The phase accumulator starts at 1. It puts out the first sample.
  • 2. The phase accumulator is incremented by the phase accumulator increment, which is 3.  Now, the phase accumulator has 4 stored in it.
  • 3. The synthesizer puts out the 4th sample.  The phase accumulator increments to 7.
  • 4. The synthesizer puts out the 7th sample.  The phase accumulator increments to 10.
  • 5. The synthesizer wraps around by adding 3 and ends up at the 3rd sample.  Then, the 6th, 9th, 2nd, 5th, 8th, 1st….

So, what values are played? 0,0,1,1,0,1,1,0,0,1,0. The first and the last 0 are both the first sample. Can you see the problem?  The sequence does not repeat evenly, or to say it another way it is not perfectly periodic.  Sometimes the sequence will only play one 1.  So, not only will it play a 3Hz tone, but a 1Hz tone will be heard slightly quieter than the 3Hz tone and it sounds like garbage.  You will easily hear both tones.  The synthesizer will not be able to make a pure 3Hz tone.  Not if it’s designed this way.

This is aliasing.

If the frequency you’re trying to generate is not a factor of the sample frequency, this system will generate aliasing.  In my synthesizer, I’ve got a 48000 Hz sample frequency.  I can make a perfect 1000Hz tone, but 1100Hz shows up as 1000Hz plus a 100Hz undertone.  It sounds like an old telephone modem.  So, what can we do?  Well, I’ve been doing some research, reading, sweating, and fretting.  Like aliasing, no one explains the solution simply so it takes some serious thought.  I’m working on the solution and I’ll explain it in a coming post.  Many, many people smarter than me have solved this problem and I’ll explain it to you.  Stay tuned.

Posted in General Electronics, Rockit and tagged , , , , , , , .

2 Comments

  1. Pingback: 8 Bit Synth: MATLAB Bandlimited Wavetable Simulation and Aliasing « Hackme Electronics

Leave a Reply