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.

Saxophone ranges

Saxophone quartet

I stumbled on a recording of a contrabass saxophone last night and wondered just how low it was [1], so I decided to write this post giving the ranges of each of the saxophones.

The four most common saxophones are baritone, tenor, alto, and soprano. These correspond to the instruments in the image above. There are saxophones below the baritone and above the soprano, but they’re rare.

Saxophones have roughly the same range as the human vocal parts with the corresponding names, as shown in the following table.

\begin{center} \begin{tabular}{lllrr} \hline Part & Sax SPN & Human SPN & Sax Hz & Human Hz\\ \hline Soprano & \(A \flat_3\) -- \(E \flat_6\) & \(C_4\) -- \(C_6\) & 208--1245 & 262--1047\\ Alto & \(D \flat_3\) -- \(A \flat_5\) & \(F_3\) -- \(F_5\) & 139--831 & 175--698\\ Tenor & \(A \flat_2\) -- \(E \flat_5\) & \(C_3\) -- \(C_5\) & 104--622 & 131--523\\ Baritone & \(D \flat_2\) -- \(A \flat_4\) & \(G_2\) -- \(G_4\) & 69--415 & 98--392\\ Bass & \(A \flat_1\) -- \(E \flat_4\) & \(E_2\) -- \(E_4\) & 52--311 & 82--330\\ \hline \end{tabular} \end{center}

SPN stands for scientific pitch notation, explained here. Hz stands for Hertz, vibrations per second.

The human ranges are convenient two-octave ranges. Of course different singers have different ranges. (Different saxophone players have different ranges too if you include the altissimo range.)

If you include the rare saxophones, the saxophone family has almost the same range as a piano. The lowest note on a subcontrabass saxophone is a half step lower than the lowest note on a piano, and the highest note on the sopranissimo saxophone is a few notes shy of the highest note on a piano.

\begin{center} \begin{tabular}{llr} \hline Part & Sax SPN & Sax Hz\\ \hline Sopranissimo & \(A \flat_4\) -- \(E \flat_7\) & 416--2490\\ Sopranino & \(D \flat_4\) -- \(A \flat_6\) & 277--1662\\ Soprano & \(A \flat_3\) -- \(E \flat_6\) & 208--1245\\ Alto & \(D \flat_3\) -- \(A \flat_5\) & 139--831\\ Tenor & \(A \flat_2\) -- \(E \flat_5\) & 104--622\\ Baritone & \(D \flat_2\) -- \(A \flat_4\) & 69--415\\ Bass & \(A \flat_1\) -- \(E \flat_4\) & 52--311\\ Contrabass & \(D \flat_1\) -- \(A \flat_3\) & 35--208\\ Subcontrabass & \(A \flat_0\) -- \(E \flat_3\) & 26--156\\ \hline \end{tabular} \end{center}

Update

My intent when I wrote this post was to add some visualization. One thought was to display the data above on a piano keyboard. That would be a nice illustration, but it would be a lot of work to create. Then it occurred to me that what putting things on a piano is really just a way of displaying the data on a log scale. So I plotted the frequency data on a log scale, which was much easier.

Saxophone and human voice ranges

More saxophone posts

[1] I could figure it out in terms of musical notation—you can see what a regular pattern the various saxes have in the table above—but I think more in terms of frequencies these days, so I wanted to work everything out in terms of Hz. Also, I’d always assumed that tenor saxes and tenor voices have about the same range etc., but I hadn’t actually verified this before.

Pitch of a big wine bottle

Yesterday my daughter came by and dropped off a huge blue wine bottle (empty).

Trader Joe's Incanto Chardonnay Pinot Grigio

She had started removing the label, but as you can see she didn’t get very far yet. It’s an Incanto Chardonnay Pinot Grigio from Trader Joe’s.

I blew across the top of the bottle to hear what sound it makes, and it makes a nice deep rumble.

I tried to identify the pitch using a spectrum analyzer app on my phone, and it says 63 Hz.

audio spectrum analyzer screen shot

Next I tried to figure out what pitch I should expect theoretically based on physics. Wine bottles are Helmholtz resonators, and there’s a formula for the fundamental frequency of Helmholtz resonators:

f = \frac{v}{2\pi} \sqrt{\frac{A}{LV}}

The variables in this equation are:

  • f, frequency in Hz
  • v, velocity of sound
  • A, area of the opening
  • L, length of the neck
  • V, volume

I measured the opening to be 3/4 of an inch across, and the neck to be about 7 inches. The volume is 1.5 liters. The speed of sound at sea level and room temperature is 343 meters per second. After a few unit conversions [1] I got a result of 56.4 Hz, about 10% lower than what the spectrum analyzer measured.

An ideal Helmholtz resonator has a cylindrical neck attached to a spherical body. This bottle is far from spherical. The base is an ellipse with a major axis about twice as long as the minor axis. And from there it tapers off more like a cone than a sphere [2]. And yet the frequency predicted by Helmholtz’ formula comes fairly close to what I measured empirically.

I suspect I got lucky to some extent. I didn’t measure the bottle that accurately; it’s hard to even say when the neck of the bottle stops. But apparently Helmholtz’ formula is robust to changes in shape.

Update: Pitch of a beer bottle

I repeated my experiment with a beer bottle, specifically a Black Venom Imperial Stout.

Black Venom Imperial Stout

The opening diameter is about 3/4″, as with the wine bottle above, and the neck is about 3″ long. The volume is 12 fluid ounces. Helmholtz’ formula predicts a pitch of 177 Hz. My spectrum analyzer measured 191 Hz, the G below middle C. So this time theory was about 7% lower than the observed value.

Spectral analysis of blowing across beer bottle

The beer bottle is closer to the shape of a Helmholtz resonator than the wine bottle was. It’s at least radially symmetric, but the body is a cylinder rather than a sphere.

Update 2: Typical wine bottle

When I tested a typical 750 ml wine bottle, I got a pitch of 114 Hz. With a 3.5 inch neck and a 0.75 in diameter opening, the calculated pitch was 113 Hz. There’s some element of luck that theory and measurement agree so well, especially since the punt at the bottom means its shape is even further from spherical than that of a beer bottle.

Audio spectrum of a 750 ml pinot noir bottle

More acoustics posts

[1] Thanks to a reader who provided this write-up of the calculation:

calculation with dimensions

[2] What we usually call a cone is more specifically a right circular cone. But more generally a cone can have any base, not just a circle, and this bottle is approximately an elliptical cone.

The Crown and The Planets

I first heard the hymn “I Vow to Thee, My Country” while watching the first season of The Crown [1]. I assume the hymn is familiar in the UK, but it is not in America as far as I know.

When I say I first heard the hymn, I mean that I first heard it as a hymn with words. I thought the tune sounded familiar, and that it reminded me of The Planets by Holst.

I’ve started watching the latest season of The Crown and once again I heard the hymn [2], so this time I looked into it more. The tune does indeed come from The Planets, specifically from the middle of the Jupiter movement.

With a little searching I found the sheet music to the hymn.

Sheet music for the tune Thaxted

This brought up more things I’ve long meant to look into. As a child I remember cryptic notations around hymns, such as “Thaxted 13.13.13 D” above, and never knew what they meant.

Tunes have names independent of the hymns they appear in, but these tune names were, and still are, completely unfamiliar to me. For example, the hymn “Amazing Grace” has the tune “McIntosh,” though I don’t imagine many people know that.

In the example here, “Thaxted” is the name of the melody from Jupiter when it is used as a hymn. The name comes from the English town of Thaxted where Holst lived. Perhaps there are other hymns that use the same tune.

Now what about the mysterious numbers 13.13.13? They mean that the hymn is built out of groups of three lines, each with 13 syllables. The hymn Once in Royal David’s City is marked 87 87 77, meaning the hymn has three phrases, the first two alternating lines of 8 and 7 syllables, and the last having two lines of 7 syllables each.

From what I’ve read, the “D” in “13.13.13 D” stands for double meter, which I would take to mean 2/4, but the tune is clearly in 3/4, so I’m not sure what the D means.

Update: The D means the entire pattern is doubled, not that the meter is double time. Thaxted has six lines, in two groups of three. Thanks to Michael Lugo for letting me know via Twitter.

***

[1] S1E1 10:00

[2] S4E3 40:30

 

Lee distance: codes and music

The Hamming distance between two sequences of symbols is the number of places in which they differ. For example, the Hamming distance between the words “hamming” and “farming” is 2, because the two worlds differ in their first and third letters.

Hamming distance is natural when comparing sequences of bits because bits are either the same or different. But when the sequence of symbols comes from a larger alphabet, Hamming distance may not be the most appropriate metric.

Here “alphabet” is usually used figuratively to mean the set of available symbols, but it could be a literal alphabet. As English words, “hamming” seems closer to “hanning” than to “farming” because m is closer to n, both in the alphabet and phonetically, than it is to f or r. [1]

The Lee distance between two sequences x1x2xn and y1y2yn of symbols from an alphabet of size q is defined as

\sum_{i=1}^n \min\{ |x_i - y_i|, q - |x_i - y_i| \}

So if we use distance in the English alphabet, the words “hamming” and “hanning” are a Lee distance of 1 + 1 = 2 apart, while “hamming” and “farming” are a Lee distance of 2 + 5 = 7 apart.

Coding theory uses both Hamming distance and Lee distance. In some contexts, it only matters whether symbols are different, and in other contexts it matters how different they are. If q = 2 or 3, Hamming distance and Lee distance coincide. If you’re working over an alphabet of size q > 3 and symbols are more likely to be corrupted into nearby symbols, Lee distance is the appropriate metric. If all corruptions are equally likely, then Hamming distance is more appropriate.

Application to music

Lee distance is natural in music since notes are like integers mod 12. Hence the circle of fifths.

My wife and I were discussing recently which of two songs was in a higher key. My wife is an alto and I’m a baritone, so we prefer lower keys. But if you transpose a song up so much that it’s comfortable to sing an octave lower, that’s good too.

If you’re comfortable singing in the key of C, then the key of D is two half-steps higher. But what about they key of A? You could think of it as 9 half-steps higher, or 3 half-steps lower. In the definition of Lee distance, measured in half-steps, the distance from C to D is

min{2, 12 – 2} = 2,

i.e. you could either go up two half-steps or down 10. Similarly the distance between C and A is

min{9, 12-9} = 3.

So you could think of the left side of the minimum in the definition of Lee distance as going up from x to y and the right side as going down from x to y.

Using Lee distance, the largest interval is the tritone, the interval from C to F#. It’s called the tritone because it is three whole steps. If C is your most comfortable key, F# would be your least comfortable key: the notes are as far away from your range as possible. Any higher up and they’d be closer because you could drop down an octave.

The tritone is like the hands of a clock at 6:00. The hour and minute hands are as far apart as possible. Just before 6:00 the hands are closer together on the left side of the clock and just after they are closer on the right side of the clock.

Related posts

[1] I bring up “Hanning” because Hamming and Hanning are often confused. In signal processing there is both a Hamming window and a Hanning window. The former is named after Richard Hamming and the latter after Julius von Hann. The name “Hanning window” rather than “Hann window” probably comes from the similarity with the Hamming window.

Python and the Tell-Tale Heart

I was browsing through SciPy documentation this evening and ran across a function in scipy.misc called electrocardiogram. What?!

It’s an actual electrocardiogram, sampled at 360 Hz. Presumably it’s included as convenient example data. Here’s a plot of the first five seconds.

ECG plot

I wrote a little code using it to turn the ECG into an audio file.

from numpy import int16, iinfo
from scipy.io.wavfile import write
from scipy.misc import electrocardiogram

def to_integer(signal):
    # Take samples in [-1, 1] then scale to 16-bit integers
    m = iinfo(int16).max
    M = max(abs(signal))
    return int16(signal*m/M)

ecg = electrocardiogram()
write("heartbeat.wav", 360, to_integer(ecg))

I had to turn the volume way up to hear it, and that made me think of Edgar Allan Poe’s story The Tell-Tale Heart.

I may be doing something wrong. According to the documentation for the write function, I shouldn’t need to convert the signal to integers. I should just be able to leave the signal as floating point and normalize it to [-1, 1] by dividing by the largest absolute value in the signal. But when I do that, the output file will not play.

Related posts

Updated pitch calculator

I’ve made a couple minor changes to my page that converts between frequency and pitch. (The page also includes Barks, a psychoacoustic unit of measure.)

If you convert a frequency in Hertz to musical notation, the page used to simply round to the nearest note in the chromatic scale. Now the page will also tell you how sharp or flat the pitch is if it’s not exact.

For example, if you enter 1100 Hz, the page used to report simply “C#6” and now it reports “C#6 – 14 cents” meaning the closest note is C#6, but it’s a little flat, 14/100 of a semitone flat. If you enter 1120 Hz it will report “C#6 + 18 cents” meaning that the note is 18/100 of a semitone sharp.

Octave numbers, such as the 6 in C#6 are explained here.

The other change I made to the page was to add a little eighth note favicon that might show up in a browser tab.

pitch converter favicon

I’ve written several online converters like this: LaTeX to Unicode, wavelength to RGB, etc. See a full list here.

 

 

Saxophone with short bell

Paul A. sent me a photo of his alto sax in response to my previous post on a saxophone with two octave keys. His saxophone also has two octave keys, and it has a short bell. Contemporary saxophones have a longer bell, go down to B flat, and have two large pads on the bell. Paul’s saxophone has a shorter bell, only goes down to B, and only has one pad on the bell.

Alto sax with short bell

Here’s a closeup of the octave keys.

Two octave keys

Paul says he found his instrument in an antique shop. It has no serial number or manufacturer information. If you know anything about this model, please leave a comment below.

Saxophone blog posts

All possible scales

Pete White contacted me in response to a blog post I wrote enumerating musical scales. He has written a book on the subject, with audio, that he is giving away. He asked if I would host the content, and I am hosting it here.

Here are a couple screen shots from the book to give you an idea what it contains.

Here’s an example scale, number 277 out of 344.

scale 277

And here’s an example of the notes for the accompanying audio files.

sheet music example, track 22