sdft

Single file forward and inverse Sliding DFT in C, C++ and Python

https://github.com/jurihock/sdft

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: ieee.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.2%) to scientific vocabulary

Keywords

algorithms audio c99 cpp cpp11 dft digital-signal-processing discrete-fourier-transform dsp fft fourier fourier-transform math python qdft sdft signal-processing sliding-dft spectral-analysis spectral-synthesis
Last synced: 4 months ago · JSON representation ·

Repository

Single file forward and inverse Sliding DFT in C, C++ and Python

Basic Info
  • Host: GitHub
  • Owner: jurihock
  • License: mit
  • Language: C
  • Default Branch: main
  • Homepage:
  • Size: 3.4 MB
Statistics
  • Stars: 31
  • Watchers: 2
  • Forks: 6
  • Open Issues: 4
  • Releases: 5
Topics
algorithms audio c99 cpp cpp11 dft digital-signal-processing discrete-fourier-transform dsp fft fourier fourier-transform math python qdft sdft signal-processing sliding-dft spectral-analysis spectral-synthesis
Created over 3 years ago · Last pushed 7 months ago
Metadata Files
Readme License Citation

README.md

Sliding Discrete Fourier Transform (SDFT)

language license pypi

Forward and inverse Sliding DFT according to [1] and [2] with following features:

  • Arbitrary number of DFT bins
  • Built-in analysis window functions Boxcar, Hann (default), Hamming and Blackman
  • Customizable time and frequency domain data type in C/C++
  • Endless single or multiple sample processing at once
  • Optional synthesis latency control parameter
  • Real-time low latency* analysis and synthesis capability

*) compared to STFT latency

The Sliding Discrete Fourier Transform (SDFT) is a recursive approach to compute the Fourier transform sample by sample. In this particular case it's more efficient than the FFT based Short Time Fourier Transform (STFT) approach with one sample hops. On the other side, the SDFT is still known to suffer from accumulated errors and potential instabilities.

This implementation features the modulated SDFT algorithm, which is guaranteed to be stable while being accurate. It takes real valued samples and estimates the corresponding half size complex valued DFT vector for each of them. The DFT vector of a particular input sample contains linearly spaced frequency bins from 0 Hz up to the Nyquist frequency. Therefore, the spectral resolution depends on the input sample rate and the specified DFT vector length. The length of the estimated DFT vector, as specified in the SDFT constructor, is not limited to the power of two. The eventually altered DFT vector can also be used to synthesize an output sample.

Compared to STFT, the algorithmic synthesis latency of SDFT is lower and can additionally be reduced at the expense of signal to noise ratio. Spectral data processing coupled with reduced latency is especially useful for real-time applications, e.g. digital audio signal processing.

Basic usage

For detailed usage, please have a look at the provided "analysis" examples.

C

```c

define SDFTTDFLOAT // time domain data type (float by default)

define SDFTFDDOUBLE // frequency domain data type (double by default)

include // see also src/c folder

sizet n = ...; // number of samples sizet m = ...; // number of dft bins

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

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

sdftt* sdft = sdftalloc(m); // create sdft plan

sdftsdftn(sdft, n, x, dft); // extract dft matrix from input samples sdftisdftn(sdft, n, dft, y); // synthesize output samples from dft matrix

sdft_free(sdft); // destroy sdft plan ```

MSVC

Due to incomplete [C complex math support](https://docs.microsoft.com/cpp/c-runtime-library/complex-math-support) in MSVC, optionally use following universal typedefs: * `sdft_float_t` instead of `float` * `sdft_double_complex_t` instead of `double complex` or even better the corresponding generic typedefs: * `sdft_td_t` * `sdft_fdx_t` In both cases, the underlying data type results from the `SDFT_TD_*` and `SDFT_FD_*` definitions.

No complex.h? No problem...

Just define `SDFT_NO_COMPLEX_H` to prevent `complex.h` from being included and internally enable compatible complex number representation instead: ```c typedef struct { sdft_fd_t r, i; } sdft_fdx_t; ```

C++

```c++

include // see also src/cpp folder

sizet n = ...; // number of samples sizet m = ...; // number of dft bins

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

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

SDFT sdft(m); // create sdft plan for custom time and frequency domain data types

sdft.sdft(n, x, dft); // extract dft matrix from input samples sdft.isdft(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

```python from sdft import SDFT # see also src/python folder

n = ... # number of samples m = ... # number of dft bins

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

sdft = SDFT(m) # create sdft plan

dft = sdft.sdft(x) # extract dft matrix from input samples y = sdft.isdft(dft) # synthesize output samples from dft matrix ```

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

Test spectrogram

Below you can see two spectrograms of the same audio file test.wav computed by SDFT and STFT with identical spectral resolution, window function and hop size. Do you see any significant differences between them?

| SDFT | STFT | | ---- | ---- | | SDFT | STFT |

Well, the results are very similar, which is to be considered as the proof of concept...

See also

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

References

  1. Krzysztof Duda (2010). Accurate, Guaranteed Stable, Sliding Discrete Fourier Transform. IEEE Signal Processing Magazine. https://ieeexplore.ieee.org/document/5563098

  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

License

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

Owner

  • Name: Jürgen Hock
  • Login: jurihock
  • Kind: user
  • Location: Karlsruhe, Germany
  • Company: Fraunhofer

❤️ Open Source, DSP, Audio FX

Citation (CITATION.cff)

cff-version: 1.2.0
title: "Single file forward and inverse Sliding DFT in C, C++ and Python"
authors:
  - family-names: Hock
    given-names: Juergen
url: https://github.com/jurihock/sdft
license: MIT
type: software
message: >-
  If you use this software, please cite it
  using the metadata from this file.
references:
  - title: "Accurate, Guaranteed Stable, Sliding Discrete Fourier Transform"
    authors:
      - family-names: Duda
        given-names: Krzysztof
    url: https://ieeexplore.ieee.org/document/5563098
    doi: 10.1109/MSP.2010.938088
    type: article
  - title: "Sliding is Smoother Than Jumping"
    authors:
      - family-names: Bradford
        given-names: Russell
    url: http://hdl.handle.net/2027/spo.bbp2372.2005.086
    type: article

GitHub Events

Total
  • Issues event: 1
  • Watch event: 8
  • Push event: 6
  • Create event: 3
Last Year
  • Issues event: 1
  • Watch event: 8
  • Push event: 6
  • Create event: 3

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 182
  • Total Committers: 1
  • Avg Commits per committer: 182.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Jürgen Hock j****k@j****e 182
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 5 months ago

All Time
  • Total issues: 11
  • Total pull requests: 0
  • Average time to close issues: 1 day
  • Average time to close pull requests: N/A
  • Total issue authors: 3
  • Total pull request authors: 0
  • Average comments per issue: 1.55
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • jurihock (9)
  • stellarpower (2)
  • joaromi (1)
Pull Request Authors
Top Labels
Issue Labels
enhancement (9) documentation (2) wontfix (1) question (1)
Pull Request Labels

Dependencies

rust/Cargo.toml cargo
  • ndarray 0.15.* development
  • ndarray-npy 0.8.* development
  • num 0.4.*
python/pyproject.toml pypi