A MATLAB Coder compatible filter function, capable of 2nd order high, low, and bandpass filters and their combinations.
Creative Commons 0 i.e. do what you want with it!
I often use MATLAB coder to speed up simulations. A generic filtering function can be useful in these simulations, but MATLAB's filter design functions (specifically
butter()) do not support code generation. For this reason I built my own quick-and-easy 2nd order, cascadable filter.
- Only designed for 1D signals.
- Not all filters possible with a biquad are included, only high/low/bandpass.
coderFilter(x, fs, fc, Q, type)
x and it's sample rate
fs form the first two arguments of the filter, followed by the cutoff frequency
fc in hertz,
Q and the type of filter (
To cascade multiple 2nd order sections, simply add additional entries to the arguments
type. These must each be the same length.
Example filter responses
The following amplitude responses were generated with the testbench file
coderFilter_testbench.mat. The first plot shows the cascading of several 2nd order sections, performed within
cascadeSSM(). The second is a bandpass filter consisting of a highpass filter at 10 Hz and a lowpass filter at 1 kHz, both with different Q values.