Skip to main content

JM

Music. Tech. Philosophy.

JM

Music Theory: Representing the Circle of Fifths as a Matrix

5 min read

The Circle of Fifths

We all know them when we hear them, but what makes a wrong note wrong? If you're in a private place (or a public place -- I'm not going to tell you how to live), try this simple experiment. Sing a note -- any note. Was this note right or wrong? A note, or combination of notes (chord) is only 'right' or 'wrong' in the context of the notes and chords around it. Therefore, it's not the exact pitch of a note that matters, but rather the relationship between the note and the rest of the pitch class space in which it appears.

I wanted to find a way to represent these relationships between chords in a way that would be convenient and transparent for musicians and songwriters. The result is this lazily-named Magic Chord Helper app, which uses a musical concept called the Circle of Fifths to suggest additional chords based on the chords that already appear in a song.

The Pitch Class Space Matrix

The principle insight that powers this application is the notion that every musical key can be represented as a 12-element array, where each element represents a note serving as the root of a chord. This array contains the following values:

0 = not in key
1 = major
2 = minor
3 = diminished

For example, the key of A can be represented like this: [ 1, 0, 2, 0, 2, 1, 0, 1, 0, 2, 0, 3 ]. Here's how we read this array. At index 0 (the first element), we find the value 1, which means that the key of A contains the chord A major. Continuing, we see that the second value, representing B flat, is 0, therefore, no B flat chords are in the key of A. At index 2, we find the value 2, meaning that the key of A includes the B minor chord, etc.

For every note, there is exactly one major key for which it is the root note. Therefore, we can construct a matrix of every possible major key by simply offsetting the array from the previous example by 1, and moving the last element to the front of the new array, so we end up with a matrix that looks like this:

[[ 1, 0, 2, 0, 2, 1, 0, 1, 0, 2, 0, 3 ],
 [ 3, 1, 0, 2, 0, 2, 1, 0, 1, 0, 2, 0 ],
 [ 0, 3, 1, 0, 2, 0, 2, 1, 0, 1, 0, 2 ],
 [ 2, 0, 3, 1, 0, 2, 0, 2, 1, 0, 1, 0 ],
 [ 0, 2, 0, 3, 1, 0, 2, 0, 2, 1, 0, 1 ],
 [ 1, 0, 2, 0, 3, 1, 0, 2, 0, 2, 1, 0 ],
 [ 0, 1, 0, 2, 0, 3, 1, 0, 2, 0, 2, 1 ],
 [ 1, 0, 1, 0, 2, 0, 3, 1, 0, 2, 0, 2 ],
 [ 2, 1, 0, 1, 0, 2, 0, 3, 1, 0, 2, 0 ],
 [ 0, 2, 1, 0, 1, 0, 2, 0, 3, 1, 0, 2 ],
 [ 2, 0, 2, 1, 0, 1, 0, 2, 0, 3, 1, 0 ],
 [ 0, 2, 0, 2, 1, 0, 1, 0, 2, 0, 3, 1 ]]

As we established in the previous example, the rows represent keys and the columns represent the chords within that key. So with labels applied it looks like this:

     [ a ] [ a#] [ b ] [ c ] [ c#] [ d ] [ d#] [ e ] [ f ] [ f#] [ g ] [ g#]
[ a ]  1     0     2     0     2     1     0     1     0     2     0     3
[ a#]  3     1     0     2     0     2     1     0     1     0     2     0
[ b ]  0     3     1     0     2     0     2     1     0     1     0     2
[ c ]  2     0     3     1     0     2     0     2     1     0     1     0
[ c#]  0     2     0     3     1     0     2     0     2     1     0     1
[ d ]  1     0     2     0     3     1     0     2     0     2     1     0
[ d#]  0     1     0     2     0     3     1     0     2     0     2     1
[ e ]  1     0     1     0     2     0     3     1     0     2     0     2
[ f ]  2     1     0     1     0     2     0     3     1     0     2     0
[ f#]  0     2     1     0     1     0     2     0     3     1     0     2
[ g ]  2     0     2     1     0     1     0     2     0     3     1     0
[ g#]  0     2     0     2     1     0     1     0     2     0     3     1

 

By calculating which row most strongly corresponds to the selected chords, we can predict the key and, subsequently, additional chords that will sounds 'right' within the predicted pitch class space. No distinction is made for major keys vs minor keys since this calculation is unconcerned with determining the root note; instead, it simply evaluates the pitch class space taken as a whole, regardless of the mode.

Still Curious?

Coders: check out the source code!

Musicians: check out this other cool circle of fifths app

JM

Music: Chassol

1 min read

Really loving the idea of composing harmonies to match the natural pitch / cadence of speech:

JM

Mic Check
One...Two...