<?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="Module.2004-01-09.2347">
  <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Adaptive FIR Filtering</name>
  <metadata xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
  <md:version xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">1.3</md:version>
  <md:created xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">2004/01/09 13:23:47 US/Central</md:created>
  <md:revised xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">2007/04/18 21:30:16.215 GMT-5</md:revised>
  <md:authorlist xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
      <md:author xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="potter">
      <md:firstname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Lee</md:firstname>
      <md:othername xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">C</md:othername>
      <md:surname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Potter</md:surname>
      <md:email xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">potter@ece.osu.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
    <md:maintainer xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="potter">
      <md:firstname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Lee</md:firstname>
      <md:othername xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">C</md:othername>
      <md:surname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Potter</md:surname>
      <md:email xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">potter@ece.osu.edu</md:email>
    </md:maintainer>
    <md:maintainer xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="charlet">
      <md:firstname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Charlet</md:firstname>
      
      <md:surname xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Reedstrom</md:surname>
      <md:email xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">charlet@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">adaptive filter</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">echo cancellation</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">LMS</md:keyword>
    <md:keyword xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">system identification</md:keyword>
  </md:keywordlist>

  <md:abstract xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">In this laboratory, students implement a real-time adaptive FIR filter, investigate the convergence of the least mean squares (LMS) algorithm, and apply the adaptive filter to the problems of system identification and echo cancellation.</md:abstract>
</metadata>

<content xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
<section 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="prelab">
<name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Pre-Lab: Adaptive Filter Implementation</name>
<para 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="para1">First, use MATLAB to simulate the system identification
block diagram in <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" target="fig1"/>.  For the simulation, let 
	<m:math>
		<m:apply>
			<m:ci type="fn" class="discrete">x</m:ci>
			<m:ci>n</m:ci>
		</m:apply>
	</m:math>
be a Gaussian random noise input, which can be generated in
MATLAB using the command <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">randn</code>.   
For the "unknown" system, use
a fourth-order, low-pass elliptical IIR filter.  Thus, the
reference signal can be generated
with the following MATLAB commands:
	<code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" type="block">
	  &gt;&gt; x = randn(1000,1);%random input signal
	  &gt;&gt; [B,A] = ellip(4,0.25,10,0.25);%IIR filter
	  &gt;&gt; d = filter(B,A,x);%reference signal
	  &gt;&gt; figure;freqz(B,A)%view frequency response
	</code>
Simulate the system with an adaptive filter of length 32 (32 taps) and a
step-size of 0.02.  Initialize all adaptive filter
coefficients to zero.  Because the
adaptive filter coefficients change with time, implement the
filter on a sample by sample basis (<foreign xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">e.g.</foreign>,
using a loop with the <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">for</code>
or <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">while</code> commands).
Plot the squared-error versus sample
number as the filter adapts over time.  Also, 
use <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">freqz</code> to plot the
frequency response of the adaptive filter coefficients, <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">W</code>,
at the end of the simulation.  Finally, use <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">figure;stem(W)</code>
and <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">figure;stem(dimpulse(B,A,32))</code> to view and
compare the adaptive FIR impulse response and the IIR impulse reponse.


      </para>

      <para 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="element-973">How well does the adaptive FIR filter at convergence
approximate the fourth-order IIR system?
How long does the adaptive FIR filter take to converge?</para><figure 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="fig1">
	<media xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" type="image/png" src="afir_fig1.idr.png"/>
	<caption xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">An adaptive filter.</caption>
      </figure>

<para 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="para2">Second, write pseduo code for an assembly program to implement
an adaptive FIR filter. Your code can be modified
from the FIR filtering laboratory exercise.
The foundation for your modification is the
LMS filter coefficient update equation
<equation 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="eqn1">
		<m:math>
			<m:apply>
				<m:eq/>
				<m:apply>
					<m:ci type="fn" class="discrete">W</m:ci>
					<m:apply>
						<m:plus/>
						<m:ci>n</m:ci>
						<m:cn>1</m:cn>
					</m:apply>
				</m:apply>
				<m:apply>
					<m:plus/>
					<m:apply>
						<m:ci type="fn" class="discrete">W</m:ci>
						<m:ci>n</m:ci>
					</m:apply>
					<m:apply>
						<m:times/>
						<m:ci>μ</m:ci>
						<m:apply>
							<m:ci type="fn" class="discrete">e</m:ci>
							<m:ci>n</m:ci>
						</m:apply>
						<m:apply>
							<m:ci type="fn" class="discrete">X</m:ci>
							<m:ci>n</m:ci>
						</m:apply>
					</m:apply>
				</m:apply>
			</m:apply>
		</m:math>
	</equation>
where 
	<m:math>
		<m:apply>
			<m:ci type="fn" class="discrete">W</m:ci>
			<m:ci>n</m:ci>
		</m:apply>
	</m:math> is the vector of 32 FIR filter coefficients at time
	<m:math><m:ci>n</m:ci></m:math>, 
	<m:math>
		<m:apply>
			<m:eq/>
			<m:apply>
				<m:ci type="fn" class="discrete">e</m:ci>
				<m:ci>n</m:ci>
			</m:apply>
			<m:apply>
				<m:minus/>
				<m:apply>
					<m:ci type="fn" class="discrete">d</m:ci>
					<m:ci>n</m:ci>
				</m:apply>
				<m:apply>
					<m:ci type="fn" class="discrete">y</m:ci>
					<m:ci>n</m:ci>
				</m:apply>
			</m:apply>
		</m:apply>
	</m:math> is the error between the reference and output,
<m:math><m:ci>μ</m:ci></m:math> is the step size, and
<m:math>
		<m:apply>
			<m:ci type="fn" class="discrete">X</m:ci>
			<m:ci>n</m:ci>
		</m:apply>
	</m:math> is the length 32 vector of current and past input samples.
(Note the upper-case X is used to denote the state vector that stores the
current and past 31 input samples.)
Observe that the update is implemented
by multiply and accumulate operations applied
to the buffer of filter coefficients.
 
Consider the following five suggestions
for implementing the processing shown
in <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" target="fig1"/>.
<list xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" type="enumerated" id="list1"><item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
	    The filter coefficients should be initialized to zero at
	    the start of program execution.
	  </item>
		<item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
	    The left input channel is the input 
	    <m:math>
				<m:apply>
					<m:ci type="fn" class="discrete">x</m:ci>
					<m:ci>n</m:ci>
				</m:apply>
			</m:math> to the adaptive filter.
	  </item>
		<item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
	    The right input channel is the reference input signal
	    <m:math>
				<m:apply>
					<m:ci type="fn" class="discrete">d</m:ci>
					<m:ci>n</m:ci>
				</m:apply>
			</m:math>.
	  </item>
		<item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
	    The left channel output is the adaptive filter output
	    <m:math>
				<m:apply>
					<m:ci type="fn" class="discrete">y</m:ci>
					<m:ci>n</m:ci>
				</m:apply>
			</m:math>.
	  </item>
		<item xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
	    The right channel output is the error signal
	    <m:math>
				<m:apply>
					<m:ci type="fn" class="discrete">e</m:ci>
					<m:ci>n</m:ci>
				</m:apply>
			</m:math>.
	  </item>
	</list>
The following opcodes may be useful:  <code xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">SUB, MPY, MAC, BCC</code>.</para>
</section>

<!--
\begin{figure}[t]
\centerline{\epsfig{file=figures/afir_fig1.idr,width=12.0cm}}
\caption{\label{afir}An adaptive filter.}
\end{figure}
-->

<section 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="section2">
<name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Lab Exercise: Adaptive Filtering for System Identification</name>
<para 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="para3">
	One application of adaptive filters is adaptive modeling or
	system identification.  <cnxn xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" target="fig2"/> depicts the
	system modeling problem. The output of an unknown system to a
	known input is used as the reference input to an adaptive
	filter.  The known input signal is fed through the adaptive
	filter in an effort to duplicate the unknown system
	output. Upon convergence, the adaptive filter parameters
	represent an estimate of the unknown system.
      </para>

      <para 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="para4"><name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">System ID</name> Test your adaptive filter program by
	applying it to the identification of a known system.  Use a
	filter box as your "unknown" system.  Use a random noise
	generator as your "known" input signal. Run your adaptive
	filter program using only 10 filter taps and stop the program
	after the filter has converged.  Enter the estimated filter
	coefficients into MATLAB
and plot the magnitude response to verify
that the adaptive filter has approximated
the system.

	<figure 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="fig2">
		<media xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" type="image/png" src="afir_fig2.idr.png"/>
		<caption xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">
	    Using an adaptive filter to module an unknown system.
	  </caption>
	</figure>
	<!--
\begin{figure}[ht]
\centerline{\epsfig{file=figures/afir_fig2.idr,width=12.0cm}}
\caption{\label{afir_sid}Using an adaptive filter to model an unknown
system.}
\end{figure}
-->
</para>
    </section>

<!--
    <section id='section3'>
      <name>Speed of Convergence</name>
      <para id='para5'>
	We know that it takes some time for the LMS algorithm to
	converge, and that this convergence rate depends on the value
	of the loop gain.  Perform the following experiment to
	demonstrate this property.
      </para>
      <para id='para6'>
	Modify your program to perform adaptation and filtering for a
	fixed number of steps, after which only filtering is
	performed.  Use your modified program in the filtering setup
	of Figure~\ref{afir_sid} to estimate a bandpass system
	response using a 60 tap filter.  For a given adaptation
	interval (number of steps over which adaptation is performed),
	measure the estimation error power of the resulting filter
	using the oscilloscope.  Repeat your measurements over a range
	adaptation intervals and two values of the loop gain.  Plot
	your results.  Be sure that your filter weights are
	initialized to the same values at the beginning of each run.
	You may find it helpful to first measure estimation error
	power without any adaptation, and estimation error power after
	full convergence.  Then, as you vary the adaptation interval,
	your estimation error power should lie between these two
	values.
      </para>
      <para id='para7'>
	How many iterations does it takes for the LMS algorithm to
	converge for a 60 tap filter estimating a bandpass system?
	How much of an effect does the loop gain have on convergence?
<para id='para_report_A'>
Record the filter coefficients at converge and report the settings of the hardware filter box.  Use the filter coefficients to plot, in MATLAB, the magnitude and phase responses of the estimated filter. Compare and contrast the hardware filter and the estimated system.
      </para>
    </section>
-->



<section 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="section4">
      <name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Lab Exercise: Adaptive Interference Cancellation</name>
      <para 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="para8">
	Adaptive filters are used in modern telephony to perform echo
	suppression.  A small amount of speech from talker A,
	transmitted to talker B, is unavoidably "echoed" back to
	talker A with talker B's speech.
      </para>

      <para 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="para9">
	<name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">Echo Cancellation</name> With this application in mind, a stereo
	speech recording has been made.  On one channel, talker A is
	speaking. On the other channel, speech from talker B is
	present, along with a delayed "echo" of talker A's speech.
	Use your adaptive filter to suppress the "echo" from the
	speech of talker B.  Can you estimate the delay of the "echo"?
	Does the step size, <m:math><m:ci>μ</m:ci></m:math>, or
	number of filter taps, <m:math><m:ci>N</m:ci></m:math>, have
	any effect on your results?
      </para>

<para 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="para10">
Report the estimated filter coefficients.
Describe the echo in specific terms (seconds delay,
frequency response, <foreign xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/">etc.</foreign>).
Qualitatively report on the effects observed by changing
the step size or the number of filter taps.
</para>
</section>

</content>
  
</document>
