# \[ANN\] Announcing SlidingDFTs.jl

**URL:** <https://discourse.julialang.org/t/ann-announcing-slidingdfts-jl/123793>\
**Category:** Package Announcements\
**Tags:** dsp, fourier\
**Created:** [December 13, 2024, 12:14am UTC](https://discourse.julialang.org/t/ann-announcing-slidingdfts-jl/123793 "2024-12-13T00:14:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [December 13, 2024, 12:14am UTC](https://discourse.julialang.org/t/ann-announcing-slidingdfts-jl/123793/1 "2024-12-13T00:14:06Z")

</div>

This is a self-answer to [Is there a package for Sliding Discrete Fourier Transforms?](https://discourse.julialang.org/t/is-there-a-package-for-sliding-discrete-fourier-transforms/122320)

The package [SlidingDFTs](https://github.com/heliosdrm/SlidingDFTs.jl) provides the tools to compute [Sliding Discrete Fourer Transforms](https://en.wikipedia.org/wiki/Sliding_DFT) (SDFT) recursively, over one-dimensional series of values. The SDFT implemented in this package are different from spectrograms (e.g. as defined in DSP.jl) in various ways:

- They are lazy, non-indexable iterators that update the computed DFT at each iteration.
- The stride or step between consecutive DFTs is always one sample.
- The input data series are not limited to `AbstractArrays` - they can even be stateful iterators!

This is meant to provide a significant improvement in performance with respect to repeated computation of FFTs. I haven’t done a systematic benchmark yet, but in real use cases I have observed a reduction of computation times over one order of magnitude.

Its usage is very simple: given a data series `x`, just do:

```julia
itr = sdft(SDFT(n), x)

```

and you will have an iterator that yields a `Vector{Complex(eltype(x))}` of length `n` at each iteration (the DFT of the first `n` values at the first iteration, from the second to the `n+1`-th value at the second iteration, etc.). Typically used in a loop:

```julia
for spectrum in sdft(SDFT(n), x)
    # `spectrum` is a `Vector{Complex(eltype(x))}` of length `n`
end

```

For the time being, only the most basic version of the SDFT is implemented (the `SDFT` type used in the previous example). There are many possible variations (see for instance [Chauhan and Singh’s paper](https://doi.org/10.1016/j.dsp.2022.103560) cited in the linked post above), and the package provides an interface to facilitate the implementation of new methods, either as PRs to this one or in independent packages ([see the docs](https://heliosdrm.github.io/SlidingDFTs.jl/dev/implement/)). I plan to implement myself at least the rSDFT, but I’m happy to leave it to others if someone doesn’t want to wait for me.

I have not registered the package because I would like others to review it first and give suggestions about how to improve it (@roflmaostc kindly offered to do it in the old post). I’m not particularly fond of the names of structs and functions, so feel free to make suggestions about them too. Also about the general structure - e.g. is it ok to have the interface and the particular implementations in a single package because the code base is small, or would it be preferable to split it?, etc.

I’m also open to suggestions about maintenance. I’m not particularly interested in “owning” the package, since to be honest this is not a tool that I’ll be using that often. (It’s useful for a project I’m involved in right now, but once that project is over I may not use it anymore.) So, if this is worth to be integrated as part of another package, or transferred to an organization, instead of registering it as it is, I’ll be fine with that too.

---

<div class="post-metadata">

**Author:** ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Post date:** [December 14, 2024, 11:33am UTC](https://discourse.julialang.org/t/ann-announcing-slidingdfts-jl/123793/2 "2024-12-14T11:33:29Z")

</div>

Amazing!  
I can try to review it, maybe also making it GPU compatible (if worth it).  
But if it’s only 1D, maybe not a big deal.

If you agree, we can move it to FourierTools.jl, you could start a PR and I could review it. In that way it might stay maintained 🙂

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [December 14, 2024, 10:56pm UTC](https://discourse.julialang.org/t/ann-announcing-slidingdfts-jl/123793/3 "2024-12-14T22:56:29Z")

</div>

Done!

> <https://github.com/bionanoimaging/FourierTools.jl/pull/49>
>
> Following the recommendation in: https://discourse.julialang.org/t/ann-announcin…g-slidingdfts-jl/123793
> 
> This is an adaptation of https://github.com/heliosdrm/SlidingDFTs.jl for FourierTools. Some points to note:
> \* This PR actually contains two things: an interface to use and develop SDFTs, and the actual implementation of SDFT methods. Accordingly, two files are included in \`src\`: \`sdft\_interface.jl\` (with a module \`SlidingDFTs\`), and \`sdft\_implementations.jl\`. The documentation page deals with both of them in different sections.
> \* Only the most basic method is implemented for the time being. At least the rSDFT will follow if this is approved.
