# Fourier transform freezes Julia

I am processing an audio sample (about 20minutes long) in small parts of several seconds.

At the moment my code freezes every now and then. The example below is a bit silly but is a minimal ‘working’ example which often stops within the first 100 iterations.

``````using FileIO, SampledSignals, LibSndFile, FFTW

for T in 10s:0.1s:1000s
print( T)
a = [ fft( ls[ (t-0.1s)..(t-0.1s+1s)]) for t in .1s:.1s:T]
end
``````

The next loop is similar except for the interval / indexing but seems to work without issues:

``````# this works ...
for T in 10s:0.1s:1000s
print( T)
a = [ fft( ls[ t..(t+10s)]) for t in .1s:.1s:T]
end
``````

For me it is unclear why the first loop has a problem but the second loop not. Garbage collection within the first loop seem to stabilize the code, but makes it terribly slow, of course.

I would like to make clean and efficient code, but as I am not sure what the problem is (indexing / memory / IntervalSets), I cannot manage it… Any help is appreciated!

1 Like

I checked another OS…

The above problem occurs when using Linux, often within a few minutes. With Windows, it seems that the issue does not occur.

No idea what it might be but maybe you could try planning the FFT to see if it helps anything? You could also try in-place FFTs via `mul!`, either just do it in-place on those slices that are created in each iteration which are allocating an array anyway, or pre-allocate everything you need for the results to start, and then use views of each slice so they don’t allocate (I’m actually not sure Julia can FFT views without making a copy, but worth checking). You could also try `rfft` to get a factor of 2x in speed / memory usage, assuming those input samples are real.

https://juliamath.github.io/AbstractFFTs.jl/stable/api/#AbstractFFTs.plan_fft

Also, if you have FFTW built with MKL, try turning that off, or if you don’t, try turning it on (MKL is generally faster, but maybe your error is tied to one or the other).

I had already tried using in-place FFT via `fft!`, but that froze the evaluation as well.

I will try to perform a planned FFT, and also see if I can toggle the MKL. Thanks for these tips. The latter could be an explanation as to why it works on Windows but not on Linux(?)

Upgrading my Linux Julia installation from v1.3.0 to v1.4.0 fixed the issue.