Two notes sound smooth together when their frequencies make a simple ratio, like 3 to 2. Build a scale from those ratios and you hit a snag: stacking perfect fifths never lands exactly on an octave. Modern pianos fix this by splitting the octave into twelve equal steps, which puts almost every interval slightly out of tune. This page measures by how much.
A note's frequency is how many times per second the air vibrates, in hertz (Hz). An interval is two notes heard together, described by the ratio of their frequencies. When the ratio is made of small whole numbers, the two waves line up again after only a few cycles, so their sum is a short pattern that repeats. Real instruments also vibrate at whole-number multiples of the main frequency, called overtones or harmonics (see S00 · Waves & harmonics). A simple ratio makes many overtones of the two notes coincide exactly. Overtones that land close together without matching cause a fast wobble called beating, which the ear hears as roughness.
How to read this: the top three rows show the two notes and their sum, with a small dot sliding along each to mark playback. With a simple ratio the sum repeats quickly (gold dashed lines). The middle part lays out each note's overtones as ticks along a pitch line: gold links are overtones that match perfectly, red links are near-misses that sound rough. In the bottom strip, the dips line up with simple ratios like 3:2 and 2:1, the intervals that sound smooth. Click the strip to jump to the nearest interval.
Try this: click Fifth, then Half step, and watch the gold links vanish and the red ones multiply.
In one period T the lower wave fits exactly q cycles and the upper wave fits exactly p. The number 1/T is the greatest common divisor of the two frequencies, which 003 · Euclid's algorithm finds. Every p-th overtone of the lower note matches an overtone of the upper note.
The lower strip is a model of how rough two tones sound. Each note here has six harmonics with strengths 1, ½, ⅓ and so on. Every pair of harmonics adds roughness when the pair sits close together, peaking at about a quarter of the ear's critical band (a range of frequencies the inner ear can't fully separate). The curve shape comes from listening tests by Plomp and Levelt (1965), using a formula fitted by William Sethares. The dips fall on the simple ratios. With pure sine tones, which have no overtones, most of those dips vanish. Treat it as a toy model: it ignores musical context and the richer overtones of real instruments, and with only six harmonics it rates the tritone a little smoother than the major third.
from math import exp, gcd, log2
def interval(f_low, p, q):
g = gcd(p, q); p, q = p // g, q // g
f_high = f_low * p / q
period_ms = 1000 * q / f_low # sum repeats after q low cycles
cents = 1200 * log2(p / q)
shared = [(n, n // p * q) for n in range(1, 17) if n % p == 0]
return f_high, period_ms, cents, shared
def roughness(f1, f2, partials=6):
# Plomp-Levelt curve, Sethares' fit; harmonic k has amplitude 1/k
total = 0.0
for i in range(1, partials + 1):
for j in range(1, partials + 1):
a, b = i * f1, j * f2
s = 0.24 / (0.0207 * min(a, b) + 18.96)
x = s * abs(a - b)
total += min(1 / i, 1 / j) * (exp(-3.5 * x) - exp(-5.75 * x))
return total
print(interval(220, 3, 2))
# (330.0, 9.09..., 701.955..., [(3, 2), (6, 4), (9, 6), (12, 8), (15, 10)])
for p, q in [(2, 1), (3, 2), (5, 4), (45, 32), (16, 15)]:
print(p, q, round(roughness(220, 220 * p / q), 3))
A perfect fifth multiplies frequency by 3/2. An octave doubles it, and the ear hears notes an octave apart as "the same note, higher". So you can climb by fifths and fold each new note back down by octaves into one octave. Twelve fifths visit all twelve piano notes and should return to the start. They come back a little high. To measure small gaps like this, musicians use cents: one octave is 1200 cents and one piano step is 100 cents.
How to read this: each amber step is one perfect fifth, and the path spirals outward as you climb. If fifths and octaves fit perfectly, the red end dot would land exactly on the green start. The red arc is the leftover gap, measured in cents (¢), hundredths of a piano half step.
Try this: press Animate climb, then compare 12 with 53: the red gap nearly disappears.
Cents use a logarithm so that stacking intervals means adding cents. A pure fifth is 1200·log2(1.5) ≈ 701.955 cents. Twelve of them make 8423.46 cents, and seven octaves make 8400.
Closing the circle would need 3a = 2b for some whole numbers a and b. The left side is odd and the right side is even, so it never happens. Every whole number factors into primes in only one way, and powers of 3 never share a factor with powers of 2.
Some counts come closer than others. 12, 41 and 53 are denominators of the continued-fraction approximations to log2(3/2) ≈ 0.58496 (the same tool as in 001 · Golden ratio). That's why 12 notes per octave works so well.
from fractions import Fraction
from math import log2
def cents(ratio):
return 1200 * log2(ratio)
comma = Fraction(3, 2) ** 12 / Fraction(2) ** 7
print(comma, float(comma), cents(comma))
# 531441/524288 1.0136432647705078 23.460010384649...
fifth = cents(1.5) # 701.955 cents
for n in (5, 7, 12, 41, 53):
total = n * fifth
octaves = round(total / 1200)
print(n, octaves, round(total - 1200 * octaves, 3))
# 12 -> 7 octaves, +23.46; 41 -> 24, -19.845; 53 -> 31, +3.615
Equal temperament gives up on pure ratios. It splits the octave into twelve identical steps, each multiplying frequency by the twelfth root of 2. Every key then works the same in every key signature, at the cost of small errors. Piano keys are numbered 1 to 88 from the left, and key 49 is the A above middle C, tuned to 440 Hz. Pick a key, pick an interval, and compare the pure (just) version with the piano's version.
How to read this: the number on each key is its frequency in hertz (vibrations per second). In the chart, each bar shows how far the piano's version of an interval is from the pure one: right of the gold line, the piano is a bit sharp; left, a bit flat. Click a row to choose that interval.
Try this: click a key, click the M3 row in the chart, then press Just, then equal to hear the piano's third beat.
Each key is 21/12 times the one to its left, so twelve keys make exactly one octave. Key 1 (A0) is 27.5 Hz and key 88 (C8) is about 4186 Hz. The wavelength is the speed of sound, about in air at , divided by the frequency.
| Interval | Just | Just ¢ | Equal ¢ | Diff |
|---|
Some intervals have more than one just version. This table uses common 5-limit choices (ratios built from 2, 3 and 5). Fifths and fourths are within 2 cents, which few listeners notice. Thirds and sixths are off by 14 to 16 cents, enough to hear as beating in a held chord.
from math import log2 NAMES = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"] def key_freq(n): # piano key 1..88 return 440 * 2 ** ((n - 49) / 12) def key_name(n): return NAMES[(n - 1) % 12] + str((n + 8) // 12) for n in (1, 40, 49, 88): print(n, key_name(n), round(key_freq(n), 3)) # 1 A0 27.5 · 40 C4 261.626 · 49 A4 440.0 · 88 C8 4186.009 for name, p, q, steps in [("fifth", 3, 2, 7), ("major third", 5, 4, 4)]: just = 1200 * log2(p / q) equal = 100 * steps print(name, round(just, 3), equal, round(equal - just, 3)) # fifth 701.955 700 -1.955 · major third 386.314 400 13.686 root = key_freq(40) # C4 top = key_freq(44) # E4, equal tempered print(abs(4 * top - 5 * root)) # beats/s between overtones, about 10.4