Skip to content

Implement bluestein algorithm for prime size FFT (Trac #579) #1177

Closed

Activity

  1. numpy-gitbot commented on Oct 23, 2012

    @numpy-gitbot
    Author

    Milestone changed to 1.1 by @cournape on 2007-09-14

  2. numpy-gitbot commented on Oct 23, 2012

    @numpy-gitbot
    Author

    Milestone changed to 1.3.0 by @cournape on 2008-08-13

  3. numpy-gitbot commented on Oct 23, 2012

    @numpy-gitbot
    Author

    Milestone changed to Unscheduled by @cournape on 2009-03-02

  4. numpy-gitbot commented on Oct 23, 2012

    @numpy-gitbot
    Author

    @endolith wrote on 2009-12-01

    From #1104:

    According to

    http://www.fftw.org/fftw-paper-ieee.pdf

    FFTW implements Bluestein's algorithm. A python implementation is available at

    http://www.mail-archive.com/[email protected]/msg01812.html

    Also, here is [http://healpix.jpl.nasa.gov/html/libfftpack/bluestein_8c-source.html Bluestein algorithm] written for a C port of fftpack, [http://healpix.jpl.nasa.gov/html/libfftpack/group__fftgroup.html#_details described here]

  5. endolith commented on Dec 18, 2014

    @endolith
    Contributor

    So as I understand it, the Bluestein algorithm was originally developed to do FFTs, and then the concept was expanded into the Chirp Z-transform, and DFT and zoom-FFT are special cases of CZT (CZT does spirals through Z plane, while circles and arcs are subtypes of spiral), so if we have a CZT then this can do the prime FFTs and zoom FFTs.

    Turns out this has already been submitted to SciPy under public domain by Paul Kienzle and Nadav Horesh: [SciPy-user] Chirp Z transform and it works:

    x = rand(42073) # prime length
    
    allclose(czt(x), fft(x))
    Out[37]: True
    
    timeit czt(x)
    10 loops, best of 3: 53.9 ms per loop
    
    timeit fft(x)
    1 loops, best of 3: 2.35 s per loop
    
    2.35 / 53.9e-3 # speedup factor
    Out[40]: 43.59925788497217
    

    @stefanv said:

    Thank you both for the contribution! I've reviewed the code and think
    it should be included in SciPy. Would someone else like to have a
    look before I commit it?

    Where would the best place for this be? scipy.fftpack?

    The submission probably does belong in scipy.fftpack because it's specialized and has classes to generate functions, etc. But this bug is for numpy, should some variant be included in numpy too, or should it all be in numpy?

  6. endolith commented on Dec 18, 2014

    @endolith
    Contributor
  7. endolith commented on Jul 18, 2015

    @endolith
    Contributor

    So I started merging the CZT functions by Paul Kienzle and Nadav Horesh, and modified it to have good accuracy as a prime-length FFT replacement.

    N = 100003
    
    is_prime(N)
    Out[132]: True
    
    timeit is_prime(N)
    1000000 loops, best of 3: 755 ns per loop
    
    a = randn(N)
    
    allclose(czt(a), fft(a))
    Out[135]: True
    

    The CZT requires pre-computing large chirp signals, though, which means calling it like this isn't as efficient as it could be. Their code has classes that create a function for a specific-length transform so that it can be called repeatedly on multiple arrays of the same length and the chirps are only generated once. Still, the inefficient function version is faster for prime sizes above ~500:

    timeit czt(a)
    10 loops, best of 3: 85 ms per loop
    
    timeit fft(a)
    1 loops, best of 3: 18.7 s per loop
    

    Should a simplified FFT-only version of this be added to NumPy?

    I think in FFTW they always pre-compute which algorithm will be fastest anyway, before applying it to lots of data? So generating the chirps would be part of that.

  8. mreineck commented on Apr 5, 2019

    @mreineck
    Contributor

    Numpy 1.17 contains an FFT implementation supporting Bluestein's algorithm.

  9. endolith commented on Apr 5, 2019

    @endolith
    Contributor

    @mreineck Which pull request is that from?

  10. mreineck commented on Apr 5, 2019

    @mreineck
    Contributor

    It's #11888

  11. seberg commented on Apr 5, 2019

    @seberg
    Member

    Cool, one more closed issue :), thanks @mreineck.

  12. fasiha commented on Nov 29, 2019

    @fasiha

    Numpy 1.17 contains an FFT implementation supporting Bluestein's algorithm.

    @mreineck, is Bluestein's algorithm available for all functions in numpy.fft, including rfft* irfft* (1D and up, direct and inverse, real FFT)? Or just some subset? I didn't see any mention of "Bluestein" in the 1.17 docs.

  13. mreineck commented on Nov 29, 2019

    @mreineck
    Contributor

    Yes, Bluestein's algorithm is used in all sorts of transforms if they have a length containing too large prime factors. Unfortunately, if Bluestein is used, a real-valued transform has no speed benefit compared to a complex-valued one any more, since the FFTs carried out within Bluestein's algorithm are intrinsically complex-valued, but at least the O(N**2) scaling is avoided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions