<?xml version="1.0" encoding="utf-8"?>
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" xmlns:q="http://cnx.rice.edu/qml/1.0" id="m0536" module-id="" cnxml-version="0.6">

  <title>FIR Filter Example</title>

  <metadata xmlns:md="http://cnx.rice.edu/mdml/0.4">
  <!-- WARNING! The 'metadata' section is read only. Do not edit below.
       Changes to the metadata section in the source will not be saved. -->
  <md:content-id>m0536</md:content-id>
  <md:title>FIR Filter Example</md:title>
  <md:version>2.7</md:version>
  <md:created>2000/08/10</md:created>
  <md:revised>2009/06/09 17:41:52.152 GMT-5</md:revised>
  <md:authorlist>
    <md:author id="dhj">
        <md:firstname>Don</md:firstname>
        <md:surname>Johnson</md:surname>
        <md:fullname>Don Johnson</md:fullname>
        <md:email>dhj@rice.edu</md:email>
    </md:author>
  </md:authorlist>
  <md:maintainerlist>
    <md:maintainer id="dhj">
        <md:firstname>Don</md:firstname>
        <md:surname>Johnson</md:surname>
        <md:fullname>Don Johnson</md:fullname>
        <md:email>dhj@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="mselik">
        <md:firstname>Melissa</md:firstname>
        <md:surname>Selik</md:surname>
        <md:fullname>Melissa Selik</md:fullname>
        <md:email>mselik@alumni.rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="jac3">
        <md:firstname>John</md:firstname>
        <md:othername>Austin</md:othername>
        <md:surname>Cottrell</md:surname>
        <md:fullname>John Cottrell</md:fullname>
        <md:email>jac3@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  <md:license href="http://creativecommons.org/licenses/by/1.0"/>
  <md:licensorlist>
    <md:licensor id="dhj">
        <md:firstname>Don</md:firstname>
        <md:surname>Johnson</md:surname>
        <md:fullname>Don Johnson</md:fullname>
        <md:email>dhj@rice.edu</md:email>
    </md:licensor>
  </md:licensorlist>
  <md:keywordlist>
    <md:keyword>analog</md:keyword>
    <md:keyword>analog signals</md:keyword>
    <md:keyword>buffering</md:keyword>
    <md:keyword>digital signal processing</md:keyword>
    <md:keyword>discrete-time</md:keyword>
    <md:keyword>discrete-time filtering</md:keyword>
    <md:keyword>DSP</md:keyword>
    <md:keyword>example</md:keyword>
    <md:keyword>examples</md:keyword>
    <md:keyword>fast Fourier transform</md:keyword>
    <md:keyword>FFT</md:keyword>
    <md:keyword>filtering</md:keyword>
    <md:keyword>finite impulse response</md:keyword>
    <md:keyword>FIR</md:keyword>
    <md:keyword>frequency domain</md:keyword>
  </md:keywordlist>
  <md:subjectlist>
    <md:subject>Science and Technology</md:subject>
  </md:subjectlist>
  <md:abstract>An example of using a Finite Impulse Response filter.
</md:abstract>
  <md:language>en</md:language>
  <!-- WARNING! The 'metadata' section is read only. Do not edit above.
       Changes to the metadata section in the source will not be saved. -->
</metadata>

<content>

    <example id="exa2000">
      <para id="para1">
	We want to lowpass filter a signal that contains a sinusoid
	and a significant amount of noise.  <link target-id="fig1003" strength="3"/> shows a portion of this signal's waveform.  If
	it weren't for the overlaid sinusoid, discerning the sine wave
	in the signal is virtually impossible.  One of the primary
	applications of linear filters is <term>noise removal</term>:
	preserve the signal by matching filter's passband with the
	signal's spectrum and greatly reduce all other frequency
	components that may be present in the noisy signal.
      </para>
      
      <figure id="fig1003">
	<media id="id14359082" alt="">
          <image src="sig25.png" mime-type="image/png"/>
          <image src="sig25.eps" mime-type="application/postscript"/>
        </media>
	<caption>
	 The noisy input signal is sectioned into length-48 frames,
	each of which is filtered using frequency-domain
	techniques.  Each filtered section is added to other outputs
	that overlap to create the signal equivalent to having
	filtered the entire input.  The sinusoidal component of the
	signal is shown as the red dashed line.
	</caption>
      </figure>    

      <para id="para2">
	A smart Rice engineer has selected a FIR filter having a
	unit-sample response corresponding a period-17 sinusoid:
	<m:math>
	  <m:apply>
	    <m:eq/>
	    <m:apply>
	      <m:ci type="fn">h</m:ci>
	      <m:ci>n</m:ci>
	    </m:apply>
	    <m:apply>
	      <m:divide/>
	      <m:apply>
		<m:minus/>
		<m:cn>1</m:cn>
		<m:apply>
		  <m:divide/>
		  <m:apply>
		    <m:cos/>
		    <m:apply>
		      <m:times/>
		      <m:cn>2</m:cn>
		      <m:pi/>
		      <m:apply>
			<m:plus/>
			<m:ci>n</m:ci>
			<m:cn>1</m:cn>
		      </m:apply>
		    </m:apply>
		  </m:apply>
		  <m:cn>17</m:cn>
		</m:apply>
	      </m:apply>
	      <m:cn>18</m:cn>
	    </m:apply>
	  </m:apply>
	</m:math>
	,
	<m:math>
	  <m:apply>
	    <m:in/>
	    <m:ci>n</m:ci>
	    <m:set>
	      <m:cn>0</m:cn>
	      <m:ci>…</m:ci>
	      <m:cn>16</m:cn>
	    </m:set>
	  </m:apply>
	</m:math>
	, which makes
	<m:math>
	  <m:apply>
	    <m:eq/>
	    <m:ci>q</m:ci>
	    <m:cn>16</m:cn>
	  </m:apply>
	</m:math>
	.  Its frequency response (determined by computing the
	discrete Fourier transform) is shown in <link target-id="fig1004" strength="3"/>.  To apply, we can select the length of each
	section so that the frequency-domain filtering approach is
	maximally efficient:  Choose the section length
	<m:math>
	  <m:ci><m:msub>
	      <m:mi>N</m:mi>
	      <m:mi>x</m:mi>
	    </m:msub></m:ci>
	</m:math>
	so that
	<m:math>
	  <m:apply>
	    <m:plus/>
	    <m:ci><m:msub>
		<m:mi>N</m:mi>
		<m:mi>x</m:mi>
	      </m:msub></m:ci>
	    <m:ci>q</m:ci>
	  </m:apply>
	</m:math>
	is a power of two.  To use a length-64 FFT, each section must
	be 48 samples long.  Filtering with the difference equation
	would require 33 computations per output while the frequency
	domain requires a little over 16; this frequency-domain
	implementation is over twice as fast!  <link target-id="fig1003" strength="3"/> shows how frequency-domain filtering works.
      </para>

      <figure id="fig1004">
	<media id="id14364954" alt="">
          <image src="sig24.png" mime-type="image/png"/>
          <image src="sig24.eps" mime-type="application/postscript"/>
        </media> 
	<caption>
	  The figure shows the unit-sample response of a length-17
	  Hanning filter on the left and the frequency response on the
	  right.  This filter functions as a lowpass filter having a
	  cutoff frequency of about 0.1.
	</caption>
      </figure>

      <para id="para3">
	We note that the noise has been dramatically reduced, with a
	sinusoid now clearly visible in the filtered output.  Some
	residual noise remains because noise components within the
	filter's passband appear in the output as well as the signal.
      </para>
    </example>

    <exercise id="exer1">
      <problem id="id14364999">
	<para id="exer1a">
	  Note that when compared to the input signal's sinusoidal
	  component, the output's sinusoidal component seems to be
	  delayed. What is the source of this delay?  Can it be
	  removed?
	</para>
      </problem>
      <solution id="id14365019">
	<para id="exer1b">
	  The delay is <emphasis>not</emphasis> computational delay
	  here—the plot shows the first output value is aligned with
	  the filter's first input—although in real systems this is
	  an important consideration.  Rather, the delay is due to the
	  filter's phase shift: A phase-shifted sinusoid is equivalent
	  to a time-delayed one:
	  <m:math>
	    <m:apply>
	      <m:eq/>
	      <m:apply>
		<m:cos/>
		<m:apply>
		  <m:minus/>
		  <m:apply>
		    <m:times/>
		    <m:cn>2</m:cn>
		    <m:pi/>
		    <m:ci>f</m:ci>
		    <m:ci>n</m:ci>
		  </m:apply>
		  <m:ci>φ</m:ci>
		</m:apply>
	      </m:apply>
	      <m:apply>
		<m:cos/>
		<m:apply>
		  <m:times/>
		  <m:cn>2</m:cn>
		  <m:pi/>
		  <m:ci>f</m:ci>
		  <m:apply>
		    <m:divide/>
		    <m:apply>
		      <m:minus/>
		      <m:ci>n</m:ci>
		      <m:ci>φ</m:ci>
		    </m:apply>
		    <m:apply>
		      <m:times/>
		      <m:cn>2</m:cn>
		      <m:pi/>
		      <m:ci>f</m:ci>
		    </m:apply>
		  </m:apply>
		</m:apply>
	      </m:apply>
	    </m:apply>
	  </m:math>
	  .  All filters have phase shifts.  This delay could be
	  removed if the filter introduced no phase shift.  Such
	  filters do not exist in analog form, but digital ones can be
	  programmed, but not in real time.  Doing so would require the
	  output to emerge before the input arrives!
	</para>
      </solution>
    </exercise>

  </content>
</document>
