Archive

Archive for March, 2009

Music is Math (part 1)

March 10th, 2009

I was listening to some random songs the other day, and a couple times I couldn’t help but notice how often melodies get recycled and repeated, even by completely unrelated artists. And I’m talking about legitimate music here; the fact that, for example, every Nickelback song is exactly the same is a different story.

So of course, being the music nerd/math major/insomniac that I am, I started wondering if all this melodic repetition is statistically inevitable. Clearly there are pitch intervals and rhythmic patterns that our ears like to hear, so we tend to gravitate towards those melodies that we’re comfortable with. But how many unique melodies could we potentially create?

Initially, I aimed for extremely basic melodic fragments–1 bar of melody in 4/4 time, with notes no shorter than 8th notes (think: first line of Mary Had a Little Lamb). I omitted rests mainly to keep it simple, but also because including rests would generate a lot of melodies that sound the same but just have different note durations. Pitch-wise, we start out by assuming all the available notes will be diatonic to a 7-tone scale (major, minor) and by disregarding octaves as distinct.

Rhythmically, there are 128 possible combinations of notes we can use in a melody following the guidelines above. This is obtained by finding the number of ways we can arrange 1 note (1), plus the number of ways we can arrange two notes (7), etc. This turns out to be C(7,0) + C(7,1) + … + C(7,7) = 1 + 7 + 21 + 35 + 35 + 21 + 7 + 1. This is recognizable as the 8th row of Pascal’s triangle:

which we know sums to 2^7 = 128. The number 7 is prominent here because we are assuming that a note is being played/sung at any given time, and thus the divisions we are concerned with are the seven possible note breaks, where the note may either repeat or change pitch.

Next, we account for the fact that any of the notes in any of the patterns above may have one of 7 pitches diatonic to the scale we’re in. Breaking it down into the Pascal’s triangle divisions, we see that when there is one note there are 7 possible patterns, when there are 2 notes there are 7*7^2=343 patterns, etc, so we have 1*7^1 + 7*7^2 + 21*7^3 + … + 7*7^7 + 1*7^8 = 14,680,064.

So there are roughly 14.7 million possible melodies under the strict initial criteria above. Of course, some of these will sound pretty strange, but since every note is diatonic to a scale, it is plausible that we could harmonize each of those 14.7 million melodies into something fairly musical.

Now we can generalize; using the same methods as above we obtain

Where m is the total number of possible melodies, t is the time signature expressed as a fraction (4/4 time = 4/4 = 1), b is the base rhythmic value expressed as a fraction of a whole note (in the case above, we have b = 1/8 = .125), and n is the number of notes available to choose from. It is easier to simply calculate the value ( t / b )-1 initially and assign it to a new variable r, giving us a cleaner equation:

Some applications:

Possibilities for a chromatic melody in 4/4 time, eighth-note base: 752,982,204
Possibilities for a pentatonic melody in 6/8, eighth-note base: 38,880

Finally: most full melodies will be around 8 measures long, and the average vocal range is around 2 octaves. So the number of possibilities for a typical melodic phrase in a typical voice:

4.85 x 10^151, or
48507533781993166111612232428658393420459960575040081678400749031792433262513522776935109626845034299191809567606548631891897073188914213560934937997326

You have no excuse, Nickelback.

Nate Academia