<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="m10624">
  <name>IIR Filtering: Exercise on TI TMS320C55x</name>
  <metadata>
  <md:version>1.3</md:version>
  <md:created>2006/07/26 11:22:45 GMT-5</md:created>
  <md:revised>2007/02/19 17:07:57.028 US/Central</md:revised>
  <md:authorlist>
      <md:author id="tbshen">
      <md:firstname>Thomas</md:firstname>
      
      <md:surname>Shen</md:surname>
      <md:email>tbshen@uiuc.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="tbshen">
      <md:firstname>Thomas</md:firstname>
      
      <md:surname>Shen</md:surname>
      <md:email>tbshen@uiuc.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>block repeat counter</md:keyword>
    <md:keyword>butter</md:keyword>
    <md:keyword>conv</md:keyword>
    <md:keyword>difference equation</md:keyword>
    <md:keyword>direct form II</md:keyword>
    <md:keyword>DSP</md:keyword>
    <md:keyword>elinfinite impulse response</md:keyword>
    <md:keyword>ellip</md:keyword>
    <md:keyword>elliptic low-pass filter</md:keyword>
    <md:keyword>freqz</md:keyword>
    <md:keyword>gain factor</md:keyword>
    <md:keyword>IIR</md:keyword>
    <md:keyword>impulse response</md:keyword>
    <md:keyword>infinite impulse response</md:keyword>
    <md:keyword>linear time-invariant</md:keyword>
    <md:keyword>LTI</md:keyword>
    <md:keyword>notch filter</md:keyword>
    <md:keyword>poles</md:keyword>
    <md:keyword>quantize</md:keyword>
    <md:keyword>zeros</md:keyword>
  </md:keywordlist>

  <md:abstract>You will implement a fourth-order, elliptical, low-pass infinite impulse-response (IIR) filter as a cascade of two second-order sections.</md:abstract>
</metadata>





<content>
    <section id="sec4">
      <name>Implementation</name> 
      
      <para id="p16">On the DSP, you will implement the
	<term>elliptic low-pass filter</term> designed using the
	<code>ellip</code> command from <cnxn document="m13799">IIR
	Filters: Filter-Design Exercise in MATLAB</cnxn>. You should
	not try to implement the notch filter designed in <cnxn document="m10813">IIR Filtering: Filter-Coefficient
	Quantization Exercise in MATLAB</cnxn>, because it will not
	work correctly when implemented using Direct Form II.  (Why
	not?)
      </para>
      <para id="p17">
	To implement the fourth-order filter, start with a single set
	of second-order coefficients and implement a single
	second-order section.  Make sure you write and review
	pseudo-code <emphasis>before</emphasis> you begin programming.
	Once your single second-order IIR is working properly you can
	then proceed to code the entire fourth-order filter.
      </para>
      <section id="sec4a">
	<name>Large coefficients</name>
	<para id="p18">
	  You may have noticed that some of the coefficients you have
	  computed for the second-order sections are larger than 1.0
	  in magnitude.  For any stable second-order IIR section, the
	  magnitude of the "0" and "2" coefficients 
	  (<m:math>
	    <m:ci><m:msub>
		<m:mi>a</m:mi>
		<m:mn>0</m:mn>
	      </m:msub></m:ci>
	  </m:math> and 
	  <m:math>
	    <m:ci><m:msub>
		<m:mi>a</m:mi>
		<m:mn>2</m:mn>
	      </m:msub></m:ci>
	  </m:math>, for example) will always be less than or equal to
	  1.0.  However, the magnitude of the "1" coefficient can be
	  as large as 2.0.  To overcome this problem, you will have to
	  divide the
	  <m:math>
	    <m:ci><m:msub>
		<m:mi>a</m:mi>
		<m:mn>1</m:mn>
	      </m:msub></m:ci>
	  </m:math> and 
	  <m:math>
	    <m:ci><m:msub>
		<m:mi>b</m:mi>
		<m:mn>1</m:mn>
	      </m:msub></m:ci>
	  </m:math> coefficients by two prior to saving them for your
	  DSP code.  Then, in your implementation, you will have to
	  compensate somehow for using half the coefficient value.
	</para>
      </section>
      <section id="sec4b">
	<name>Repeating code</name>
	<para id="p20">Rather than write separate code for each second-order
	  section, you are encouraged first to write one section, then
	  write code that cycles through the second-order section code
	  twice using the repeat structure below.  Because the IIR
	  code will have to run inside the block I/O loop and this
	  loop uses the <term>block repeat counter</term>
	  (<code>BRC0</code>), you must use another looping structure
	  to avoid corrupting the <code>BRC0</code>.  <note type="Note">You will have to make sure that your code uses
	  different coefficients and states during the second cycle of
	  the repeat loop.</note>
	</para>
	<code type="block"><![CDATA[ 
          mov   #num_stages-1, AR1

          start_stage

          ; IIR code goes here

          BCC	start_stage, *AR1- != #0]]>
	</code>
      </section>
      <section id="sec4c">
	<name>Gain</name>
	<para id="p21">It may be necessary to add gain to the output of the system.
	  To do this, simply shift the output left (which can be done
	  using the <code>sfts</code> opcode) before saving the output to
	  memory.
	</para>
      </section>
    </section>

    <section id="sec5">
      <name>Grading</name>

      <para id="p22">
        Your grade on this lab will be split into three parts:
      </para>

      <list id="point_list" type="bulleted">
        <item>1 point: Prelab</item> 
	<item>4 points: Code.  Your DSP code implementing the
        fourth-order IIR filter is worth 3 points and the MATLAB
        exercise is worth 1 point.</item> 
	<item>5 points: Oral quiz.  The quiz may cover differences
        between FIR and IIR filters, the prelab material, and the
        MATLAB exercise.</item>
      </list>
    </section>
  </content>
</document>
