Tuning Systems#

import IPython.display as ipd
import matplotlib.pyplot as plt
import numpy
import scipy
import scipy.signal

from mirdotcom import mirdotcom

mirdotcom.init()

Introduction#

Tuning Systems#

In twelve-tone equal temperament (Wikipedia), all twelve semitones within the octave have the same width. With this tuning system, expressed as a frequency ratio, the interval of one semitone is \(2^{1/12}\). Expressed in cents, this same interval is defined to be 100 cents. Therefore, the octave has 1200 cents.

In just intonation (Wikipedia), the frequency ratio is expressed as a fraction between two small integers, e.g. 3:2, 4:3. As a result, the higher harmonic partials between two notes will overlap, resulting in a consonant interval that is pleasing to the ear. In 5-limit just tuning, these fractions are expressed with prime factors no larger than 5, i.e. {2, 3, 5}. In 7-limit just tuning, these fractions are expressed with prime factors no larger than 7, i.e. {2, 3, 5, 7}. For example, 7:4 is a 7-limit interval, but it is not a 5-limit interval.

In Pythagorean tuning (Wikipedia), every frequency ratio is based upon the ratio 3:2. To find that ratio, from one note in the interval, step around the Circle of Fifths until you reach the other note in the interval, multiplying (if stepping forward) or dividing (if stepping backward) by 3/2 with each step. Finally, multiply or divide by 2 enough times to return to the octave of interest. Pythagorean tuning can also be considered 3-limit just tuning since every ratio only uses prime factors no greater than 3.

How To Use This Notebook#

In the examples below, listen to each interval, and compare intervals both visually and aurally across tuning systems. In some tuning systems, the upper harmonics do not align. In such cases, try to listen for dissonance and beat frequencies. Then compare them to the tuning systems where the harmonics align perfectly.

Notebook Setup#

Global parameters for this notebook:

T = 5  # duration in seconds
sr = 22050  # sampling rate in Hertz
fcutoff = 4000  # frequency cutoff for filter

Functions used to create the sounds and figures:

def simulate_tone(f0, harmonics=None):
    """Returns a tone with a specified fundamental frequency and harmonic amplitudes."""
    if harmonics is None:
        harmonics = [1]
    t = numpy.linspace(0, T, T * sr, endpoint=False)
    x = sum(
        v * numpy.sin(2 * numpy.pi * i * f0 * t) for i, v in enumerate(harmonics, 1)
    )
    return x
def filter_tone(x, fcutoff=None):
    """Return a low-pass filtered signal."""
    if fcutoff is None:
        fcutoff = sr / 2.0
    h = scipy.signal.firwin(55, 2 * float(fcutoff) / sr)
    y = scipy.signal.convolve(x, h)
    return y
def make_double_stop(ratio, f0=440, harmonics=None):
    """Listen to two tones played simultaneously, and plot the tones' spectra."""
    if harmonics is None:
        harmonics = [1]
    f1 = ratio * f0

    # Generate both tones.
    x0 = filter_tone(simulate_tone(f0, harmonics=harmonics), fcutoff=fcutoff)
    x1 = filter_tone(simulate_tone(f1, harmonics=harmonics), fcutoff=fcutoff)

    # Add both tones, and normalize.
    y = x0 + x1
    y = 0.5 * y / y.max()

    # Generate both spectra.
    X0 = scipy.fft.fft(x0)
    X1 = scipy.fft.fft(x1)

    # Create frequency variable.
    N = len(X0)
    f = numpy.linspace(0, sr, N, endpoint=False)

    # Plot spectrum of both notes.
    plt.semilogy(f, abs(X0), marker="o", linewidth=1)
    plt.semilogy(f, abs(X1), color="r", linewidth=1)

    plt.xlim(xmin=0, xmax=(len(harmonics) + 1) * (f1 if ratio > 1 else f0))
    plt.ylim(ymin=0.1)

    plt.xlabel("Frequency (Hz)")
    plt.ylabel("Magnitude")
    plt.legend(("f0 = %.2f Hz" % f0, "f0 = %.2f Hz" % f1))

    # Output audio widget.
    print("ratio between notes:", ratio)
    print("difference in cents:", numpy.log2(ratio) * 1200)
    return ipd.Audio(y, rate=sr)

Unison#

Within each section below, the intervals are provided in order of interval width from lowest to highest.

make_double_stop(1)
ratio between notes: 1
difference in cents: 0.0
../../_images/2b7d66d4365a1a952d17287a7fffec0ac7158630ffc56e7d26b33bf2fcd81476.png

Octaves#

harmonics = [1.0, 0.5]

Just intonation or equal temperament, 12 semitones, 1200 cents:

make_double_stop(2, harmonics=harmonics)
ratio between notes: 2
difference in cents: 1200.0
../../_images/a5996d8b3154bb9f47e25b9eca6c0507e67ed4aa06aa3eeb9d1d0a8f40c61141.png

Pythagorean tuning, twelve steps forward on the Circle of Fifths. In Pythagorean tuning, multiply the fundamental frequency by 3/2 twelve times, and then divide by two enough times to return to the octave of interest:

\[ \left( \frac{3}{2} \right)^{12} \left( \frac{1}{2} \right)^6 = \frac{531441}{262144} \approx 2.0273 \]
make_double_stop(531441.0 / 262144, harmonics=harmonics)
ratio between notes: 2.0272865295410156
difference in cents: 1223.4600103846492
../../_images/cce6ce7a81e939c33553bac6dfa59d1fe12f4b56ca8d52b94732ef9aa04dc0b2.png

The Pythagorean comma, the degree of inconsistency when trying to define a twelve-tone scale using only perfect fifths, is about 1.0136 when expressed as a frequency ratio:

\[ \left( \frac{3}{2} \right)^{12} \left( \frac{1}{2} \right)^7 = \frac{531441}{524288} \approx 1.0136 \]

Fifths#

harmonics = [1.0, 0.1, 0.1]

Equal temperament, seven semitones, 700 cents:

make_double_stop(2 ** (7.0 / 12), harmonics=harmonics)
ratio between notes: 1.4983070768766815
difference in cents: 700.0
../../_images/0bb93c75d0299d950881557293449740825d98c86d66906a0e04c8fc2ed77bfe.png

Just intonation or Pythagorean tuning, one step forward on the Circle of Fifths:

make_double_stop(3.0 / 2, harmonics=harmonics)
ratio between notes: 1.5
difference in cents: 701.9550008653874
../../_images/f913b21458f7483125ad2acb292b45e0f9e4d8632ebbcbca04b50ea2c77c20fa.png

Fourths#

harmonics = [1.0, 0.01, 0.1, 0.1]

Just intonation or Pythagorean tuning, one step backward on the Circle of Fifths:

\[ \left( \frac{2}{3} \right) \left( \frac{2}{1} \right) = \frac{4}{3} = 1.\overline{3} \]
make_double_stop(4.0 / 3, harmonics=harmonics)
ratio between notes: 1.3333333333333333
difference in cents: 498.0449991346125
../../_images/3c0970bc13a31e27488b8f8b8483e66b7bd72c4354b8f3b443745903b17c22fd.png

Equal temperament, five semitones:

make_double_stop(2 ** (5.0 / 12), harmonics=harmonics)
ratio between notes: 1.3348398541700344
difference in cents: 500.0
../../_images/a5d7bb85e5a1bec5dc49cbe66f60da60d9ec02b67653ef0d70a23c410ab70435.png

Major Sixths#

harmonics = [1.0, 0.01, 0.1, 0.01, 0.1]

Just intonation:

make_double_stop(5.0 / 3, harmonics=harmonics)
ratio between notes: 1.6666666666666667
difference in cents: 884.3587129994474
../../_images/989cca7089fe2b41a472aa650815e331fa07979ee0e218944ee74c276164ede5.png

Equal temperament, i.e. nine semitones:

make_double_stop(2 ** (9.0 / 12), harmonics=harmonics)
ratio between notes: 1.681792830507429
difference in cents: 899.9999999999999
../../_images/7a362bf4491c8b6efedc4f743813f3656408b32d58d2dcddab77e68a479838ed.png

Pythagorean tuning, three steps forward on the Circle of Fifths:

\[ \left( \frac{3}{2} \right)^3 \left( \frac{1}{2} \right) = \frac{27}{16} = 1.6875 \]
make_double_stop(27.0 / 16, harmonics=harmonics)
ratio between notes: 1.6875
difference in cents: 905.8650025961623
../../_images/c351d241981b7a0c1a0935a95197edf948c326de16d14350260335920fa5082b.png

Minor Thirds#

harmonics = [1.0, 0.01, 0.01, 0.01, 0.1, 0.1]

Pythagorean tuning, three steps backward on the Circle of Fifths:

\[ \left( \frac{2}{3} \right)^3 \left( \frac{2}{1} \right)^2 = \frac{32}{27} = 1.\overline{185} \]
make_double_stop(32.0 / 27, harmonics=harmonics)
ratio between notes: 1.1851851851851851
difference in cents: 294.13499740383764
../../_images/e7c12dff2c82552c1f1fe607426a3937876501c373c46f4556b905b1e6fad638.png

Equal temperament, three semitones:

make_double_stop(2 ** (3.0 / 12), harmonics=harmonics)
ratio between notes: 1.189207115002721
difference in cents: 299.99999999999994
../../_images/8213b9594c83000417bbd7f4c309844438cc2d5f315a32d8400beb30324332ef.png

Just intonation:

make_double_stop(6.0 / 5, harmonics=harmonics)
ratio between notes: 1.2
difference in cents: 315.64128700055255
../../_images/ef3d066445538b89b7123aa7d391a45f4970161485f42707721992e24bac807a.png

Major Thirds#

harmonics = [1.0, 0.01, 0.01, 0.1, 0.1]

Just intonation:

make_double_stop(5.0 / 4, harmonics=harmonics)
ratio between notes: 1.25
difference in cents: 386.3137138648348
../../_images/45c25c8f29f97cefee6af2f3d806c78afa6286452e7b0bfdc894667144ecaa78.png

Equal temperament, four semitones:

make_double_stop(2 ** (4.0 / 12), harmonics=harmonics)
ratio between notes: 1.2599210498948732
difference in cents: 400.00000000000006
../../_images/e99839db952cc6cbf3aa5f486cdb5ed31ed1bc8391135f97dd19b174092d07d1.png

Pythagorean tuning, four steps forward on the Circle of Fifths:

\[ \left( \frac{3}{2} \right)^4 \left( \frac{1}{2} \right)^2 = \frac{81}{64} = 1.265625 \]
make_double_stop(81.0 / 64, harmonics=harmonics)
ratio between notes: 1.265625
difference in cents: 407.8200034615497
../../_images/696acd62f01003b34968a77d1e3f245cad80301c02192719f32576623fe44318.png

Minor Sixths#

harmonics = [1.0, 0.001, 0.001, 0.001, 0.01, 0.001, 0.001, 0.01]

Pythagorean tuning, four steps backward on the Circle of Fifths:

\[ \left( \frac{2}{3} \right)^4 \left( \frac{2}{1} \right)^3 = \frac{128}{81} \approx 1.58 \]
make_double_stop(128.0 / 81, harmonics=harmonics)
ratio between notes: 1.5802469135802468
difference in cents: 792.1799965384502
../../_images/ff97eaa23b4572fa139be915d619381384268cdcca144a87828bb2147fb0d704.png

Equal temperament, eight semitones:

make_double_stop(2 ** (8.0 / 12), harmonics=harmonics)
ratio between notes: 1.5874010519681994
difference in cents: 799.9999999999998
../../_images/59144a04b2bc4466be051a0e43a0751858b727f590e8393a0c82ee60ddf34c93.png

Just intonation:

make_double_stop(8.0 / 5, harmonics=harmonics)
ratio between notes: 1.6
difference in cents: 813.6862861351652
../../_images/e4e7d5835442bcf182176c3c36d1dcd9df35f98489fd1fa4d168499501859e2e.png

Major Seconds#

harmonics = [1.0, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.1, 0.1, 0.1]

In just intonation, there are two versions of the major second: the major tone a.k.a. greater tone (9:8), and the minor tone a.k.a. lesser tone (10:9). The difference between the two, expressed as a ratio of their widths, is called a syntonic comma and is equal to 81:80.

\[ \frac{10}{9} n = \frac{9}{8} \Rightarrow n = \frac{81}{80} \]

Just intonation (minor tone a.k.a. lesser tone). Observe how the tenth harmonic of the lower note aligns with the ninth harmonic of the upper note.

make_double_stop(10.0 / 9, harmonics=harmonics)
ratio between notes: 1.1111111111111112
difference in cents: 182.40371213406007
../../_images/1121b2effb5079e21f9902dda8611e1ef1abe91a2a717639d4c91e573ea6e7f4.png

Equal temperament, two semitones:

make_double_stop(2 ** (2.0 / 12), harmonics=harmonics)
ratio between notes: 1.122462048309373
difference in cents: 200.00000000000006
../../_images/b89962b89ec55964da2e875e8238d3eefbc31035393a978513b1d3ca3a188ff9.png

Just intonation (major tone a.k.a. greater tone) or Pythagorean tuning, two steps forward on the Circle of Fifths:

\[ \left( \frac{3}{2} \right)^2 \left( \frac{1}{2} \right) = \frac{9}{8} = 1.125 \]

Observe how the ninth harmonic of the lower note aligns with the eighth harmonic of the upper note.

make_double_stop(9.0 / 8, harmonics=harmonics)
ratio between notes: 1.125
difference in cents: 203.91000173077484
../../_images/d3b9b51a02972486b7a03330aa564543cb1ca11b961e0201ab4bee95de71cc28.png

Minor Sevenths#

harmonics = [1.0, 0.01, 0.01, 0.1, 0.1, 0.01, 0.1, 0.01, 0.1]

7-limit just intonation, a.k.a. septimal minor seventh, harmonic seventh, or subminor seventh:

make_double_stop(7.0 / 4, harmonics=harmonics)
ratio between notes: 1.75
difference in cents: 968.8259064691249
../../_images/74eeac5f7dc74721e4fd9185be20adcd8905c327eaf38b87778a9d97bdf99aa2.png

Pythagorean tuning, two steps backward on the Circle of Fifths, or small just minor seventh:

\[ \left( \frac{2}{3} \right)^2 \left( \frac{2}{1} \right)^2 = \frac{16}{9} = 1.\overline{7} \]
make_double_stop(16.0 / 9, harmonics=harmonics)
ratio between notes: 1.7777777777777777
difference in cents: 996.089998269225
../../_images/0dc9219b92e0db2c6b50f00eb9b4f68cd2ecd84525c0d413b72975c6b6a4bce7.png

Equal temperament, ten semitones:

make_double_stop(2 ** (10.0 / 12), harmonics=harmonics)
ratio between notes: 1.7817974362806785
difference in cents: 999.9999999999999
../../_images/bff8faeaec5033dd8e4d5cef1971aef6431d7581e052ee445a23b3def7573da7.png

5-limit just intonation, a.k.a. large just minor seventh:

make_double_stop(9.0 / 5, harmonics=harmonics)
ratio between notes: 1.8
difference in cents: 1017.5962878659401
../../_images/b7b73d4f10a0df07288bc16c3e53ac397a2dfe78e3ef815a331dffe37b5d3090.png

Major Sevenths#

harmonics = [
    1.0,
] * 15

Just intonation:

make_double_stop(15.0 / 8, harmonics=harmonics)
ratio between notes: 1.875
difference in cents: 1088.2687147302222
../../_images/8cd519d47985399969d92b84a415a9036f54398677659da981a471aa7ffdbae5.png

Equal temperament, eleven semitones:

make_double_stop(2 ** (11.0 / 12), harmonics=harmonics)
ratio between notes: 1.8877486253633868
difference in cents: 1099.9999999999998
../../_images/3ef15c98dfc16a3d0dcdb676ebfc012248b3fa7dee2f1ceb3e342ed089a37241.png

Pythagorean tuning, five steps forward on the Circle of Fifths:

\[ \left( \frac{3}{2} \right)^5 \left( \frac{1}{2} \right)^2 = \frac{243}{128} \approx 1.8984 \]
make_double_stop(243.0 / 128, harmonics=harmonics)
ratio between notes: 1.8984375
difference in cents: 1109.775004326937
../../_images/00e673728e294752f8b05a6d98eee1f2b1bfb069d2f7848a431475aff5e700fe.png

Minor Seconds#

harmonics = [
    0.01,
] * 16
harmonics[0] = 1.0
harmonics[14] = 0.1
harmonics[15] = 0.1

Pythagorean tuning, five steps backward on the Circle of Fifths:

\[ \left( \frac{2}{3} \right)^5 \left( \frac{2}{1} \right)^3 = \frac{256}{243} \approx 1.0535 \]
make_double_stop(256.0 / 243, harmonics=harmonics)
ratio between notes: 1.0534979423868314
difference in cents: 90.22499567306306
../../_images/6c42216d46b55d2316d288700be9d7b14ab340ebef1a9080e0bab719a497c758.png

Equal temperament, one semitone:

make_double_stop(2 ** (1.0 / 12), harmonics=harmonics)
ratio between notes: 1.0594630943592953
difference in cents: 100.00000000000007
../../_images/79b4a0662d4ad7b9214a0daf94cbd2b957f3f892a6aa01ac57bdba0c05f36f05.png

Just intonation:

make_double_stop(16.0 / 15, harmonics=harmonics)
ratio between notes: 1.0666666666666667
difference in cents: 111.73128526977774
../../_images/0569ba948341c8cbceb8a2220e90852e3b8572b0eb3ac8d72fc4c1c93c6ba75f.png

Tritone, Augmented Fourths, Diminished Fifths#

Diminished fifth, Pythagorean tuning, six steps backward on the Circle of Fifths:

\[ \left( \frac{2}{3} \right)^6 \left( \frac{2}{1} \right)^4 = \frac{1024}{729} \approx 1.40466 \]
make_double_stop(1024.0 / 729)
ratio between notes: 1.4046639231824416
difference in cents: 588.2699948076754
../../_images/bfd24e19b2c4203d5dc84089cfc7054ce7c7e6966617bf6ca79f0147e4f110c8.png

Augmented fourth:

make_double_stop(45.0 / 32)
ratio between notes: 1.40625
difference in cents: 590.2237155956096
../../_images/76fff7041760386c3c62bd6ba4abcb048569590800debd564cea61f4039cd3dd.png

Equal temperament, six semitones, 600 cents:

make_double_stop(2 ** (6.0 / 12))
ratio between notes: 1.4142135623730951
difference in cents: 600.0000000000001
../../_images/c5523342003d4a946efaaa4ddddbcbc3f61ac7c353967bfc904b66ce40aee01d.png

Diminished fifth:

make_double_stop(64.0 / 45)
ratio between notes: 1.4222222222222223
difference in cents: 609.7762844043904
../../_images/2900f2ae22766dccfb542c1c622b7c88d52691bc95b220ebfcf70aa3c6761b5c.png

Augmented fourth, Pythagorean tuning, six steps forward on the Circle of Fifths:

\[ \left( \frac{3}{2} \right)^6 \left( \frac{1}{2} \right)^3 = \frac{729}{512} \approx 1.4238 \]
make_double_stop(729.0 / 512)
ratio between notes: 1.423828125
difference in cents: 611.7300051923246
../../_images/e589126597711a90c3ad1790c09e28132fad1a99b94e2785ffbe94c8defd1fc4.png