Saturday, 15 October 2011


The sine wave. For the last 4 years of maths I've never really taken to trigonometry - it seems closer to black magic, with formulae coming thick and fast from nowhere and it seeing very little application to daily shopping etc. I could probably argue the same about calculus, but then that seemed to click a lot more easily, possibly aided with the worst youtube videos I've ever seen (courtesy of my maths teachers).

But now the sine wave is unavoidable - according to my textbook the sine wave is "everything" in music programming. From physics I knew sound is constructed of waves, and I'd seen the sine wave on synths, but I was still sure there were other waves too - square looking waves and triangle looking waves.  Instruments on an oscilloscope showed some kind of repeating wave, but it was nothing like a sine wave.

Here's a sine wave for the mathematically deprived
So, with that in the back of our minds I'll take you through some musical terminology. Different pitches have different frequencies - higher pitches have waves that are more squashed together, and lower pitches have waves that are more stretched out. If you're a musician you might of heard of harmonics - you can play them on guitar by lightly touching a string in certain places, you can get them on piano by keeping a key down and playing the same note at different octaves (try it!) and you can even play them on wind instruments, but that technique's usually reserved for weird experimental pieces. Harmonics are simply frequencies at integer (whole number) multiples of the original, or base frequency. For example, an in-tune concert A, the note an oboist should in theory be able to play really well, is 440Hz - so saying this is the base frequency, we have harmonics at 2f, 3f, 4f, and forever until our ears bleed. Convert this to Hz and we get 880Hz, 1320Hz, 1760Hz and so on. On a little side note, doubling frequency is equivalent to going up an octave.

Here's where Fourier series come in. Thanks to the works of a clever frenchman, Joseph Fourier, we now know that every periodic (repeating) wave can be made just out of sine waves in different ratios of frequency and amplitude. By this we might mean we choose certain frequencies, and then for the higher frequencies, we'll make them quieter and quieter. By carefully choosing the frequencies and amplitudes we can make the important square, saw-tooth and triangle waves. Here's one I made earlier.

A sawtooth wave with 3 harmonics
See how it's still a bit wavy, one day it aspires to be a perfect wave, but it's not there yet. Listening to how the waves sound as they get sharper and sharper is pretty interesting - see the clip below. For those non-musically inclined, it's hard to describe how a wave can sound different, but I think the best way is by going and listening to the different waves - the pitches are the same but the timbre (pretentious musical analysis term) is different.  (Be a bit careful when listening to my clips of raw waves - they have a harsh sound and come out fairly loud)

Sawtooth Wave Harmonics by Boyley
For reference, without any harmonics you're going to just have a plain old sine wave, and as the sound clip progresses, one at a time (about every 1-2 seconds), I've added more and more harmonics.  The little pause is followed by a richer wave with 20 harmonics.

The different waves all have their own rules. The square wave has only odd harmonics, and the amplitude of each harmonic is 1/the harmonic number. In English: the 1st harmonic will have an amplitude of 1 (no change), the 3rd harmonic has an amplitude of 1/3 (the sine wave is 1/3 as tall), the 5th harmonic has an amplitude of 1/5, and so on, to infinite and beyond. Although, with a synth, we might say, do the first 20 harmonics, because I want my sound generated in finite time. When we add sine waves we'll get bits that add to each other (constructive) and bits that cancel out (destructive), and with this ratio, our wave becomes squarer and squarer. I'm not sure that's a word...

For the triangle wave we take odd harmonics again, but the amplitude for each harmonic is 1/(harmonic number)^2 (squared). The saw-tooth wave is a bit special because every harmonic is used, with amplitudes of 1/harmonic number. A little protip I found was if the wave is symmetrical when reflected across the x axis e.g. the triangle wave, it must only have odd harmonics. Otherwise, it must include some even harmonics (it might still have odd harmonics).

Hopefully this wave is self explanatory
Square Wave by Boyley

Take a guess...
  Triangle Wave by Boyley

So there it is.  Pretty much the mathsy fundamentals behind the synth stuff that I'm currently doing.  I can't currently write any more on Fourier series or analysis, but scanning through my textbook there's definitely more to come.  Next time I'll try not to write so much about maths.

No comments:

Post a Comment