Package: sdft
Sliding Discrete Fourier Transform (SDFT)Forward and inverse Sliding DFT according to[1]and[2]with following features:Arbitrary number of DFT binsBuilt-in analysis window functions Boxcar, Hann (default), Hamming and BlackmanCustomizable time and frequency domain data type in C/C++Endless single or multiple sample processing at onceOptional synthesis latency control parameterReal-time low latency*analysis and synthesis capability*) compared to STFT latencyTheSliding 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 basedShort 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 themodulatedSDFT 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 length of the estimated DFT vector 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 usageC#define SDFT_TD_FLOAT// time domain data type (float by default)#define SDFT_FD_DOUBLE// frequency domain data type (double by default)#include<sdft/sdft.h>// see also src/c foldersize_tn=...;// number of samplessize_tm=...;// number of dft binsfloat*x=...;// analysis samples of shape (n)float*y=...;// synthesis samples of shape (n)doublecomplex*dft=...;// dft matrix of shape (n, m)sdft_t*sdft=sdft_alloc(m);// create sdft plansdft_sdft_n(sdft,n,x,dft);// extract dft matrix from input samplessdft_isdft_n(sdft,n,dft,y);// synthesize output samples from dft matrixsdft_free(sdft);// destroy sdft planMSVCDue to incompleteC complex math supportin MSVC, optionally use following universal typedefs:sdft_float_tinstead offloatsdft_double_complex_tinstead ofdouble complexor even better the corresponding generic typedefs:sdft_td_tsdft_fdx_tIn both cases, the underlying data type results from theSDFT_TD_*andSDFT_FD_*definitions.No complex.h? No problem...Just defineSDFT_NO_COMPLEX_Hto preventcomplex.hfrom being included and internally enable compatible complex number representation instead:typedefstruct{sdft_fd_tr,i;}sdft_fdx_t;C++#include<sdft/sdft.h>// see also src/cpp foldersize_tn=...;// number of samplessize_tm=...;// number of dft binsfloat*x=...;// analysis samples of shape (n)float*y=...;// synthesis samples of shape (n)std::complex<double>*dft=...;// dft matrix of shape (n, m)SDFT<float,double>sdft(m);// create sdft plan for custom time and frequency domain data typessdft.sdft(n,x,dft);// extract dft matrix from input samplessdft.isdft(n,dft,y);// synthesize output samples from dft matrixThe time domain data type defaults tofloatand the frequency domain data type todouble.PythonfromsdftimportSDFT# see also src/python foldern=...# number of samplesm=...# number of dft binsx=...# analysis samples of shape (n)sdft=SDFT(m)# create sdft plandft=sdft.sdft(x)# extract dft matrix from input samplesy=sdft.isdft(dft)# synthesize output samples from dft matrixFeel free to obtain current version fromPyPIby executingpip install sdft.Test spectrogramBelow you can see two spectrograms of the same audio filetest.wavcomputed by SDFT and STFT with identical spectral resolution, window function and hop size. Do you see any significant differences between them?SDFTSTFTWell, the results are very similar, which is to be considered as the proof of concept...See alsoIf you're interested in Sliding DFT withlogarithmicfrequency resolution, don't forget to browse myjurihock/qdftproject!ReferencesKrzysztof Duda (2010). Accurate, Guaranteed Stable, Sliding Discrete Fourier Transform. IEEE Signal Processing Magazine.https://ieeexplore.ieee.org/document/5563098Russell Bradford et al. (2005). Sliding is Smoother Than Jumping. International Computer Music Conference Proceedings.http://hdl.handle.net/2027/spo.bbp2372.2005.086Licensegithub.com/jurihock/sdftis licensed under the terms of the MIT license.
For details please refer to the accompanyingLICENSEfile distributed with it.