16
$\begingroup$

IIR filters may be implemented as direct form 1 or 2. But how do you decide which form to use? What are the pros and cons of each?

$\endgroup$
  • $\begingroup$ Moreover, what is the best way to implement them on GPU. $\endgroup$ – Royi Aug 18 '11 at 14:13
  • 2
    $\begingroup$ @Drazick, GPUs are a whole different game. requiring another quesiton. $\endgroup$ – Trevor Boyd Smith Aug 21 '11 at 16:59
9
$\begingroup$

First of all, a bit from wikipedia on Direct Form I and II implementation.

Direct form I requires more memory, but is a somewhat simpler strategy, and is less likely to have round-off and resonance problems.

Direct form II requires less memory, but it has the potential for unusual interactions, larger numbers, and more round off error. Much of this can be reduced by cascading smaller filters, especially 2nd order filters.

$\endgroup$
  • 2
    $\begingroup$ In either case, you should be cascading second-order sections. $\endgroup$ – Oliver Charlesworth Aug 18 '11 at 11:58
  • 1
    $\begingroup$ So, in short, is it memory vs round-off error trade-off? $\endgroup$ – anasimtiaz Aug 18 '11 at 13:23
  • 2
    $\begingroup$ Super weak answer IMO. Technically it answers the question... but only "technically". I would like to see some source code in a language. I know how to implement an FIR filter that is easy. Let's see IIR source code. $\endgroup$ – Trevor Boyd Smith Aug 21 '11 at 17:00
  • 2
    $\begingroup$ Also, in terms of mathematical operations performed per sample, which is a better implementation I or II? $\endgroup$ – anasimtiaz Aug 22 '11 at 10:30
  • 1
    $\begingroup$ i know how to do FIR filtering. i also know what is direct form I/II/III/IV. what i don't have experience doing is IIR: design or implementation. My original comment was not very constructive. I should have said "I understand what is direct form I-IV, would you please talk more about how you design/implement an IIR filter?" $\endgroup$ – Trevor Boyd Smith Sep 8 '11 at 17:29
9
$\begingroup$

A little dated but may deserve a more comprehensive answer, especially since Direct Form II can get you into a lot of trouble. First of all, there is no "one size fits all" and the best choice depends on your specific application and constraints. What you can consider is

  1. Memory: Direct Form II and Transposed Form II take a little less state memory then Direct Form I and Transposed Form I but in a cascaded second-order section implementation the difference is minor
  2. MIPS: In terms of number of multiplies and additions, all four implementations are the same. However depending on the instruction set of the specific processor, there can be significant differences in implementation efficiency. So "it depends".
  3. Fixed Point properties: This makes a huge difference. Primarily you have to make sure that your state variables don't overflow so you need to analyze the transfer function between in/output and the state variables. Here Direct Form I and Transposed Form II are the clear winners. State variables are bound to +106dB or thereabouts vs input and output. In direct Form II for example, the transfer function from input to state is given by the poles only. I have seen real world examples where this can actually exceed 100 dB of gain. This is an absolute no non for fixed point implementation.
  4. Noise: In terms of truncation and round off error, all implementations are roughly the same. The state variable transfer function problem mentioned in 3) also affects this to some extend and I have seen audible noise issues with Direct Form II filters even when using 32-bit floating point.

So in summary Transposed Form II is more often than not the best choice. In some fixed point scenarios, especially if there are significant noise problems Direct Form I is better since it can more easily augmented with things like Error Spectrum Shaping, etc.

$\endgroup$
  • $\begingroup$ This is a much more comprehensive and better answer! $\endgroup$ – Lorem Ipsum Sep 14 '11 at 14:34
  • 2
    $\begingroup$ I figured out today - in a much harder way - why Direct Form I is a better choice for my application. Thanks for a really good answer! $\endgroup$ – anasimtiaz Sep 14 '11 at 15:04
1
$\begingroup$

Unless your working with a very resource-scarce system or have extreme requirements it really doesn't matter in practice whether you choose direct form I or II. For instance, if you're doing stuff on a PC or a smartphone it really doesn't matter. Personally, I prefer Form I.

The real issue is normally MIPS and if you plan to do a fixed-point implementation things get more complicated. For instance, on ARM your IIR filter will consume much more MIPS if both coefficients and filter states are 32-bits. 32 bits in states and coefficients is a requirement if you need to implement for instance a low-pass filter with very low cut-off frequency. In those cases you can use a different type of filter, such as for instance a state-variable filter.

$\endgroup$
1
$\begingroup$

Aside from the technical differences such as numerical accuracy, there is also the issue of stability. When digital filters have pole/zero pairs close to each other, the frequency response can become unstable at various locations (usually approaching Nyquist or approaching zero).

When IIR filters are used for musical applications, the choice of realization can have a profound effect on filter stability when filter parameters are modulated in real time (for example, varying the cut-off frequency on a low pass filter).

I have an open source application that lets you listen to the differences, while time-varying parameters such as cutoff frequency or peak gain, of each of the following realizations:

  • Direct Form I
  • Direct Form II
  • Transposed Direct Form I
  • Transposed Direct Form II
  • Lattice Form
  • State Variable

The project is here:

https://github.com/vinniefalco/DSPFiltersDemo.git

https://github.com/vinniefalco/DSPFilters.git

Screenshot

$\endgroup$
  • 1
    $\begingroup$ You've posted this several times, and I'm inclined to enforce spam policy unless your answers are actually tailored to the questions. None of these posts answer questions directly, and also promote a product. Edit them to directly answer the questions or they will be removed. $\endgroup$ – Phonon Aug 24 '12 at 20:32
0
$\begingroup$

In addition to the comments above about memory, MIPS, noise, and stability; there is another factor that is commonly overlooked. This factor is reset capability; which happens to be very important in most of my situations.

With a Direct Form II implementation, there are no states for the delayed outputs, therefor if you "reset" a Direct Form II filter to say "5", it's initial output is not going to be 5. I find this to be quite counter-intuitive which has caused some serious frustration when using Simulink. For this reason I almost always use a Direct Form I implementation. Unfortunately Simulink only supports Direct Form I if you have the DSP toolbox, and even then it still doesn't let you set the initial conditions from an input signal.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.