fftjuliazero-pad

Zero-padded FFT in Julia


How can I calculate the fft zero-padded to a specific length in Julia? Naturally, I can append zeros to my vector, but that seems awkward.

I cannot find anything about this in the docs, nor does calling methods(fft) seem to bring up any relevant method signatures. I cannot find anything relevant for plan_fft either.


Solution

  • I don't think there are any keyword arguments to do this or something like that if thats what you were looking for?

    The nextpow2() and nextprod() functions are useful for getting the size of the array to input to fft(). Then you can either create an array of zeros that is a more efficient size and fill it with your data. Or you can append the difference between the ideal-size and your array-size to your array (the former is better if you are computing lots of fft's as then you can reuse the input array by just re-filling it each time).

    One-liner from comments datpad = [dat; zeros(eltype(dat), nextprod(length(dat)) - length(dat)]

    http://docs.julialang.org/en/release-0.5/stdlib/math/?highlight=fft#signal-processing In case you haven't already checked that out!