Skip to main content

Constant-Q Sliding DFT

Project description

Constant-Q Sliding DFT in C++ and Python (QDFT)

language license pypi

Forward and inverse Constant-Q Sliding DFT according to [1] with following features:

  • Arbitrary octave resolution (quarter tone by default)
  • Built-in parameterizable cosine family window (Hann by default)
  • Customizable time and frequency domain data type in C++
  • Endless single or multiple sample processing at once
  • Optional analysis latency control parameter
  • Real-time analysis and synthesis capability

The Constant-Q Sliding Discrete Fourier Transform (QDFT) is a recursive approach to compute the Fourier transform sample by sample. This is an efficient implementation without the FFT calculus. Just define an arbitrary frequency range and octave resolution to obtain the corresponding DFT estimate. In contrast to the linear SDFT, frequency bins of the QDFT are logarithmically spaced. Thus, both high and low frequencies are resolved with the same quality, which is particularly useful for audio analysis. Based on the QDFT, a chromagram feature with detailed instantaneous frequency estimation is planned for the future release.

WIP

  • Readme
  • Docstrings
  • PyPI package qdft
  • Sliding chromagram as a bonus (a draft is already included in the Python package)

Basic usage

C++

#include <qdft/qdft.h> // see also src/cpp folder

double sr = 44100;                             // sample rate in hertz
std::pair<double, double> bw = { 50, sr / 2 }; // lowest and highest frequency in hertz to be resolved
double r = 24;                                 // octave resolution, e.g. number of DFT bins per octave

QDFT<float, double> qdft(sr, bw, r); // create qdft plan for custom time and frequency domain data types

size_t n = ...;         // number of samples
size_t m = qdft.size(); // number of dft bins

float* x = ...; // analysis samples of shape (n)
float* y = ...; // synthesis samples of shape (n)

std::complex<double>* dft = ...; // dft matrix of shape (n, m)

qdft.qdft(n, x, dft);  // extract dft matrix from input samples
qdft.iqdft(n, dft, y); // synthesize output samples from dft matrix

The time domain data type defaults to float and the frequency domain data type to double.

Python

from qdft import QDFT # see also src/python folder

sr = 44100        # sample rate in hertz
bw = (50, sr / 2) # lowest and highest frequency in hertz to be resolved
r = 24            # octave resolution, e.g. number of DFT bins per octave

qdft = QDFT(sr, bw, r) # create qdft plan

n = ...       # number of samples
m = qdft.size # number of dft bins (if need to know in advance)

x = ... # analysis samples of shape (n)

dft = qdft.qdft(x)  # extract dft matrix of shape (n, m) from input samples
y = qdft.iqdft(dft) # synthesize output samples from dft matrix

Feel free to obtain current version from PyPI by executing pip install qdft.

Examples

QDFT Chroma12
SDFT STFT
face.py cmajor.py
SDFT STFT

See also

If you're interested in Sliding DFT with linear frequency resolution, don't forget to browse my jurihock/sdft project!

References

  1. Russell Bradford et al. (2008). Sliding with a Constant Q. International Conference on Digital Audio Effects. https://www.dafx.de/paper-archive/2008/papers/dafx08_63.pdf

  2. Russell Bradford et al. (2005). Sliding is Smoother Than Jumping. International Computer Music Conference Proceedings. http://hdl.handle.net/2027/spo.bbp2372.2005.086

  3. Eric Jacobsen and Peter Kootsookos (2007). Fast, Accurate Frequency Estimators. IEEE Signal Processing Magazine. https://ieeexplore.ieee.org/document/4205098

License

github.com/jurihock/qdft is licensed under the terms of the MIT license. For details please refer to the accompanying LICENSE file distributed with it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qdft-0.5.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

qdft-0.5-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file qdft-0.5.tar.gz.

File metadata

  • Download URL: qdft-0.5.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for qdft-0.5.tar.gz
Algorithm Hash digest
SHA256 0178074a0a8c13eb3dd3e38096631c62348ed8a694f31ebf2a40c7d261c79dd9
MD5 e21c22e97ccb96506abe581a1b2c6a7e
BLAKE2b-256 1d085e6ea71b7c2e22da0103b7d51c86adafe8a4c0264e0f58cde41796ae94dc

See more details on using hashes here.

File details

Details for the file qdft-0.5-py3-none-any.whl.

File metadata

  • Download URL: qdft-0.5-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for qdft-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 78284c4df70c3c14036965e909d9b85966336491f5ce22d06cd6334e4d70b118
MD5 bf3b28baaad1ee016f35d0397eab62a0
BLAKE2b-256 2dd9e4c8e8a1e7a9d27cb4aa000824336698279eb634c374d6f97650fda81d56

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page