# Quartal melody: Star Trek fanfare

Intervals of a fourth, such as the interval from C to F, are common in western music, but consecutive intervals of this size are not. Quartal harmony is based on intervals of fourths, and quartal melodies use a lot of fourths, particularly consecutive fourths.

Maybe the most famous quartal melody is the opening fanfare to Star Trek (original series). Here’s a transcription of the opening line:

And here is the same music with the intervals of a fourth circled.

The theme opens with two consecutive fourths, there’s an augmented fourth in the middle, then two more consecutive fourths. There are two major thirds in the phrase above, which you could call diminished fourths.

Incidentally, there are four bell tones before the melody above begins, and the interval between the first two tones is a fourth.

## Making the sheet music

Here’s the Lilypond source code I used to create the images above.

    \begin{lilypond}

\score {
\relative e'{
\time 4/4
\partial 2 a4. d8 |
\tuplet 3/2 {g4~ 4 ges4} \tuplet 3/2 {d4 b4 e4} |
a2 ~ 4 ~ 8 8 |
des1
}
\end{lilypond}


This uses a few Lilypond features I hadn’t used before.

• The \partial command for the two pickup notes.
• The \tuple command for the triples.
• The shortcut of not repeating the names repeated notes.

The last point applies twice, writing g4 4 rather than g4 g4 and writing a2 4 8 8 rather than a2 a4 a8 a8.

# Mathematics and piano tuning

The following is a slightly edited version of a Twitter thread on @AlgebraFact.

The lowest C on a piano is called C1 in scientific pitch notation. The C one octave up is C2 and so forth. Middle C is C4.

The frequency of Cn is approximately 2n+4 Hz. This would be exact if C0 were 16 Hz, but it’s a little flat. In order to make A4 have frequency 440 Hz, CO must have frequency 16.3516.

Notes other than C take their number from the nearest C below. So A4 is the A above C4, middle C. The lowest note on a standard piano, the A below C1, is A0.

At one point in time C0 was defined to be exactly 16 Hz. The frequencies of notes have been defined slightly differently across time and location.

Mathematically perfect octaves, however, don’t sound quite right. The highest notes on a piano would sound flat if every octave were exactly twice the frequency of the previous octave. So we tune the lowest notes a little lower than the math would say to, and the high notes higher.

In the original thread I said that C0 was the lowest C on a piano when I should have said C1.

No discussion of mathematics and piano tuning would be complete without mentioning Fermi problems. As I discuss here,

These problems are named after Enrico Fermi, someone who was known for being able to make rough estimates with little or no data.

A famous example of a Fermi problem is “How many piano tuners are there in New York?” I don’t know whether this goes back to Fermi himself, but it’s the kind of question he would ask. Of course nobody knows exactly how many piano tuners there are in New York, but you could guess about how many piano owners there are, how often a piano needs to be tuned, and how many tuners it would take to service this demand.

# Multiple Frequency Shift Keying

A few days ago I wrote about Frequency Shift Keying (FSK), a way to encode digital data in an analog signal using two frequencies. The extension to multiple frequencies is called, unsurprisingly, Multiple Frequency Shift Keying (MFSK). What is surprising is how MFSK sounds.

When I first heard MFSK I immediately recognized it as an old science fiction sound effect. I believe it was used in the original Star Trek series and other shows. The sound is in once sense very unusual, which is why it was chosen as a sound effect. But in another sense it’s familiar, precisely because it has been used as a sound effect.

Each FSK pulse has two possible states and so carries one bit of information. Each MFSK pulse has 2n possible states and so carries n bits of information. In practice n is often 3, 4, or 5.

## Why does it sound strange?

An MFSK signal will jump between the possible frequencies in no apparent; if the data is compressed before encoding, the sequence of frequencies will sound random. But random notes on a piano don’t sound like science fiction sound effects. The frequencies account for most of the strangeness.

MFSK divides its allowed bandwidth into uniform frequency intervals. For example, a 500 Hz bandwidth might be divided into 32 frequencies, each 500/32 Hz apart. The tones sound strange because they are uniformly on a linear scale, whereas we’re used to hearing notes uniformly spaced on a logarithmic scale. (More on that here.)

In a standard 12-note chromatic scale, the ratios between consecutive frequencies is constant, each frequency being about 6% larger than the previous one. More precisely, the ratio between consecutive frequencies equals the 12th root of 2. So if you take the logarithm in base 2, the distance between each of the notes is 1/12.

In MFSK the difference between consecutive frequencies is constant, not the ratio. This means the higher frequencies will sound closer together because their ratios are closer together.

## Pulse shaping

As I discussed in the post on FSK, abrupt frequency changes would cause a signal to use an awful lot of bandwidth. The same is true of MFSK, and as before the solution is to taper the pulses to zero on the ends by multiplying each pulse by a windowing function. The FSK post shows how much bandwidth this saves.

When I created the audio files below, at first I didn’t apply pulse shaping. I knew it was important to signal processing, but I didn’t realize how important it is to the sound: you can hear the difference, especially when two consecutive frequencies are the same.

## Audio files

The following files are a 5-bit encoding. They encode random numbers k from 0 to 31 as frequencies of 1000 + 1000k/32 Hz.

Here’s what a random sample sounds like at 32 baud (32 frequency changes per second) with pulse shaping.

32 baud

Here’s the same data a little slower, at 16 baud.

And here is is even slower, at 8 baud.

## Examples

Here’s one example I found: “Sequence 2” from
this page of sound effects sounds like a combination of teletype noise and MFSK. The G7 computer sounds like MFSK too.

# Dial tone and busy signal

Henry Lowengard left a comment on my post Phone tones in musical notation mentioning dial tones and busy signals, so I looked these up.

## Tones

According to this page, a dial tone in DTMF [1] is a chord of two sine waves at 350 Hz and 440 Hz. In musical notation:

According to the same page, a busy signal is a combination of 480 Hz and 620 Hz with pulses of 1/2 second.

Note that the bottom note is an B half flat, i.e. midway between a B and a B flat, denoted by the backward flat sign. The previous post on DTMF tones also used quarter tone notation because the frequencies don’t align well with a conventional chromatic scale. The frequencies were chosen to be easy to demodulate rather than to be musically in tune.

## Audio files

Here are audio files corresponding to the notation above.

## Lilypond code for music

Here is the Lilypond code that was used to make the images above.

    \begin{lilypond}
\new Staff \with { \omit TimeSignature} {
\relative c'{ 1 \fermata | }
}
\new Staff {
\tempo 4 = 120
\relative c''{
<beh dis> r4 <beh dis> r4 | <beh dis> r4 <beh dis> r4 |
}
}
\end{lilypond}


## Related posts

[1] Dual-tone multi-frequency signaling, trademarked as Touch-Tone

# Dividing an octave into 14 pieces

Keenan Pepper left a comment on my previous post saying that the DTMF tones used by touch tone phones “are actually quite close to 14 equal divisions of the octave (rather than the usual 12).”

Let’s show that this is right using a little Python.

    import numpy as np

freq = np.array([697, 770, 852, 941, 1209, 1336, 1477])
lg = np.log2(freq)
spacing = lg[1:] - lg[:-1]
print(spacing)
print([2/14, 2/14, 2/14, 5/14, 2/14, 2/14])


If the tones are evenly spaced on a 14-note scale, we’d expect the logarithms base 2 of the notes to differ by multiples of 1/14.

This produces the following:

    [0.144 0.146 0.143 0.362 0.144 0.145]
[0.143 0.143 0.143 0.357 0.143 0.143]


By dividing the octave into 14 points the DFMT system largely avoids overlap between the set of tones and the set of their harmonics. However, the first overtone of the first tone (1394 Hz) is kinda close to the fundamental of the 6th tone (1336 Hz).

# Phone tones in musical notation

The sounds produced by a telephone keypad are a combination of two tones: one for the column and one for the row. This system is known as DTMF (dual tone multiple frequency).

I’ve long wondered what these tones would be in musical terms and I finally went to the effort to figure it out when I ran across DTMF in [1].

The three column frequencies are 1209, 1336, and 1477 Hz. These do not correspond exactly to standard musical pitches. The first frequency, 1209 Hz, is exactly between a D and a D#, two octaves above middle C. The second frequency, 1336 Hz, is 23 cents [2] higher than an E. The third frequency, 1477 Hz, lands on an F#.

In approximate musical notation, these pitches are two octaves above the ones written below.

Notice that the symbol in front of the D is a half sharp, one half of the symbol in front of the F.

Similarly, the four row frequencies, starting from the top, are 697, 770, 852, and 941 Hz. In musical terms, these notes are F, G (31 cents flat), A (54 cents flat), and B flat (16 cents sharp).

The backward flat symbol in front of the A is a half flat. As with the column frequencies, the row frequencies are two octaves higher than written.

These tones are deliberately not in traditional harmony because harmonic notes (in the musical sense) are harmonically related (in the Fourier analysis sense). The phone company wants tones that are easy to pull apart analytically.

Finally, here are the chords that correspond to each button on the phone keypad.

Update: Dial tone and busy signal

## Related posts

[1] Electric Circuits by Nilsson and Riedel, 10th edition, page 548.
[2] A cent is 1/100 of a semitone.

# Morse code in musical notation

Maybe this has been done before, but I haven’t seen it: Morse code in musical notation.

Here’s the Morse code alphabet, one letter per measure; in practice there would be less space between letters [1]. A dash is supposed to be three times as long as a dot, so a dot is a sixteenth note and a dash is a dotted eighth note.

Morse code is often at a frequency between 600 and 800 Hz. I picked the E above middle C (660 Hz) because it’s in that range.

## Rhythm

Officially a dash is three times as long as a dot. But there’s also a space equal to the length of a dot between parts of a letter. So the sheet music above would be more accurate if you imagined all the sixteenth notes are staccato and the dotted eighth notes are really eighth notes followed by a sixteenth rest.

This doesn’t make much difference because individual operators have varying “fists,” styles of sending Morse code, and won’t exactly follow the official length and spacing rules.

You could rewrite the music above as follows, but it’s all an approximation.

## Tempo

According to Wikipedia, “the dit length at 20 words per minute is 50 milliseconds.” So if a sixteenth note has a duration of 50 milliseconds, this would mean five quarter notes per second, or 300 beats per minute. But according to this video, the shortest duration people can distinguish is about 50 milliseconds.

That would imply that copying Morse code at 20 wpm is pushing the limits of human hearing. But copying at 20 wpm is common. Some people can copy Morse code at more than 50 words per minute or more, but at that speed they’re not hearing individual dits and dahs. An H, for example, four dits in a row, sounds like a single rough sound. In fact, they’re not really hearing letters at all but recognizing the shape of words.

## How the image was made

I made the image above with LaTeX and Lilypond.

Adding the letters above each measure was kind of a hack. I used rehearsal markings to label the measures, but there was one problem: the software skips from letter H to letter J. That meant that the labels I and all subsequent letters were one ahead of what they should be, and the final letter Z was labeled AA. I tried several tricks, and Lilypond steadfastly refused to label a measure with ‘I’ even though I’ve seen such a label in the documentation.

My way around this was to make it label two consecutive measures with H, then in image editing software I turned the second H into an I. No doubt there’s a better way, but this worked.

I may play around with this and try to improve it a bit. If you have any suggestions, particularly related to Lilypond, please let me know.

## Related posts

[1] You could think of the musical score above as a sort of transcription of the Farnsworth method of teaching Morse code. Students learn the letters at full speed, but with extra space between the letters at first. The faster speed discourages consciously counting the dits and dahs, forcing the student to listen to the overall rhythm of the letters.

# O Come, O Come, Emmanuel: condensing seven hymns into one

The Christmas hymn “O Come, O Come, Emmanuel” is a summary of the seven “O Antiphons,” sung on December 17 though 23, dating back to the 8th century [1]. The seven antiphons are

1. O Sapientia
4. O Clavis David
5. O Oriens
6. O Rex Gentium
7. O Emmanuel

The corresponding verses of “O Come, O Come, Emmanuel” begin with the lines below.

1. O come, Thou Wisdom from on high
2. O come, o come, thou lord of might
3. O come, Thou Branch of Jesse’s stem
4. O come, Thou Key of David, come
5. O come, Thou Bright and Morning Star
6. O come, Desire of nations, bind
7. O come, O come, Emmanuel

[1] Mars Hill Audio Conversations O Come, O Come, Emmanuel: Malcolm Guite and J. A. C. Redford on the Advent O Antiphons

# Complexity below the surface

The other day I ran across a Rick Beato video entitled “The most complex pop song of all time.”

I thought the song would be something by a cerebral group like Rush, but instead it’s “Never Gonna Let You Go” by Sérgio Mendes. The song made it to #4 on the weekly pop charts in 1983 and came in at #16 for the year. I knew the song, but I would not have thought it was especially simple or complex.

The song works because the melody is simple enough but the harmony is complex. The complexity isn’t gratuitous, but serves the song. Millions of people thought the song was enjoyable, not impressive; you have to listen closely to be impressed.

I was reminded, as I often am, of the line from Feynman that nearly everything is really interesting if you look into it deeply enough. I wonder what other pop songs I’ve dismissed that have a lot going on if you listen more closely. And I wonder more generally what else around me is more interesting than I realize.

# Perfect fifths, octaves, and an ergodic map

In music, a perfect fifth is the interval between two notes whose frequencies are in 3:2 ratio. For example, the interval from an A at 440 Hz and an E at 660 Hz is a perfect fifth.

Going up by 12 perfect fifths is very nearly the same as going up 7 octaves. That is,

(3/2)12 ≈ 27

or in other words,

27/12 ≈ 3/2.

This is why equal temperament tuning works. More on that here.

## 53-note scale

Going back to our first approximation, we can say that (12, 7) is an approximate solution to the equation

(3/2)x = 2y.

One could naturally ask whether there are better approximate solutions. One such solution, dating back to 40 BC, came from the Chinese scholar King Fang [1]. He discovered that (53, 31) is a substantially more accurate solution than (12, 7), between 6 and 7 times better.

    >>> 1.5**12/2**7
1.0136432647705078
>>> 1.5**53/2**31
1.0020903140410862


In other words, going up 53 perfect fifths is nearly the same as going up 31 octaves. You could divide the octave into 53 parts using perfect fifths; we will demonstrate this visually below. However, we’re moving more the realm of number theory than practical music theory at this point.

## Powers of 2 and 3

We could change our problem slightly, making it mathematically simpler though less obviously related to music, by putting all our powers of 2 on one side and looking for powers of 3 that approximately equal powers of two. That is, we could look at approximate solutions to

3x = 2y.

where now x and y have different meanings; our new y is our old y plus our old x. No power of 3 will ever equal a power of 2, but you can find powers of 3 close to powers of 2, making the ratio as small as you’d like.

## Ergodic map

Taking the logarithm of both sides in base 2, we recast the problem as looking for integers n such that

log2(3) n

is approximately an integer.

If we define k = log2(3), we are looking for n such that kn mod 1, the integer part of kn, is near 0.

The map

nkn mod 1

is ergodic because k is irrational, and so its image in the unit interval is dense as n goes to infinity. This means we can find solutions as close we’d like to 0. It also means we can find solutions as close as we’d like to any other number in the interval.

Here’s a plot of our map for n up to 12.

Note that the range of the map falls very nearly on the 12 evenly-spaced horizontal lines. This corresponds to the circle of fifths filling in the 12 notes of the chromatic scale.

Now let’s keep going for n up to 53.

Look closely at the bottom of the plot. The graph gets close to 0 at 12, and it gets even closer to 0 at 53. The value of kn mod 1 doesn’t get smaller than the value at n = 53 until n = 359 where the value is about twice as small.

When we go up by 12 perfect fifths, we don’t end up exactly on the note we started on; 12 fifths is a little more than 7 octaves. If we keep going up in fifths we fill in notes a little higher than the original chromatic scale. Here’s a plot for n up to 24, with the values sorted so we can focus on the range rather than the ups and downs of filling in the range.

Every note in the original chromatic scale now has a counterpart that’s somewhere around 25 cents sharp.

If we keep going to n = 53, we fill in the octave more evenly. Here’s a plot of the sorted values.

## Related posts

[1] A. L. Leigh Silver. Some Musico-Mathematical Curiosities. The Mathematical Gazette , Feb., 1964, Vol. 48, No. 363 (Feb., 1964), pp. 1-17.