Constant-Q transform
In mathematics and signal processing, the constant-Q transform, simply known as CQT transforms a data series to the frequency domain. It is related to the Fourier transform[1] and very closely related to the complex Morlet wavelet transform.[2]
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.
Calculation
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:
- Filter width, δfk.
- Q, the "quality factor":
- This is shown below to be the integer number of cycles processed at a center frequency fk. As such, this somewhat defines the time complexity of the transform.
- Window length for the k-th bin:
- Since fs/fk is the number of samples processed per cycle at frequency fk, Q is the number of integer cycles processed at this central frequency.
The equivalent transform kernel can be found by using the following substitutions:
- The window length of each bin is now a function of the bin number:
- The relative power of each bin will decrease at higher frequencies, as these sum over fewer terms. To compensate for this, we normalize by N[k].
- Any windowing function will be a function of window length, and likewise a function of window number. For example, the equivalent Hamming window would be
- Our digital frequency, , becomes .
After these modifications, we are left with
Variable-Q bandwidth calculation
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 bandwidth δfk for variable-Q transform with arbitrary frequency resolution scale can be evaluated below:
- The variable-Q transform with Mel scale is used below:
- where the f(x) denotes the frequency scale and g(x) denotes the corresponding inverses.
- Calculate the slo and shi using this equation below:
- where tresAtHz is a center frequency for the desired time resolution and tres is a desired time resolution at the specified frequency.
- Then calculate the lower and higher boundaries using this equation below:
- Finally, calculate the bandwidth by this equation below:
- where Hz is the center frequency of the VQT.
Fast calculation
The direct calculation of the constant-Q transform is slow when compared against the fast Fourier transform (FFT). However, the FFT can itself be employed, in conjunction with the use of a kernel, to perform the equivalent calculation but much faster.[3] An approximate inverse to such an implementation was proposed in 2006; it works by going back to the DFT, and is only suitable for pitch instruments.[4]
A development on this method with improved invertibility involves performing CQT (via FFT) octave-by-octave, using lowpass filtered and downsampled results for consecutively lower pitches.[5] Implementations of this method include the MATLAB implementation and LibROSA's Python implementation.[6] LibROSA combines the subsampled method with the direct FFT method (which it dubs "pseudo-CQT") by having the latter process higher frequencies as a whole.[6]
Comparison with the Fourier transform
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.[7] 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.[8]
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.[9]
Also note that because the frequency scale is logarithmic, there is no true zero-frequency / DC term present, which may in some cases be a drawback.
References
- Judith C. Brown, Calculation of a constant Q spectral transform, J. Acoust. Soc. Am., 89(1):425–434, 1991.
- Continuous Wavelet Transform "When the mother wavelet can be interpreted as a windowed sinusoid (such as the Morlet wavelet), the wavelet transform can be interpreted as a constant-Q Fourier transform. Before the theory of wavelets, constant-Q Fourier transforms (such as obtained from a classic third-octave filter bank) were not easy to invert, because the basis signals were not orthogonal."
- Judith C. Brown and Miller S. Puckette, An efficient algorithm for the calculation of a constant Q transform, J. Acoust. Soc. Am., 92(5):2698–2701, 1992.
- FitzGerald, Derry; Cychowski, Marcin T.; Cranitch, Matt (1 May 2006). "Towards an Inverse Constant Q Transform". Audio Engineering Society Convention. Paris: Audio Engineering Society. 120.
- Schörkhuber, Christian; Klapuri, Anssi (2010). "CONSTANT-Q TRANSFORM TOOLBOX FOR MUSIC PROCESSING". 7th Sound and Music Computing Conference. Barcelona. Retrieved 12 December 2018. paper
- McFee, Brian; Battenberg, Eric; Lostanlen, Vincent; Thomé, Carl (12 December 2018). "librosa: core/constantq.py at 8d26423". GitHub. librosa. Retrieved 12 December 2018.
- http://newt.phys.unsw.edu.au/jw/graphics/notes.GIF
- Hendrik Purwins, Benjamin Blankertz and Klaus Obermayer, A New Method for Tracking Modulations in Tonal Music in Audio Data Format, International Joint Conference on Neural Network (IJCNN’00)., 6:270-275, 2000.
- Benjamin Blankertz, The Constant Q Transform, 1999.