ConstantQTransform<T>

Models & Types ยท AiDotNet.Audio.Features

Constant-Q Transform (CQT) for music analysis with logarithmic frequency resolution.

Inheritance: ModelBase<T, Tensor<T>, Tensor<T>> โ†’ ConstantQTransform<T>

For Beginners

The CQT is perfect for music analysis because:

  • Musical notes are logarithmically spaced (each octave doubles frequency)
  • Low notes get wide bins, high notes get narrow bins (matches perception)
  • Makes chord/key detection much easier than FFT

Usage:

How It Works

Unlike the FFT which has linear frequency spacing, the CQT uses logarithmic spacing where each frequency bin is a constant ratio (Q factor) above the previous one. This matches how humans perceive pitch: octaves are equally spaced.

Constructors

Constructor Summary
ConstantQTransform(int sampleRate, double fMin, int binsPerOctave, int numOctaves, int hopLength, WindowType windowType) Creates a new Constant-Q Transform instance.

Properties

Property Summary
ILossFunction<T> DefaultLossFunction { get; }
double QFactor { get; } Gets the Q factor (quality factor) for this CQT.
double[] Frequencies { get; } Gets the center frequencies for each bin.
int NumBins { get; } Gets the number of frequency bins in the CQT output.
int SampleRate { get; } Gets the sample rate.

Methods

Method Summary
IFullModel<T, Tensor<T>, Tensor<T>> WithParameters(Vector<T> parameters)
Tensor<T> Predict(Tensor<T> input)
Tensor<T> Transform(Tensor<T> audio) Computes the Constant-Q Transform of an audio signal.
Tensor<T> TransformComplex(Tensor<T> audio) Computes the complex CQT (with phase information).
Tensor<T> TransformDb(Tensor<T> audio, double refValue, double minDb) Computes CQT in decibels (log scale).
Tensor<T> TransformPower(Tensor<T> audio, double power) Computes CQT with power spectrum (magnitude squared).
double GetMidiNote(int binIndex) Gets the MIDI note number for a given bin index.
string GetNoteName(int binIndex) Gets the note name for a given bin index.
void Train(Tensor<T> input, Tensor<T> expectedOutput)