How is the
filter() implemented in MATLAB? How is it so fast?
What's the fastest implementation of a FIR filter?
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:
- Utilizing Vectorized / SIMD Operations (SSE / AVX in
- Multi Threading.
- Loop Unrolling.
In recent MATLAB versions the function was accelerated using parallelization and vectorization.
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