# Digital filtering

Dave Higton (1515) 1515 posts |
I’ve been working on some digital filters at work for the last few weeks. It’s been interesting. The application is a voice recorder front end. Audio is sampled at 32 kHz and low pass filtered to remove everything above 4 kHz, then every 4th output sample is taken. The filtering is comprised of three digital biquad filters, which are actually the same block used three times but with different coefficients. Two interesting things have shown up: 1) If you just use integer arithmetic of the same word length all the way through, some output codes are unreachable. You just have to crunch some numbers yourself, using real filter coefficients, to see why. The internal arithmetic has to be done with a few fractional bits as well as the integers. 2) If you just use integer arithmetic of the same word length all the way through, a large sudden transition at the input can cause the output to clip at the extreme of the numeric range. Passing this clipped set of values through to the next stage increases the amplitude and duration of the disturbance. The internal arithmetic has to be done with at least double the numeric range of the original input. Clipping at the final output is acceptable and is the least worst thing that can be done. To get communications quality audio, we have had to process with internal word lengths of 24 bits – probably 21 would have been OK, but, since the delay RAM comes in 8 bit wide modules, 24 does the job. The internal numbers are 17 bits integer and 7 bits fraction. It’s also an interesting comparison between FIR and IIR filters for decimation. With FIR, you only need to compute every output sample. With IIR, you have to compute every input sample and then discard the output samples that you don’t want, because the filter maintains an ever-moving (and in theory infinite) history. |

Jon Abbott (1421) 1254 posts |
Interesting indeed. Does this mean you’ll be applying your new found skills to an IIR filter we could use with the RISCOS soundsystem ;) Personally, I’ve never been a fan of FIR filters, they just seem computationally wasteful. Aren’t IIR filters supposed to be a closer match to analogue filters anyhow? |

jim lesurf (2082) 1104 posts |
Agree in general with your comments. FWIW I used simple FIR filtering for my upsampling demos, and used some bits shifting to get a fractional part for the ‘integer’ values. I prefer FIR because its easier to design for things like low-pass and resampling filters with preferred shapes. Simply use a FT approach to work out the coefficients from the required response. Admittedly, you then have to bend and scale the coefficients a little to take the finite time range into account. I assume you’ve seen the code I wrote for my demos as I think we spoke about it ages ago. I’ve been hesitant of IIR biquads, etc, because of the risk of large internal values that clip, etc. But I did do some demos as narrow notch filters for ‘Archive’ magazine years ago to let people cut down 50/100 Hz hum on recordings.The extent of ‘waste’ tends to depend on the application in my experience.
So much for my doing my demos in the hope someone would do them Jim |

Dave Higton (1515) 1515 posts |
It’s unlikely. I have very little motivation to work on audio. It may appear bizarre, but the only time I listen to anything (except a bit of TV) is in the car (Radio 3). I can’t sit here with music on, otherwise I’d listen to it and never get anything done. I don’t know of any design methodolgy for cascaded biquad filters. I’ve seen a method for a single biquad, but a single biquad doesn’t filter enough to be useful. Cascading identical filters never produces an optimal response – you need to consider the overall response and then see how you would synthesise a good enough approximation from smaller sections. FIR is easy: just use the Remez Exchange algorithm. But any result that we would consider good enough for hi-fi is too compuationally expensive for an ARM, particularly as you need an accumulator bigger than 32 bits. (Even the comms grade stuff I just did was 16 bit coefficients times 24 bit samples, giving a 40 bit result, summed into a 48 bit accumulator.) I would be much more interested in getting the DSP of an OMAP up and running so we could write and run arbitrary code. Then we could offload so much processing on at least some of our platforms. |

Dave Higton (1515) 1515 posts |
Oh – and you’ll never get IIR filters past Jim. They’re unstable. But perhaps he’ll call it dither… |

jim lesurf (2082) 1104 posts |
The trick is to treat each biquad as a digital model of a 2nd order When I do that sort of thing I crib from Active-Filter Cookbook by Don Lancaster However I got my copy from Farnell mumble years ago, so it’s probably long out of print! It gives examples of how to combine two 2nd order filters as a 4th order with optimum behaviour, etc.
No, its me that dithers about them. :-) I don’t mind them if they have been well designed by someone who knows how to ensure they are stable, avoid clipping, etc. Problem is I also worry about the IIR filters used in things like SACD because these risks exist and the makers refuse to specify what they’ve done. And that when I modelled what they Agree with your point about the number of bits per value. But I’d say that for IIR as well. :-) Jim |

### Reply

To post replies, please first log in.