# Dual modes

We introduce one final significant concept: the dual mode. The dual of a mode simply has the notes that are not in the original mode. This means dual of the mode with mode number m will have mode number 4095-m. For example, the dual of the major mode m:1010 1101 0101 is m:0101 0010 1010.  Clearly, if a mode has n notes, then its dual with have 12-n notes. We will denote the dual of a mode m by

(At the risk of being confusing, m:0101 0010 1010 is generally named “the pentatonic scale”, although the meaning of “scale” used in these posts, and “pentatonic” can mean any mode or scale with five notes. If you play the major scale on piano starting on C, you will use all the white keys. The dual is then the pentatonic scale that uses all the black keys).

The concept of a dual mode can be used to explain a number of symmetries we have noticed between things involving the numbers x and 12-x in some way.

### Related modes

In the first post, we grouped together related modes using their gap patterns. We assert that if two modes m1 and m2 have the same canonical gap patterns, then their respective dual modes, 1 and 2 will also have the same canonical gap patterns. This is left as an exercise for the reader.

### Imperfections

This leads onto one of the important results for these posts: a mode m and its dual will have same number of imperfections of degree d, for all d.

This means, for example, that the (seven-note) major scale and it dual, “the” pentatonic scale, have the same number of notes without (for example) a minor third above them in the scale! This result is more surprising when you consider a mode and its dual generally have different numbers of notes.

To explain this result, we will introduce the concept of a chain. Consider a mode with at least one imperfection of degree d. That means there is an imperfect note of degree d – i.e. a note in the mode that doesn’t have another note in the mode d semitones above it. We will denote this by x1. However, we can see if there is another note x2 d semitones below x1, and this note becomes a note in the chain. We can then repeat the process until we eventually find a note without another note in mode d semitones below it, and this completes the chain. We then have a sequence of notes like the following::

• xL → … → x3 → x2 → x1

(In some cases, x1 won’t have any notes in the mode d semitones below it. This means L=1, and the chain is simply the note x1. This doesn’t affect the rest of this argument). (L has a maximum value of 12).

We can repeat the process for every imperfect note of degree d, resulting in a chain for each imperfect note of degree d.

Now consider what happen when you up d semitones from x1. This note cannot be in the mode m (because x1 is an imperfect note of degree d). This means it must in the dual mode , because contains precisely the notes that aren’t in m. We will denote note by y1. We can then form another chain starting with y1, as follows:

• xL → … → x3 → x2 → x1…→; y1 → y2 → … → yK

This chain must have an end note, yK. (If it didn’t, then the chain must have rejoined itself, which would imply that one note in the chain had two notes feeding into it. This is impossible, as it would mean that note had two different note d semitones below it.) (In general L <> K. Also, K can equal to 1, which again does not affect this argument.) That end note will be an imperfect note of degree d.

We can repeat this process for every imperfect note x of degree d in m: finding the note y in that is d semitones above x, building a chain starting on y, and then finding an imperfect note of degree d in . This implies the following:

• The (non-zero) number of imperfections of degree d in a mode m cannot be higher than the number of imperfections of degree d in its dual mode

However, we can reverse the process and apply the same logic, because the dual of the mode is simply the original mode m: for each imperfect note of degree d in , we can find the note in m that is d semitones higher, build a chain in m starting on that note and ending with an imperfect note of degree d in m. This implies the following:

• The (non-zero) number of imperfections of degree d in a dual mode cannot be higher than the number of imperfections of degree d in the original mode m.

Together, these two statements imply that the number of imperfections of degree d in a mode and its dual will the same, for all d, assuming that number is not zero.

But what if it is zero? Assume (for a contradiction) that the mode m has zero imperfections of degree d, and its dual mode has a non-zero number of imperfections of degree d. However, the latter statement implies (by the above) that m will have the same non-zero number of imperfections of degree d. This contradicts our original statement. Hence must zero imperfections of degree d also.

This argument can also be applied using the chains developed above. If a mode m has zero imperfections of degree d, then this means the chain starting with a note x1 must eventually wind up back at that note:

• x1 → x2 → x3 → … → xL → x1

We say this is a closed chain. The length of the closed chain (L) could be same as the number of notes in the mode, or less. However, it cannot be equal to 1. (L=1 implies you could take a note, go up d<12 semitones, and end up back at the original note.) For a given mode with zero imperfections of degree d, there will a set of one or more closed chains that together contain all notes in the chain. Because the chains are closed, this means every note in the mode has another note that d semitones below it in the mode.

Now, consider the dual mode . If there was an imperfect note of degree d, then the note d semitones above it would be in the original mode m, or conversely, the imperfect note in is d semitones below some note in m. However, we know that descending d semitones from any note in m produces another note in m. Hence there can be no imperfect notes of degree d in .

# How can scales be classified? (part 2)

In the previous posts, we discussed scales in terms of the number of notes without another note in the scale that is a perfect fifth higher, and defined this as the number of imperfections of the scale. The interval of a fifth has great significance musically, but mathematically has none whatsoever. Consequently, we can classify scales by using other intervals in the same role.

We will talk about the number of imperfections of degree d, where ‘d’ is the number of semitones in the relevant interval. So, where we talked about imperfections in terms of the perfect fifth, we will now talk about the number of imperfections of degree 7 (because a perfect fifth is 7 semitones). Similarly, we refer to such notes as imperfect notes of degree d.

Taking the major scale (which has seven notes), we can look at how imperfections there are of each degree. Taking degree 1, there are only two notes in the major scale with another note one semitone higher, so the scale has five imperfections of degree 1. For degree 2, there are five notes with another note a tone higher, so the scale has two imperfections of degree 2. Running through degrees 1 to 11, we end up with the following:

 d Imperfections of degree d 1 2 3 4 5 6 7 8 9 10 11 5 2 3 4 1 5 1 4 3 2 5

There is a symmetry in this table: the number of imperfections of degree d and degree 12-d are the same. This isn’t just true of the major scale – it’s true of all scales. (This is clearly trivial for d=6). The reason for this as follows. If a note x is d semitones above note y, then note y is 12-d semitones above note x. This means that note y won’t be an imperfection of degree d, and note x won’t an imperfection of degree 12-d. Hence when the respective number of imperfections are counted, the total will the same.

There will never be more than six imperfections of any degree, using the same argument at the end of the previous post.

We define signature of a scale to be the imperfections of degrees 1 to 6, written in that order. We will denote these with an initial ‘s’. So the signature of the major scale is “s523415”, and the scale of the whole-tone scale (m:1365, where p’:1365=[222222]) is s606060.

So, our final way to classify scales is by their signature. In a subseqequent post, we will look at how many possible signatures there are, and how many scales are there for a given signature.

# How can scales be classified? (part 1)

Music does not consist only of single notes isolation: notes occur in sequence, or simultaneously. The overall effect is controlled (in part) by the intervals between notes. Consequently, the intervals that exist between the various notes in a scale are or considerable important. We shall consider the interval of a perfect fifth by way of an example.

Examining the seven notes of the major mode (m:2773) reveals that all notes except one have another note in the scale that is a perfect fifth higher. (Namely, the seventh note of the scale.) We say that the major mode has one imperfection, and we call this note an imperfect note. Examining the various church modes (dorian, phrygian, lydian, mixolydian, etc.) shows they also have one imperfection. However, this is implied by the fact that the major mode has one imperfection, because of how the church modes can be derived from the major mode. This means the number of imperfections depends purely on the canonical gap pattern (and hence the scale), and not on the mode. So rather than talking about the number of imperfections of a mode (such as m:2773), we will talk about the number of imperfections of the scale [2221221] (= p’:2773).

Classifying scales by the number of notes and imperfections yields the following:

Notes Imperfections Total
0 1 2 3 4 5 6
0 1 1
1 1 1
2 1 5 6
3 1 8 10 19
4 1 11 21 10 43
5 1 12 30 20 3 66
6 1 13 34 26 5 1 80
7 1 12 30 20 3 66
8 1 11 21 10 43
9 1 8 10 19
10 1 5 6
11 1 1
12 1 1
Total 1 11 85 156 86 11 1 351

The table reveals several points of interest

### Scales with zero imperfections

There is only one (non-null) scale with no imperfections, and that is the 12-note (chromatic) scale. Every scale with less than 12 notes must have one imperfection, as there will be a note in the scale that is a perfect lower than a note not in the scale.

## Scales with one imperfection

There is exactly one scale for a given number of notes (1 through 11) with one imperfection. If the first note is C, then these scales will have the notes {C}, {C,G}, {C,G,D}, {C,G,D,A}… where each note added is a fifth above the previous note added. By construction, only the note added at each step won’t have a note a fifth above, and hence the scale has only one imperfection.

Proving these are only scales with one imperfection basically takes this line of reasoning and runs it in reverse (and is left as an exercise to the reader).

### Symmetry

The number of scales with m imperfections and n notes is the same as the number of scales with m imperfections and 12-n notes. The reasons for this will be explored in a later post.

## Maximum imperfections

Finally, the table reveals that no scale has more than six imperfections, even it has more than six notes.  The reason for this is a little complex, and can be ignored without affecting the rest of these posts.

If a scale with more six notes is constructed so the first six notes chosen do not have another note in the scale a perfect fifth above, then the remaining possible six notes must all be a perfect fifth above a note in the scale so far and a perfect fifth below another note in the scale so far. Consequently, the seventh note picked will be both a perfect fifth above a note in the scale (reducing the number of imperfections by one) and will have a note a perfect fifth above it (so will not create an imperfection). Similar logic applies for the 8th through 12th notes picked.

# How many sets of related modes (scales) are there?

In the previous post, we discussed two modes that gap patterns that were related, but not identical. These were m:1312 and m:1034, which have gap patterns p:1312=[237] and p:1034=[723]. This makes them musically distinct, but clearly related. Each gap patterns can be obtained from the other by a cyclic permutation of the elements (that is, by moving the digits from one to the other). Another such mode would be that with gap pattern [372], such as m:1001 0000 0010 = m:2306. These three modes all belong to the same “scale”. (Confusingly, the term ‘scale’ is also used for playing all the notes in a given key in order. However, that term won’t be used here).

A more familiar example is to use the major scale m:1010 1101 0101 = m:2773, with gap pattern p:2773=[2212221] . The most well-known modes (dorian, phrygian, lydian, mixolydian, etc.) can all be obtained by using the notes of a major scale, but starting at different point. This is precisely equivalent to taking the gap pattern of the major scale, and performing a cyclic permutation. For example, a dorian scale can be obtained by starting on the second note of a major scale – which is the same as using the gap pattern of the major mode, but starting with the second digit. As the gap pattern of the major mode is [2212221], that of the dorian mode is [2122212]. Similarly, phrygian, lydian and mixolydian modes have gap patterns of [1222121], [2221221] and [2212212] respectively.

We shall define a way of re-writing gap patterns into the “canonical gap pattern”. This method for re-writing with result in all modes belonging to the same scale ending up with same canonical gap pattern. The method is simply to use the cyclic permutation the places the largest digit in the gap pattern at the start. If there is more than one largest digit, then choose the cyclic permutation such the second digit is the highest. Again, if there is more than one possibility, then keep maximising the value of each successive digit. The canonical gap pattern is denoted by “p’:” followed the number of the mode.

Two examples to illustrate this:

• For p:1312=[237], the largest digit is a ‘7’, so the cyclic permutation with the ‘7’ first is [723], and hence p’:1312=[723]. For p:1034=[723], the largest digit is again 7, so p’:1034=[723] = p’:1312. This means m:1034 and m:1312 have the same scale. (The other mode of this scale is m:2306, where p:2307=[372].
• For p:2773=[2212221], the largest digit is ‘2’ – of which there are five. The are several cyclic permutations which also have a ‘2’ as the second digit (e.g. [2212221], [2212212]), but only one which have a ‘2’ for the first, second and third digits, namely [2221221]. As a result p’:2773=[2221221].

One practical tip for calculating the canonical gap pattern: if you consider the gap patterns to be numbers rather than sequences of digits (so that [237] is “two hundred and thirty-seven”, not the sequence “two, three, seven”), then the canonical gap pattern will be the cyclic permutation with the highest value. For example, 723 = max(237,723,327).

From here, we shall define a scale to be “the set of modes sharing a particular gap pattern”. (In formal mathematical terms, a scale is an equivalence class where the equivalence relationship is “have the same canonical gap pattern”, and the members are modes)  This means that there is one-to-one relationship between scales and a gap pattern.

(Somewhat confusingly, scales are often given the same names as modes. So the “major scale” is the scale of the major mode. Of course, it also the scale of the dorian mode, the phrygian mode, etc.)

So, how many scales are there? In this case, the simplest way of calculating this is to work out the canonical gap pattern for each mode, and then count the unique values. This produces a total of 351 scales.

As an aside, the number of scales by number of notes is as follows:

• 0 notes: 1 scale
• 1 notes: 1 scale
• 2 notes: 6 scales
• 3 notes: 19 scales
• 4 notes: 43 scales
• 5 notes: 66 scales
• 6 notes: 80 scales
• 7 notes: 66 scales
• 8 notes: 43 scales
• 9 notes: 19 scales
• 10 notes: 6 scales
• 11 notes: 1 scale
• 12 notes: 1 scale

There is a symmetry to these numbers – the number of scales with n notes is the same as the number of scales with 12-n notes. The reasons for this will be explored in a later post.

# How many musically unique modes are there?

This series of posts will look at musical modes and both quantify and classify them. Unlike much discussion in this area (for example www.sacredmusictheory.com), no restrictions are placed on what notes or intervals are allowed.

A chromatic scale has 12 notes, and each of these is either in a given mode, or is not. This results in 2^12=4096 possible modes. (However, as we shall see later, many of these are musically equivalent.) We shall number these modes from 0 to 4095, and use “m:” followed by a number to denote a given mode. Writing the mode number as a (12-digit) binary number then allows a simple link between the mode number and which notes in the scale. If the nth (binary) digit is a 1, then the nth note of the chromatic scale starting on C is in the mode. For example, 1234 in decimal = 1001 0010 1001 in binary (the spaces are just for readability). Consequently, m:1234 contains the notes {C,D#,F#,G#,B}. We use the decimal or binary notation according to need.

Some modes in this list can obtained from other modes by simple transposition. For example, m:2624 = m:1010 0100 0000 = {C,D,F} transposed up by a semitone yields m:1312 = m:0101 0010 0000 = {C#,D#,F#}. These two modes are musically identical. However, they are not the same mode as m:1034 = m:0100 0000 1010 = {C#,G#,A#}. This mode’s notes are the same notes as those in m:2624 transposed up an augmented fifth/minor sixth (8 semitones) – but the order is different. The first note of m:2624 transposed up a minor sixth is not the first note of m:1034. Another way of comparing two modes to see if they are musically identical is to look at the gaps between successive notes. Now, m:2624 and m:1312 have a gap of 2 semitones (a tone) between the first two notes, then a gap of 3 semitones (a minor third) between the next notes, then a gap of 7 semitones (a prefect fifth) from the last note back to the first note. This produces a “gap pattern” of [2,3,7]. We shall denote the gap pattern of mode by “p:” followed the number of the mode. So, p:2624=[2,3,7], and p:1312=[2,3,7] also – but p:1034=[7,2,3], and that is why m: 1034 is not musically equivalent to m:2624 or m:1312.

For brevity, we shall henceforth write the gap patterns without the commas. A gap of 10 semitones shall be denoted by “a”, 11 semitones by “b” and 12 semitones by “c”. Hence p:1000 0000 0001 = [b1]. The digits in the gap pattern will always sum to 12, because there are 12 semitones in an octave.

Returning to the original question of “how many musically unique modes are there?”, we could calculate all gap patterns of all 4096 modes, and count the unique gap patterns. The table below shows all those gap patterns and their associated mode number(s). However, there a logical argument that lets us produce the answer.

If we take the binary notation for a mode number, remove one or more digits from the right-hand end, and place on them left-hand end (in the same order), then the resulting mode will be a transposition of the original mode. Similarly, moving digits from the left-hand to the right-hand end also produces a transposition. However, the gap pattern will only be preserved if the ‘moved’ digits are all zero. Thus, a mode starting with a binary notation starting with “1” and ending with exactly n zeros (i.e. the (n-1)th  digit is a “1”) will yield exactly n other modes that are transpositions.

For any mode (other than m:0) where the binary notation starts with exactly n zeros (n>0), we can take the first n digits from the left-hand end and move to the right-and end, to produce a mode with binary notation starting with a “1”, and where the original mode is a transposition of this new mode. Hence, every mode (other than m:0) either has a binary notation that starts with “1”, or is a transposition of a mode that starts with “1” and has the same gap pattern. If two different modes both have binary notations starting with “1”, then they will not have the same gap pattern. Hence, the number of distinct gap patterns is precisely the number of modes from m:1000 0000 0000 to m:1111 1111 1111, plus one for m:0. This is 2^11 + 1 = 2049. So, there are 2,049 musically unique modes.

Table of all distinct modes

# GO Tracker Mashups

GO Transit (the inter-regional transit provider for the greater Toronto area) has a handy online tracking tool for its trains. Naturally, I wanted to get into the data behind it all and produce something that would work outside the default website. So, simply open my GO Tracker KML file in Google Earth, and you’ll get live updates on train and (some) bus locations! The bus data is not (yet) part of GO’s tracking tool, and only includes some bus routes.

Side note: You can also view things in Google Maps, albeit without auto-update, or a version of GO’s own train-only map with no sidebars and extra info… someone took the latter, and made their own version with buses and speeds (thanks Sid!)

The KML file contains a network link (that updates every 20 seconds) to this ASP file on my sever. You can view it your browser, as it’s set to output as a generic XML file (although it’s all valid KML). This made debugging easier, as I could view it in my browser without trying to open Google Earth every time. You can also get bus-only and train-only versions, should you so desire. The ASP file contains some server-side (VBscript) scripting that imports and processes a couple of XML files from GO’s servers, and then produces the info in the desired format.

The hardest part was persuading my (Windows) server to get the XML without complaining, so I reproduce the essential bit of code here to save others the hassle:

```Response.ContentType = "text/xml"
Set XMLDoc = Server.CreateObject("Msxml2.ServerXMLHTTP")
XMLDoc.open "GET", "http://www.[long URL cut to fit on one line]", false
XMLDoc.Send
Set Root = XMLDoc.responseXML.documentElement.firstChild```

(NB: if you’re debugging and need to view the raw xml, use Response.Write(XMLDoc.responseXML.xml) or similar)

Example train data can be found here, and the bus data can be found here, both for the Lakeshore West corridor. There is also a handy list of all data sources available. The bits in {braces} correspond to variables, most of which I’ve managed to decode. Some of the more interesting/less obvious ones are:

• {includeEquipmentTrip} = “true” or “false” : shows trains (maybe buses too) that aren’t in revenue service. You’ll see a *lot* of stuff around Union station from the three yards around it
• {isPublic} = “true” or “false” : When true, produces data is a slightly cleaned-up public-friendly version. Delays seem to be rounded to the nearest minute, for instance
• {serviceCd} / {serviceId} = “01″, “09″, “21″, “31″, “61″, “65″, or “71″ : The two-digit number corresponding to the corridor. Currently these seem to be the same, bus I suspect {serviceID} is detained to be route-specific for bus data, and {serviceCd} more broad.
• {lang} = “en” or “fr” : … although you don’t get anything different either way yet.
• {StationStatus} two- or three-digit station “number”. These don’t match with anything on GO’s website. If you look at an example station status output, the values of the “StopCode” attribute work as values for {StationStatus}. So 12=Danforth, 13=Scarborough, etc. I’ve compiled a full list.

Hopefully the internet can use all this data to produce new and ever-better mashups of GO’s comprehensive live data.

# About the Foscam NVISION FI18910W

The Foscam NVISION FI18910W is a wireless IP webcam, and I recently obtained one to use as part of a project involving… a wireless webcam. Overall, the camera itself has worked fine, but the supporting documentation is a bit lacking. So, a few points about it that I will share with other users in the hope that it’s useful

• You don’t need to install the software on the CD. I know because the CD arrived broken, andI had to cope without. You can access everything through a web browser once you know the IP address of the camera.
• The green LED beside the network port will blink rapidly when its connected wirelessly. It will take a while (~30 seconds after power-up)
• The IP address of the camera is generally different in wireless and non-wireless modes. Having carefully configured the wireless network access on the camera through the web interface, you’ll unplug the network cable, wait for the green LED to start blinking rapidly, refresh the browser… and get an sulky “page not found” from your browser. Add one to the last digit of the IP address and try again. (Or do whatever you did to find the wired IP address)
• You can fix the IP address, using the web interface, so its the same for wireless and wired. Just make sure the first three numbers remain the same as the ‘gateway’ (router IP). The DNS server IP should be the same as the gateway IP.
• You can access the video stream directly at http://[ip address]/videostream.cgi?user=[username]&pwd=[password]. It’s an MJPEG stream, and be viewed in your video playing software of choice.

# First post

The aim of this blog and collection of pages is to provide a place for to post all those things which aren’t directly associated with non-League football, and my ‘main’ website, thePyramid.info. These could relate to things like :

• Mathematics
• Ringing (as in change ringing) – particularly the theory thereof
• The Raspberry Pi (a \$35 credit-card sized computer)
• Transportation, especially transit
• Anything that tickles my fancy that I feel an urge to share with the world

The name of the site is intended to reflect the eclectic mixture – blocks are generally used to build bigger things, come in all shapes and sizes, and have a discrete existence in their own right.