In mathematics and signal processing, the constant-Q transform and variable-Q transform, simply known as CQT and VQT, transforms a data series to the frequency domain. It is related to the Fourier transform and very closely related to the complex Morlet wavelet transform. Its design is suited for musical representation.


The transform can be thought of as a series of filters fk, logarithmically spaced in frequency, with the k-th filter having a spectral width δfk equal to a multiple of the previous filter's width:
where δfk is the bandwidth of the k-th filter, fmin is the central frequency of the lowest filter, and n is the number of filters per octave.
The short-time Fourier transform of x[n] for a frame shifted to sample m is calculated as follows:
Given a data series at sampling frequency fs = 1/T, T being the sampling period of our data, for each frequency bin we can define the following:
For geometrically spaced bands, , so is the same for every band and is in general not a whole number, being about 16.8 for n = 12 bins per octave. It is the number of cycles of the sinusoid spanned by the analysis window at fk, and so fixes the duration of that window.
The equivalent transform kernel can be found by using the following substitutions:
After these modifications, we are left with
The variable-Q transform is the same as constant-Q transform, but the only difference is the filter Q is variable, hence the name variable-Q transform. The variable-Q transform is useful where time resolution on low frequencies is important[examples needed]. There are ways to calculate the bandwidth of the VQT, one of them using equivalent rectangular bandwidth as a value for VQT bin's bandwidth.
The variable-Q transform is usually obtained by adding a bandwidth offset γ, so that the bandwidth of the k-th band becomes
where α = 1/Q is fixed by the number of bands per octave. Setting γ = 0 recovers the constant-Q transform, while γ > 0 widens the lower bands, which lowers their Q and shortens their windows, improving time resolution at low frequencies at the cost of frequency resolution. Choosing γ so that each bandwidth is a fixed fraction of the equivalent rectangular bandwidth at the corresponding centre frequency gives bands following an auditory scale, and is the default in some implementations.
The direct calculation of the constant-Q transform (either using naive discrete Fourier transform or slightly faster Goertzel algorithm) is slow when compared against the fast Fourier transform. However, the fast Fourier transform can itself be employed, in conjunction with the use of a kernel, to perform the equivalent calculation but much faster. An approximate inverse to such an implementation was proposed in 2006; it works by going back to the discrete Fourier transform, and is only suitable for pitch instruments.
A development on this method with improved invertibility involves performing CQT (via fast Fourier transform) octave-by-octave, using lowpass filtered and downsampled results for consecutively lower pitches. Implementations of this method include the MATLAB implementation and LibROSA's Python implementation. LibROSA combines the subsampled method with the direct fast Fourier transform method (which it dubs "pseudo-CQT") by having the latter process higher frequencies as a whole.
The sliding discrete Fourier transform can be used for faster calculation of constant-Q transform, since the sliding discrete Fourier transform does not have to be linear-frequency spacing and same window size per bin.
Alternatively, the constant-Q transform can be approximated by using multiple fast Fourier transforms of different window sizes and/or sampling rate at different frequency ranges then stitch it together. This is called multiresolution short-time Fourier transform, however the window sizes for multiresolution fast Fourier transforms are different per-octave, rather than per-bin.[ambiguous]
The constant-Q transform can be cast as a nonstationary Gabor system, in which the analysis window varies with frequency rather than with time. Each band is formed by multiplying the Fourier transform of the signal by a real window centred on that band, then taking an inverse Fourier transform whose length matches the bandwidth of that window, so each band carries its own number of time coefficients.
If the windows satisfy a "painless" condition, so that at every frequency bin the sum of their squared magnitudes, each weighted by the number of coefficients in its band, is strictly positive, then the [[Frame (linear algebra)|frame]] operator is diagonal. It is then inverted by one division per bin, giving a dual window for each band, and synthesis from these dual windows recovers the signal exactly, with no iterative step; reconstruction is therefore exact up to numerical precision rather than approximate. Analysis and synthesis each cost one fast Fourier transform of the whole signal together with one short transform per band.
A sliced variant cuts the signal into overlapping slices under a smooth window, transforms each slice, and overlap-adds the inverses, which lets the transform run on a continuous stream with bounded memory and an algorithmic delay of one slice. The same construction with bands spaced on an auditory scale instead of geometrically gives the ERBlet transform. Reference implementations are published by the authors and in MATLAB's Wavelet Toolbox.
In general, the transform is well suited to musical data, and this can be seen in some of its advantages compared to the fast Fourier transform. As the output of the transform is effectively amplitude/phase against log frequency, fewer frequency bins are required to cover a given range effectively, and this proves useful where frequencies span several octaves. As the range of human hearing covers approximately ten octaves from 20 Hz to around 20 kHz, this reduction in output data is significant.
The transform exhibits a reduction in frequency resolution with higher frequency bins, which is desirable for auditory applications. The transform mirrors the human auditory system, whereby at lower-frequencies spectral resolution is better, whereas temporal resolution improves at higher frequencies. At the bottom of the piano scale (about 30 Hz), a difference of 1 semitone is a difference of approximately 1.5 Hz, whereas at the top of the musical scale (about 5 kHz), a difference of 1 semitone is a difference of approximately 200 Hz. So for musical data the exponential frequency resolution of constant-Q transform is ideal.
In addition, the harmonics of musical notes form a pattern characteristic of the timbre of the instrument in this transform. Assuming the same relative strengths of each harmonic, as the fundamental frequency changes, the relative position of these harmonics remains constant. This can make identification of instruments much easier. The constant Q transform can also be used for automatic recognition of musical keys based on accumulated chroma content.
Relative to the Fourier transform, implementation of this transform is more tricky. This is due to the varying number of samples used in the calculation of each frequency bin, which also affects the length of any windowing function implemented.
Also note that because the frequency scale is logarithmic, there is no true zero-frequency / DC term present, which may be a drawback in applications that are interested in the DC term. Although for applications that are not interested in the DC such as audio, this is not a drawback.