Constant Q Transform – A Visual Guide

Hacker News Top Tools

Summary

An interactive visual guide explaining the Constant-Q Transform (CQT), its log-frequency geometry, comparison with FFT, kernel construction, and efficient computation, tailored for music and pitch analysis.

No content available
Original Article
View Cached Full Text

Cached at: 06/02/26, 01:46 AM

# The Constant-Q Transform — A Visual Guide Source: [https://brendanjameslynskey.github.io/ConstantQ-Transform/](https://brendanjameslynskey.github.io/ConstantQ-Transform/) A visual, interactive guide to the frequency transform that hears music the way we do — with logarithmic resolution matching the structure of pitch\. ▼ ### Chapter 1 ## 01The Core Intuition "Constant Q" means the ratio of each frequency bin's centre frequency to its bandwidth is**constant**\. Low notes get wide analysis windows \(good frequency resolution\); high notes get narrow windows \(good time resolution\)\. This mirrors how musical pitch works\. On a piano, the distance from C3 to C4 spans the same perceptual interval as C5 to C6, even though the latter covers four times the Hz range\. The CQT spaces its bins logarithmically to match, typically placing 12, 24, 36, or more bins per octave\. Bins per octave:24Octaves:5 CQT frequency bins — each bar is one bin\. Notice how bandwidth grows with frequency, but Q = f/Δf stays constant\. **Q factor:**Q = fk/ Δfk\. In a standard FFT, Q varies — low\-frequency bins are narrow \(high Q\), high\-frequency bins are wide \(low Q\)\. In the CQT, Q is the same for every bin\. This is why musical notes look equally spaced in a CQT spectrogram\. ### Chapter 2 ## 02FFT vs CQT The FFT uses linearly\-spaced frequency bins\. Musical notes are logarithmically spaced\. The mismatch makes pitch analysis with the FFT awkward — the CQT solves this directly\. Consider a signal containing notes at C3, E4, and G5\. In the FFT, these three notes are unevenly distributed across the spectrum, and the low notes are smeared across very few bins\. In the CQT, each note occupies proportionally the same width\. Three\-note chord: C3 \(130\.8 Hz\) \+ E4 \(329\.6 Hz\) \+ G5 \(784 Hz\) FFT — linear frequency axis\. Low notes are crammed into a tiny region\. CQT — log frequency axis\. Each note gets equal visual weight\. **The fundamental difference:**FFT bin spacing is Δf = fs/N \(constant in Hz\)\. CQT bin spacing is Δfk= fk· \(21/B− 1\) \(proportional to frequency\)\. This makes the CQT a natural fit for anything involving musical pitch, speech formants, or logarithmic frequency structure\. ### Chapter 3 ## 03Log\-Frequency Geometry The CQT maps frequency to a logarithmic axis where octaves are equally spaced\. This aligns perfectly with the Western chromatic scale — and with human pitch perception\. Animated piano\-roll CQT spectrogram — watch notes light up on a log\-frequency axis as the arpeggio plays **Bins per octave \(B\):**With B=12, each bin is one semitone\. B=24 gives quarter\-tone resolution\. B=36 gives eighth\-tones\. Higher B means finer pitch discrimination but longer analysis windows at low frequencies\. fk= fmin· 2k/Bfor k = 0, 1, …, K−1 where K = B · num\_octaves ### Chapter 4 ## 04The CQT Kernel Each CQT bin uses a different\-length analysis window\. Low\-frequency bins use long windows for precise pitch resolution; high\-frequency bins use short windows for precise timing\. The window length for bin k is Nk= Q · fs/ fk\. This is the heart of the constant\-Q property — the window always contains the same number of oscillation cycles, regardless of frequency\. Nk= ⌈ Q · fs/ fk⌉ where Q = 1 / \(21/B− 1\) Bin index:0 CQT analysis kernel for the selected bin — real part \(top\) and magnitude envelope \(bottom\)\. Drag the slider to see how window length shrinks at higher frequencies\. 1 Compute the window length Nkfor each bin from Q and fk 2 Generate a windowed complex exponential at fk 3 Multiply the signal by this kernel and sum — that's one CQT coefficient 4 Repeat for all K bins across all time frames ### Chapter 5 ## 05Computing the CQT The naive CQT is expensive — O\(KN\) per frame\. Efficient algorithms use the FFT as a backbone, either via spectral kernels or recursive downsampling\. Speed: Building a CQT spectrogram frame by frame — each column is one hop, each row is one log\-frequency bin **Efficient CQT \(Brown & Puckette, 1992\):**Pre\-compute spectral kernels K̂kvia FFT\. For each frame, take the FFT of the signal segment X̂, then the CQT coefficient is simply X̂ · K̂k\*\. This converts the whole transform into sparse matrix–vector multiplications, often 10–100× faster than the naive approach\. CQT\(k, n\) = Σjx\(n \+ j\) · wk\(j\) · e−i2πfkj/fs Where wk\(j\) is the window function of length Nk\. The key insight is that each bin sees a*different number of signal samples*, unlike the FFT where every bin uses the same window\. ### Chapter 6 ## 06From CQT to Chromagram Fold the CQT's log\-frequency bins into a single octave and you get a**chromagram**— a 12\-dimensional representation of harmonic content, perfect for chord recognition and key detection\. If the CQT has B=36 bins per octave across 5 octaves \(180 bins total\), the chromagram sums every 3rd bin \(for 12 chroma classes\) across all octaves, collapsing the 180 bins into 12\. Chord: CQT spectrogram \(top\) folded into a 12\-bin chromagram \(bottom\)\. Switch chords to see how the chroma profile changes\. **Octave invariance:**The chromagram treats C3, C4, and C5 as the same pitch class "C"\. This makes it robust to register changes and lets algorithms focus on harmonic identity rather than absolute pitch\. ### Chapter 7 ## 07Real\-World Applications The CQT is the backbone of modern music information retrieval, audio synthesis, and intelligent audio processing\. Signal: Live CQT spectrogram of different musical signals — note how pitched content appears as distinct horizontal bands 🎵 **Pitch tracking**— automatic transcription, melody extraction, tuner apps 🎸 **Chord recognition**— real\-time chord detection via CQT → chromagram pipeline 🎛 **Audio synthesis**— phase vocoders with perceptually uniform frequency resolution 🤖 **Deep learning**— CQT spectrograms as input features for music classification, source separation, and generative models **CQT in neural networks:**Many state\-of\-the\-art music AI systems \(Demucs, OpenL3, CREPE\) use CQT or CQT\-like representations as input features instead of mel spectrograms, because the constant\-Q resolution matches the structure of the data they're modelling\.

Similar Articles

FourierQK: Spectral Preprocessing of Query-Key Projections Improves Transformer Attention

arXiv cs.CL

This paper introduces FourierQK, a method that applies FFT-based frequency-domain preprocessing to learned query and key projections in transformer attention, achieving significant validation loss reductions on character-level language modelling. The approach preserves the full attention score structure and demonstrates reproducible gains over standard dot-product attention.

Fast Fourier Transforms Part 1: Cooley-Tukey

Lobsters Hottest

This article provides a detailed mathematical derivation of the Cooley-Tukey Fast Fourier Transform algorithm, explaining how it reduces the complexity of the Discrete Fourier Transform.

Notes on the Fourier Transform

Eli Bendersky

An in-depth exploration of the Fourier transform, starting from Fourier series and extending to non-periodic functions, with interactive visualizations and mathematical derivation.

Universal Quantum Transformer

arXiv cs.AI

This paper introduces the Universal Quantum Transformer (UQT), a quantum-native architecture that uses multi-qubit systems for exact mathematical reasoning, achieving deterministic generalization on modular arithmetic and permutation groups while bypassing classical over-parameterization and quadratic attention bottlenecks, with deployment on IBM Quantum hardware.

A noob learns FFT

Lobsters Hottest

A beginner-friendly walkthrough of the Fast Fourier Transform using R, explaining how to interpret the fft function output, amplitude, phase, and the Nyquist limit.