17
$\begingroup$

Although I have a solid experience in designing audio engines and such, I am fairly new to the realm of Digital Filter Design, particularly IIR and FIR filters. In other words, I'm trying to learn as much as I can on how to design filters and derive their difference equations. I'm starting from the basics, so please bear with me, like I said, I'm trying to learn.

Herein is my question:

Say I want to design a low-pass filter with a particular cutoff - say 300 Hz. What would be the best way of mathematically deriving the transfer function and then deriving the particular difference equation to implement the filter in Direct Form I and Direct Form II (or only DF-1 for now...)?

I have some understanding of transfer functions and how they relate to difference equations from some excellent material on the web, unfortunately some of it assumes a good bit of prior knowledge, so it is more confusing than helpful in my quest. So I guess I need a more step-by-step example which will help me connect the dots.

So I'm basically looking for help with a breakdown of the process starting from choosing the cutoff frequency up to deriving the difference equation.

Any help will be much appreciated. I am familiar with a lot of the concepts - impulse response, DFT's, the math behind it, I guess what I need more help with is the concept of the z-transform and the pole/zero use to design the filter's transfer function and then how does the cutoff freq. play in all this to finally derive the difference equation.

Since I tend to learn best from example, I thought I'd ask here. Thanks a lot to anyone who finds the time to help me out.

$\endgroup$
1
  • 2
    $\begingroup$ There are many filter design methods. Here are a few terms to get you started: the window design method, least-squares filter design, and equiripple filter design (usually using the Parks-McClellan algorithm). These are mostly limited to FIR filter designs. One common way of designing IIR filters is by mapping an analog prototype (like a Butterworth filter) to a corresponding digital filter approximation. This could be done using the bilinear transform or impulse invariance methods, for example. $\endgroup$
    – Jason R
    Commented Jun 10, 2013 at 20:07

1 Answer 1

27
$\begingroup$

Digital filter design is a very large and mature topic and - as you've mentioned in your question - there is a lot of material available. What I want to try here is to get you started and to make the existing material more accessible. Instead of digital filters I should actually be talking about discrete-time filters because I will not consider coefficient and signal quantization here. You know already about FIR and IIR filters, and you also know some filter structures like DF I and II. Nevertheless, let me start with some basics:

A non-recursive linear time-invariant (LTI) filter can be described by the following difference equation

$$y(n)=h_0x(n)+h_1x(n-1)+\ldots +h_{N-1}x(n-N+1)=\sum_{k=0}^{N-1}h_kx(n-k)\tag{1}$$

where $y(n)$ is the output sequence, $x(n)$ is the input sequence, $n$ is the time index, $h_k$ are the filter coefficients, and $N$ is the filter length (the number of taps). The filter taps $h_k$ are also the impulse response of the filter because if the input signal is an impulse, i.e. $x(n)=\delta(n)$, then $y(n)=h_n$ (if the filter's memory has been initialized with zeros). Equation (1) describes a linear time-invariant finite impulse response (FIR) system. The sum on the right-hand side of (1) is a convolution sum, i.e. the output signal is obtained by convolving the input signal with the impulse response. This is always true, but for IIR filters we cannot explicitly compute the convolution sum because the impulse response is infinitely long, i.e. there are infinitely many coefficients $h_k$. One important advantage of FIR filters is that they are always stable, i.e. for a bounded input sequence, the output sequence is always bounded. Another advantage is that FIR filters can always be realized with an exactly linear phase, i.e. they will not add any phase distortion apart from a pure delay. Furthermore, the design problem is usually easier, as we will see later.

A recursive LTI filter is described by the following difference equation:

$$y(n)=b_0x(n)+b_1x(n-1)+\ldots+b_Mx(n-M)-\\ -a_1y(n-1)-\ldots-a_Ny(n-N)\tag{2}$$

Equation (2) shows that the output is not only composed of weighted and delayed input samples, but also of weighted past output samples. In general, the impulse response of such a system is infinitely long, i.e. the corresponding system is an IIR system. However, there are special cases of recursive filters with a finite impulse response. Note that the impulse response is not anymore given by either the coefficients $b_k$ or $a_k$ as in the case of FIR filters. One advantage of IIR filters is that steep filters with high stopband attenuation can be realized with much fewer coefficients (and delays) than in the FIR case, i.e. they are computationally more efficient. However, one needs to be careful with the choice of the coefficients $a_k$ because IIR filter can be unstable, i.e. their output sequence can be unbounded, even with a bounded input sequence.

Filters can be designed according to specifications either in the time (sample) domain or in the frequency domain, or both. Since you've mentioned a cut-off frequency in your question, I assume you're more interested in specifications in the frequency domain. In this case you need to have a look at the frequency responses of FIR and IIR systems. The frequency response of a system is the Fourier transform of its impulse response, assuming that it exists (which is the case for stable systems). The frequency response of an FIR filter is

$$H(e^{j\theta})=\sum_{k=0}^{N-1}h_ke^{-jk\theta}\tag{3}$$

where $\theta$ is the discrete-time frequency variable:

$$\theta=\frac{2\pi f}{f_s}$$

with the actual frequency $f$ and the sampling frequency $f_s$. From (3) you can see that approximating a desired frequency response by an FIR system is basically a problem of polynomial approximation. For recursive systems we have

$$H(e^{j\theta})=\frac{\sum_{k=0}^Mb_ke^{-j\theta}}{1+\sum_{k=1}^Na_ke^{-j\theta}}\tag{4}$$

and you get a rational approximation problem, which is usually much more difficult than the polynomial approximation problem in the case of FIR filters. From (3) and (4) you can see that the frequency response of an FIR filter is of course only a special case of the response of a recursive filter with coefficients $a_k=0$, $k=1,\dots,N$.

Let's now take a quick look at filter design methods. For FIR filters you could take an inverse Fourier transform of the desired frequency response to get the impulse response of the filter, which directly corresponds to the filter coefficients. Since you approximate the desired response by a finite length impulse response you should apply a smooth window to the obtained impulse response to minimize oscillations in the actual frequency response due to Gibbs' phenomenon. This method is called frequency-sampling method.

For simple standard filters like ideal lowpass, highpass, bandpass or bandstop filters (and a few others), you could even analytically calculate the exact impulse response by taking the inverse Fourier transform of the ideal desired response:

$$h_k=\frac{1}{2\pi}\int_{-\pi}^{\pi}H(e^{j\theta})e^{jk\theta}d\theta$$

This integral is easy to evaluate for piecewise constant desired responses, as is the case for ideal frequency-selective filters. This will give you an infinitely long, non-causal impulse response, which needs to be windowed and shifted to make it finite and causal. This method is know as window-design.

There are of course many other FIR filter design methods. One important numerical method is the famous Parks-McClellan exchange algorithm which designs optimal filters with constant passband and stopband ripples. It is a numerical approximation method and there are many software implementations available, e.g. in Matlab and Octave.

The most common IIR design method for frequency selective filters is the bilinear transformation method. This method simply uses analytical formulas for the design of optimal analog filters (such as Butterworth, Chebyshev, Cauer/elliptic, and Bessel filters), and transforms them to the discrete-time domain by applying a bilinear transformation to the complex variable $s$ (analog domain) which maps the (imaginary) frequency axis of the complex $s$-plane to the unit circle in the complex $z$-plane (discrete-time domain). Don't worry if you do not yet know much about complex transfer functions in the analog or discrete-time domain because there are good implementations available of the bilinear transform method, e.g. in Matlab or Octave.

There are of course many more interesting and useful methods, depending on the type of specifications you have, but I hope that this will get you started and will make any material you come across more understandable. A very good (and free) book covering some basic filter design methods (and a lot more) is Intoduction to Signal Processing by Orfanidis. You can find several design examples there. Another great classic book is Digital Filter Design by Parks and Burrus.

$\endgroup$
3
  • 1
    $\begingroup$ Wow, Matt, thanks so much for the detailed and thoughtful answer. I will surely delve into it and truly appreciate your time. Thanks! $\endgroup$
    – bitwise
    Commented Jun 11, 2013 at 14:47
  • $\begingroup$ Is there any good textbook for wavelet filter design ? I am curious about such a topic: dsp.stackexchange.com/questions/29090/…. Thanks! $\endgroup$ Commented Mar 4, 2016 at 3:59
  • $\begingroup$ A very good intro and motivates to do something in the field of Signal Processing $\endgroup$
    – jomegaA
    Commented Feb 3, 2020 at 7:29

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.