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?

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

1 Answer 1


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.

  • $\begingroup$ Thanks. So let me understand: should I be summing the four previously-filtered samples (assuming a filter order of 4) with the current sample and previous three samples that have not been filtered? The way I do it now, I sum the current, unfiltered sample with the previous filtered sample (i.e. a filter order of 1). What you propose looks like the same idea, just with more samples (and more coefficients due to the increased sample count). $\endgroup$
    – Synthetix
    Jul 6, 2015 at 21:47
  • $\begingroup$ @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$). $\endgroup$
    – Matt L.
    Jul 7, 2015 at 6:56

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.