# Possible to implement simple IIR filter with greater than 6 db/octave slope?

I am using the following IIR code as a low-pass filter in a software project, and it works great. However, I would like the slope of the filter to be much steeper as the one here seems to be very gradual (6 db/octave, from what I understand):

#define CUTOFF_FREQ 500.0
#define SAMPLE_RATE 48000.0

float RC = 1.0/(CUTOFF_FREQ*2*M_PI);
float dt = 1.0/SAMPLE_RATE;
float alpha = dt/(RC+dt);

float output_sample,prev_sample,cur_sample;

/* Run the filter on the two samples (normally done inside a loop) */
output_sample = prev_sample + (alpha*(cur_sample - prev_sample));


I would like perhaps a 12 db/octave slope or even 18 db/octave, similar to the low-pass filters in popular audio programs. Is it possible to modify this code for this purpose? Or should I be looking into alternate implementations altogether?

• you might want to check out <micromodeler.com/dsp> which will generate appropriate C code for the criteria you select for a filter. Jun 13, 2015 at 11:14

You need a filter with a higher filter order, which means that your filter memory must be longer. The current output sample $y[n]$ is computed as
$$y[n]=a_1y[n-1]+a_2y[n-2]+\ldots + a_Ny[n-N]+b_0x[n]+b_1x[n-1]+\ldots + b_Nx[n-N]$$
where $x[n]$ is the current input sample, $N$ is the filter order, and $a_i$ and $b_i$ are the filter coefficients. You can design the filter (i.e., compute the coefficients) using some tool like Matlab or Octave.
• @Synthetix: For a 4th order filter you compute a weighted sum of the last 4 output samples, the last 4 input samples, and the current input sample, just like in the formula in my answer (with $N=4$). Jul 7, 2015 at 6:56