I did a comparison between 3 methods of convolution:
- Direct (Using MATLAB’s
conv()
). - Using Overlap and Save (Implemented in MATLAB, no allocation in the loop).
- In frequency domain (Using
fft()
).
This is the result I got:
We have signal length and kernel length. I only did the case the signal isn’t shorter than the kernel.
So the upper triangle of the matrix, in Dark Blue isn’t relevant.
In the diagonal and lower triangle we have which method was faster:
- Light Blue - Direct.
- Green - Overlap and Save.
- Yellow - Frequency Domain.
I am not sure what cases you use, but as you can see, there is almost no reason to use Overlap & Save.
In my opinion, as long you have the whole data in memory use either direct (Cases the kernel is shorter than ~400-500 samples in the implementation above) or Frequency Domain.
I’d even mention that MATLAB’s conv()
is probably much slower than what you can do with LoopVectorization.jl
in Julia.
This was an answer to Convolution Strategy / Method for the Fastest 1D Convolution.
@ElectronicTeaCup, In the code I posted in the answer to the question you will be able to see which exact samples you need to extract in order to replicate MATLAB’s same
.
Though the optimal thing to do will be implementing direct convolution using LoopVecotrization.jl
which on the computation only compute the required samples (full
, same
or valid
). The current approach in DSP.jl
is sub optimal in my opinion.