Sign in

username:

password:



Not a member?

Search Online Books



Search tips

Free Online Books

Sponsor

Industry's highest performing at the lowest power DSPs now as low as $5.00*
Start development today!
*volume pricing for 10ku

Chapters

See Also

Embedded SystemsFPGAElectronics
Chapter Contents:

Search Introduction to Digital Filters

  

Book Index | Global Index


Would you like to be notified by email when Julius Orion Smith III publishes a new entry into his blog?

  

FIR Software Implementations

In matlab, an efficient FIR filter is implemented by calling

        outputsignal = filter(B,1,inputsignal);
where

$\displaystyle \texttt{B} = [b_0, b_1, \ldots, b_M].
$

It is relatively efficient because filter is a built-in function (compiled C code in most matlab implementations). However, for FIR filters longer than a hundred or so taps, FFT convolution should be used for maximum speed. In Octave and the Matlab Signal Processing Toolbox, fftfilt implements FIR filters using FFT convolution (say ``help fftfilt'').

Figure 5.6 lists a second-order FIR filter implementation in the C programming language.

Figure 5.6: C code for implementing a length 3 FIR filter.

 
  typedef double *pp;  // pointer to array of length NTICK
  typedef double word; // signal and coefficient data type

  typedef struct _fir3Vars {
      pp outputAout;
      pp inputAinp;
      word b0;
      word b1;
      word b2;
      word s1;
      word s2;
  } fir3Vars;

  void fir3(fir3Vars *a)
  {
      int i;
      word input;
      for (i=0; i<NTICK; i++) {
          input = a->inputAinp[i];
          a->outputAout[i] = a->b0 * input
                +  a->b1 * a->s1  +  a->b2 * a->s2;
          a->s2 = a->s1;
          a->s1 = input;
      }
  }


Previous: FIR Order
Next: Transient Response, Steady State, and Decay

Order a Hardcopy of Introduction to Digital Filters


About the Author: Julius Orion Smith III
Julius Smith's background is in electrical engineering (BS Rice 1975, PhD Stanford 1983). He is presently Professor of Music and Associate Professor (by courtesy) of Electrical Engineering at Stanford's Center for Computer Research in Music and Acoustics (CCRMA), teaching courses and pursuing research related to signal processing applied to music and audio systems. See http://ccrma.stanford.edu/~jos/ for details.


Comments


 

pernyblom wrote:

8/11/2009
 
In my browser (IE8), the C code is centered which makes it difficult to read.
Thanks for sharing these great book online!

Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )