cqt
Builtin index · Signal processing
cqt(x, fs, [fmin=32.7], [fmax=fs/2], [bins_per_octave=12], [hop=fs/100])
Input: x, fs, fmin, fmax, bins_per_octave, hop · Output: no output
What it is
x is a length-N real vector or Signal; fs (number, Hz) is the sample rate, or is carried by a Signal. fmin/fmax (optional numbers, Hz) bound the bin range — fmin defaults to 32.703 Hz (C1, the conventional musical bottom end) and fmax to Nyquist; bins_per_octave (optional number, default 12, i.e. a semitone) sets the geometric spacing; hop (optional number, default round(fs/100), i.e. 10 ms) is the frame stride in samples. Constant-Q transform: log-spaced bins sharing one Q = f/bandwidth, so a musical interval spans the same number of bins at every pitch. That is the opposite trade to stft, whose bins are linear in Hz: the CQT spends long windows (fine in frequency) on low notes and short ones (fine in time) on high ones, which is why it, not the STFT, is the standard front end for musical and perceptual analysis. Draws a dB heatmap and returns a Record with fields coef (a (bins, frames) CMat, row 0 = fmin), freq (length-bins Vec, Hz, geometrically spaced) and time (length-frames Vec, seconds). The lowest bin needs a ceil(Q*fs/fmin)-sample window, so reaching an octave lower needs twice the record; a signal too short for it is a named error rather than an empty result. Added in v0.3.0.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
cqt(x, fs, [fmin=32.7], [fmax=fs/2], [bins_per_octave=12], [hop=fs/100]) | x vector or Signalx is a length-N real vector or Signal.fs number or Signalfs (number, Hz) is the sample rate, or is carried by a Signal.fmin number, optional (default 32.7)fmin/fmax (optional numbers, Hz) bound the bin range — fmin defaults to 32.703 Hz (C1, the conventional musical bottom end) and fmax to Nyquist.fmax number, optional (default fs/2)fmin/fmax (optional numbers, Hz) bound the bin range — fmin defaults to 32.703 Hz (C1, the conventional musical bottom end) and fmax to Nyquist.bins_per_octave number, optional (default 12)bins_per_octave (optional number, default 12, i.e.hop number, optional (default fs/100)hop (optional number, default round(fs/100), i.e. | not documented yet | 10 ms) is the frame stride in samples. Constant-Q transform: log-spaced bins sharing one Q = f/bandwidth, so a musical interval spans the same number of bins at every pitch. That is the opposite trade to stft, whose bins are linear in Hz: the CQT spends long windows (fine in frequency) on low notes and short ones (fine in time) on high ones, which is why it, not the STFT, is the standard front end for musical and perceptual analysis. Added in v0.3.0. |
Examples
No documentation example calls this form yet. The Signal processing chapter is where one belongs.
How it works
cqt(x, fs, [fmin=], [fmax=], [bins_per_octave=12], [hop=]) — constant-Q transform: bins spaced geometrically at bins_per_octave per doubling, every one with the same Q = f/bandwidth, so a musical interval covers the same number of bins at every pitch. stft's bins are linear in Hz and cannot do that.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.