By Tania Alwan
Paste a song into a chord finder and a few seconds later you get "C, Am, F, G" scrolling under a timeline. It feels like magic, but the classic pipeline behind most chord finders is surprisingly readable. This post walks through it step by step and ends with a short Python script that recognizes a chord progression from audio.
The problem in one sentence
A chord finder has to answer, for every short slice of audio: which pitch classes are sounding, and which chord do they best match?
Everything else (beat tracking, smoothing, fancy neural networks) is there to make that answer more stable.
Step 1: From waveform to spectrum
Audio is a list of amplitude samples. To talk about notes, we need frequencies, so the signal is cut into short overlapping frames and transformed into a spectrum.
Chord tools often prefer the constant-Q transform (CQT) over a plain FFT. Its frequency bins are spaced logarithmically, like musical notes, so each bin lines up with a semitone (or a fraction of one). An FFT spaces bins linearly, which wastes resolution in the highs and blurs neighbouring notes in the lows.
Step 2: Fold everything into 12 pitch classes (chroma)
For chord recognition, the octave mostly does not matter: a C3 and a C5 both say "C". So the spectrum is folded into a chroma vector: 12 numbers, one per pitch class (C, C#, D ... B), each representing how much energy that note has in the frame, across all octaves.
A C major chord should light up C, E and G. An A minor chord lights up A, C and E. Notice that they share two notes, which is exactly why chord finders sometimes confuse relative major and minor chords.
Step 3: Compare against chord templates
The simplest recognizer builds a binary template for each chord:
- C major =
[1,0,0,0,1,0,0,1,0,0,0,0](C, E, G) - A minor =
[1,0,0,0,1,0,0,0,0,1,0,0](C, E, A)
Normalize the templates and the chroma vector, take the dot product (cosine similarity), and pick the highest score. With 12 roots and 2 qualities, that is 24 templates. Real tools add 7ths, sus chords, inversions and a "no chord" class.
Step 4: Smooth over time
Frame-by-frame decisions flicker: a passing note or a drum hit can flip the label for 50 ms. Common fixes:
- Average chroma over each beat (using a beat tracker) instead of each frame
- Median-filter the chord labels
- Use a hidden Markov model or similar, where changing chords has a cost, so the system prefers stable sequences
Modern chord finders often replace templates with neural networks trained on annotated songs, but they still usually work from a CQT or chroma-like input and still smooth over time.
The Python example
This script synthesizes a four-chord progression (C, Am, F, G), computes chroma with librosa, and matches each second against 24 major/minor templates.
import numpy as np
import librosa
NOTES = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
def chord_templates():
templates, names = [], []
for root in range(12):
for quality, intervals in (('', (0, 4, 7)), ('m', (0, 3, 7))):
t = np.zeros(12)
for i in intervals:
t[(root + i) % 12] = 1
templates.append(t / np.linalg.norm(t))
names.append(NOTES[root] + quality)
return np.array(templates), names
def synth_chord(midi_notes, sr=22050, dur=1.0):
t = np.linspace(0, dur, int(sr * dur), endpoint=False)
y = sum(np.sin(2 * np.pi * librosa.midi_to_hz(m) * t) for m in midi_notes)
return y / len(midi_notes)
sr = 22050
# C major, A minor, F major, G major (MIDI note numbers)
progression = [(60, 64, 67), (57, 60, 64), (53, 57, 60), (55, 59, 62)]
y = np.concatenate([synth_chord(c, sr) for c in progression])
hop = 512
chroma = librosa.feature.chroma_cqt(y=y, sr=sr, hop_length=hop)
templates, names = chord_templates()
frames_per_sec = sr / hop
for sec in range(len(progression)):
start, end = int(sec * frames_per_sec), int((sec + 1) * frames_per_sec)
v = chroma[:, start:end].mean(axis=1)
v = v / (np.linalg.norm(v) + 1e-9)
print(sec, names[int(np.argmax(templates @ v))])
Output:
0 C
1 Am
2 F
3 G
To try it on a real recording, replace the synthesized y with y, sr = librosa.load("song.wav") and average over beats from librosa.beat.beat_track instead of fixed one-second windows.
Why real songs are harder
Clean sine waves are the easy case. On real music, accuracy drops for predictable reasons:
- Vocals and leads add non-chord notes. A melody sitting on a 9th or a passing tone pulls the chroma vector away from the template.
- Bass and drums add energy everywhere. Kick drums smear low frequencies; cymbals add broadband noise.
- Harmonics leak into other pitch classes. The third harmonic of C is a G, the fifth is an E, so a single bass note can look like a full chord.
- Real harmony is richer than 24 classes. Jazz voicings, slash chords and modal mixtures do not fit major/minor templates.
One practical trick: run source separation first and analyse only the harmonic instruments (or remove the vocal). Open-source models such as Demucs can do this locally; hosted tools like the Voicestars stems splitter do it in the browser. Either way, a cleaner input usually produces a cleaner chroma.
Takeaways
- Chord finders turn audio into a spectrum, fold it into 12-bin chroma, and match it against chord shapes.
- Relative major/minor confusion comes straight from shared notes in the templates.
- Smoothing over beats or with an HMM matters as much as the matching step.
- Fewer competing sources (vocals, drums) means a cleaner chroma and better guesses.
Disclosure: this article was written in partnership with Voicestars.
Top comments (0)