{"id":15048016,"url":"https://github.com/jurihock/sdft","last_synced_at":"2025-04-10T01:11:53.359Z","repository":{"id":58085593,"uuid":"486097547","full_name":"jurihock/sdft","owner":"jurihock","description":"Single file forward and inverse Sliding DFT in C, C++ and Python","archived":false,"fork":false,"pushed_at":"2023-11-21T15:43:31.000Z","size":3550,"stargazers_count":27,"open_issues_count":4,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T01:11:48.032Z","etag":null,"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"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jurihock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-27T07:52:51.000Z","updated_at":"2025-03-06T16:12:38.000Z","dependencies_parsed_at":"2025-02-16T06:32:44.402Z","dependency_job_id":"5eaa4550-f5e5-4379-bd65-c77e756d0d21","html_url":"https://github.com/jurihock/sdft","commit_stats":{"total_commits":182,"total_committers":1,"mean_commits":182.0,"dds":0.0,"last_synced_commit":"91d92e173079b49cd2731f2f510282f71c683f85"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jurihock%2Fsdft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jurihock%2Fsdft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jurihock%2Fsdft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jurihock%2Fsdft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jurihock","download_url":"https://codeload.github.com/jurihock/sdft/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137888,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"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"],"created_at":"2024-09-24T21:06:57.504Z","updated_at":"2025-04-10T01:11:53.331Z","avatar_url":"https://github.com/jurihock.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sliding Discrete Fourier Transform (SDFT)\n\n![language](https://img.shields.io/badge/languages-C%2FC%2B%2B%20Python-blue)\n![license](https://img.shields.io/github/license/jurihock/sdft?color=green)\n![pypi](https://img.shields.io/pypi/v/sdft?color=gold)\n\nForward and inverse Sliding DFT according to [[1]](#1) and [[2]](#2) with following features:\n\n- Arbitrary number of DFT bins\n- Built-in analysis window functions Boxcar, Hann (default), Hamming and Blackman\n- Customizable time and frequency domain data type in C/C++\n- Endless single or multiple sample processing at once\n- Optional synthesis latency control parameter\n- Real-time low latency\u003csup\u003e*\u003c/sup\u003e analysis and synthesis capability\n\n\u003csup\u003e\u003csub\u003e*) compared to STFT latency\u003c/sub\u003e\u003c/sup\u003e\n\nThe [Sliding Discrete Fourier Transform (SDFT)](https://en.wikipedia.org/wiki/Sliding_DFT) 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)](https://en.wikipedia.org/wiki/Short-time_Fourier_transform) approach with one sample hops. On the other side, the SDFT is still known to suffer from accumulated errors and potential instabilities.\n\nThis 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](https://en.wikipedia.org/wiki/Nyquist_frequency) 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.\n\nCompared 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.\n\n## Basic usage\n\nFor detailed usage, please have a look at the provided \"analysis\" examples.\n\n### C\n\n```c\n#define SDFT_TD_FLOAT  // time domain data type (float by default)\n#define SDFT_FD_DOUBLE // frequency domain data type (double by default)\n\n#include \u003csdft/sdft.h\u003e // see also src/c folder\n\nsize_t n = ...; // number of samples\nsize_t m = ...; // number of dft bins\n\nfloat* x = ...; // analysis samples of shape (n)\nfloat* y = ...; // synthesis samples of shape (n)\n\ndouble complex* dft = ...; // dft matrix of shape (n, m)\n\nsdft_t* sdft = sdft_alloc(m); // create sdft plan\n\nsdft_sdft_n(sdft, n, x, dft); // extract dft matrix from input samples\nsdft_isdft_n(sdft, n, dft, y); // synthesize output samples from dft matrix\n\nsdft_free(sdft); // destroy sdft plan\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eMSVC\u003c/strong\u003e\u003c/summary\u003e\n\u003cp/\u003e\n\nDue to incomplete [C complex math support](https://docs.microsoft.com/cpp/c-runtime-library/complex-math-support) in MSVC, optionally use following universal typedefs:\n\n* `sdft_float_t` instead of `float`\n* `sdft_double_complex_t` instead of `double complex`\n\nor even better the corresponding generic typedefs:\n\n* `sdft_td_t`\n* `sdft_fdx_t`\n\nIn both cases, the underlying data type results from the `SDFT_TD_*` and `SDFT_FD_*` definitions.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eNo complex.h? No problem...\u003c/strong\u003e\u003c/summary\u003e\n\u003cp/\u003e\n\nJust define `SDFT_NO_COMPLEX_H` to prevent `complex.h` from being included and internally enable compatible complex number representation instead:\n\n```c\ntypedef struct { sdft_fd_t r, i; } sdft_fdx_t;\n```\n\n\u003c/details\u003e\n\n### C++\n\n```c++\n#include \u003csdft/sdft.h\u003e // see also src/cpp folder\n\nsize_t n = ...; // number of samples\nsize_t m = ...; // number of dft bins\n\nfloat* x = ...; // analysis samples of shape (n)\nfloat* y = ...; // synthesis samples of shape (n)\n\nstd::complex\u003cdouble\u003e* dft = ...; // dft matrix of shape (n, m)\n\nSDFT\u003cfloat, double\u003e sdft(m); // create sdft plan for custom time and frequency domain data types\n\nsdft.sdft(n, x, dft); // extract dft matrix from input samples\nsdft.isdft(n, dft, y); // synthesize output samples from dft matrix\n```\n\nThe time domain data type defaults to `float` and the frequency domain data type to `double`.\n\n### Python\n\n```python\nfrom sdft import SDFT # see also src/python folder\n\nn = ... # number of samples\nm = ... # number of dft bins\n\nx = ... # analysis samples of shape (n)\n\nsdft = SDFT(m) # create sdft plan\n\ndft = sdft.sdft(x) # extract dft matrix from input samples\ny = sdft.isdft(dft) # synthesize output samples from dft matrix\n```\n\nFeel free to obtain current version from [PyPI](https://pypi.org/project/sdft) by executing `pip install sdft`.\n\n## Test spectrogram\n\nBelow 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?\n\n| SDFT | STFT |\n| ---- | ---- |\n| ![SDFT](https://github.com/jurihock/sdft/raw/main/test/sdft.png) | ![STFT](https://github.com/jurihock/sdft/raw/main/test/stft.png) |\n\nWell, the results are very similar, which is to be considered as the proof of concept...\n\n## See also\n\nIf you're interested in Sliding DFT with *logarithmic* frequency resolution, don't forget to browse my [jurihock/qdft](https://github.com/jurihock/qdft) project!\n\n## References\n\n1. \u003cspan id=\"1\"\u003eKrzysztof Duda (2010). Accurate, Guaranteed Stable, Sliding Discrete Fourier Transform. IEEE Signal Processing Magazine. https://ieeexplore.ieee.org/document/5563098\u003c/span\u003e\n\n2. \u003cspan id=\"2\"\u003eRussell Bradford et al. (2005). Sliding is Smoother Than Jumping. International Computer Music Conference Proceedings. http://hdl.handle.net/2027/spo.bbp2372.2005.086\u003c/span\u003e\n\n## License\n\n[github.com/jurihock/sdft](https://github.com/jurihock/sdft) is licensed under the terms of the MIT license.\nFor details please refer to the accompanying [LICENSE](https://github.com/jurihock/sdft/raw/main/LICENSE) file distributed with it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjurihock%2Fsdft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjurihock%2Fsdft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjurihock%2Fsdft/lists"}