How is the filter() implemented in MATLAB? How is it so fast?
What's the fastest implementation of a FIR filter?

  • $\begingroup$ You may look on the code of Octave and Scipy. $\endgroup$
    – Mark
    Feb 23, 2021 at 5:35

2 Answers 2


Actually it seems MATLAB implementation of the filter() function is pretty straight forward and not fast.

For a fast implementation, have a look at FilterM by Jan Simon.


In the latest releases of MATLAB (From R2016b and above) the performance of the filter() function has improved.
The methods to accelerate those operations are usually based on:

  1. Utilizing Vectorized / SIMD Operations (SSE / AVX in x86).
  2. Multi Threading.
  3. Loop Unrolling.

Update (2021):
In recent MATLAB versions the function was accelerated using parallelization and vectorization.

  • $\begingroup$ MATLAB uses a time domain Direct Form II Transposed Canonical structure to realize its filter() or conv() functions. It's not specifically designed to be fast. An FFT based implementation would be faster or fastest when data lengths are suitable... $\endgroup$
    – Fat32
    Nov 18, 2019 at 13:32
  • $\begingroup$ Actually fft() based will be faster only in the cases dimensions are really perfect for it which doesn't happen often in my experience. Filtration both with fft() or directly on data are usually memory bounded and the fft() approach stresses memory more. $\endgroup$
    – Royi
    Nov 18, 2019 at 14:32
  • $\begingroup$ By the way, MATLAB's conv() is much faster than filter() in the cases of FIR filters. $\endgroup$
    – Royi
    Nov 18, 2019 at 14:33
  • $\begingroup$ I don't know your MATLAB version but in my(old) version its help says The conv function is an M-file that uses the filter primitive.... So I don't how how it could be faster ? May be newer versions use other approaches ? $\endgroup$
    – Fat32
    Nov 18, 2019 at 17:54
  • $\begingroup$ And about fft() version, yes the length should be suitable for fastest performance, otherwise you will not get the benefit... $\endgroup$
    – Fat32
    Nov 18, 2019 at 17:55

filter() implements an IIR-filter. You mention FIR filter. While IIR is a generalization of FIR, it makes some sense to think of them as two different things wrgt optimization.

Generally, MATLAB may use libraries or point optimizations implemented in FORTRAN, C or Assembly using algorithmic optimizations, as well as SIMD, multi threading or any other clever trick that makes the function faster while still deemed sufficiently general and accurate


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.