<?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="m10625">
  <name>Spectrum Analyzer: MATLAB Exercise</name>
  <metadata>
  <md:version>1.1</md:version>
  <md:created>2004/08/24 14:51:47 GMT-5</md:created>
  <md:revised>2004/09/20 21:31:43.553 GMT-5</md:revised>
  <md:authorlist>
      <md:author id="appadwed">
      <md:firstname>Swaroop</md:firstname>
      
      <md:surname>Appadwedula</md:surname>
      <md:email>appadwed@uiuc.edu</md:email>
    </md:author>
      <md:author id="mjberry">
      <md:firstname>Matthew</md:firstname>
      <md:othername>J.</md:othername>
      <md:surname>Berry</md:surname>
      <md:email>mjberry@uiuc.edu</md:email>
    </md:author>
      <md:author id="markhaun">
      <md:firstname>Mark</md:firstname>
      <md:othername>A.</md:othername>
      <md:surname>Haun</md:surname>
      <md:email>markhaun@uiuc.edu</md:email>
    </md:author>
      <md:author id="jake">
      <md:firstname>Jake</md:firstname>
      
      <md:surname>Janevitz</md:surname>
      <md:email>jake@janevitz.com</md:email>
    </md:author>
      <md:author id="kramer">
      <md:firstname>Michael</md:firstname>
      <md:othername>L.</md:othername>
      <md:surname>Kramer</md:surname>
      <md:email>kramer@ifp.uiuc.edu</md:email>
    </md:author>
      <md:author id="moussa">
      <md:firstname>Dima</md:firstname>
      
      <md:surname>Moussa</md:surname>
      <md:email>dmoussa@uiuc.edu</md:email>
    </md:author>
      <md:author id="dsachs">
      <md:firstname>Daniel</md:firstname>
      <md:othername>Grobe</md:othername>
      <md:surname>Sachs</md:surname>
      <md:email>sachs@uiuc.edu</md:email>
    </md:author>
      <md:author id="bwade">
      <md:firstname>Brian</md:firstname>
      
      <md:surname>Wade</md:surname>
      <md:email>bwade@uiuc.edu</md:email>
    </md:author>
      <md:author id="kleffner">
      <md:firstname>Matt</md:firstname>
      
      <md:surname>Kleffner</md:surname>
      <md:email>kleffner@uiuc.edu</md:email>
    </md:author>
      <md:author id="dljones">
      <md:firstname>Douglas</md:firstname>
      <md:othername>L.</md:othername>
      <md:surname>Jones</md:surname>
      <md:email>dl-jones@uiuc.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="kleffner">
      <md:firstname>Matt</md:firstname>
      
      <md:surname>Kleffner</md:surname>
      <md:email>kleffner@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="dljones">
      <md:firstname>Douglas</md:firstname>
      <md:othername>L.</md:othername>
      <md:surname>Jones</md:surname>
      <md:email>dl-jones@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="laska">
      <md:firstname>Jason</md:firstname>
      <md:othername>Noah</md:othername>
      <md:surname>Laska</md:surname>
      <md:email>laska@uiuc.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>Fourier transform</md:keyword>
    <md:keyword>Fast Fourier transform</md:keyword>
    <md:keyword>FFT</md:keyword>
    <md:keyword>Discrete Fourier Transform</md:keyword>
    <md:keyword>DFT</md:keyword>
    <md:keyword>Discrete Time Fourier Transform</md:keyword>
    <md:keyword>DTFT</md:keyword>
    <md:keyword>boxcar</md:keyword>
    <md:keyword>hamming</md:keyword>
    <md:keyword>mainlobe</md:keyword>
    <md:keyword>sidelobe</md:keyword>
    <md:keyword>twiddle-factor</md:keyword>
    <md:keyword>bit-reversed</md:keyword>
    <md:keyword>windowing</md:keyword>
    <md:keyword>zero-pad</md:keyword>
    <md:keyword>DSP</md:keyword>
    <md:keyword>autocorrelation</md:keyword>
    <md:keyword>Power Spectra</md:keyword>
    <md:keyword>Power Spectral Density Estimate</md:keyword>
    <md:keyword>PSD</md:keyword>
  </md:keywordlist>

  <md:abstract>You will investigate the effects of windowing and zero-padding on the Discrete Fourier Transform of a signal, as well as the effects of data-set quantities and weighting windows used in Power Spectral Density estimation.</md:abstract>
</metadata>





  <content>
    <section id="sec1">
      <name>MATLAB Exercise, Part 1</name>
      <para id="s1p1">
	Since the DFT is a sampled version of the spectrum of a
	digital signal, it has certain sampling effects.  To explore
	these sampling effects more thoroughly, we consider the effect
	of multiplying the time signal by different window functions
	and the effect of using zero-padding to increase the length
	(and thus the number of sample points) of the DFT.  Using the
	following MATLAB script as an example, plot the
	squared-magnitude response of the following test cases over
	the digital frequencies
	<m:math>
	  <m:apply>
	    <m:eq/>
	    <m:ci>
	      <m:msub>
		<m:mi>ω</m:mi>
		<m:mi>c</m:mi>
	      </m:msub>
	    </m:ci>
	    <m:interval>
	      <m:apply>
		<m:divide/>
		<m:pi/>
		<m:cn>8</m:cn>
	      </m:apply>
	      <m:apply>
		<m:divide/>
		<m:apply>
		  <m:times/>
		  <m:cn>3</m:cn>
		  <m:pi/>
		</m:apply>
		<m:cn>8</m:cn>
	      </m:apply>
	    </m:interval>
	  </m:apply>
	</m:math>.  
      </para>
      <list id="list1" type="enumerated">
	<item>rectangular window with no zero-padding</item>
	<item>hamming window with no zero-padding</item>
	<item>rectangular window with zero-padding by factor of four
	(<foreign>i.e.</foreign>, 1024-point FFT)</item>
	<item>hamming window window with zero-padding by factor of
	  four</item>
      </list>
      <para id="s1p2">
	Window sequences can be generated in MATLAB by using the
	<code>boxcar</code> and <code>hamming</code> functions.
      </para>
      <code type="block">
	<![CDATA[
	1  N = 256;                % length of test signals
	2  num_freqs = 100;        % number of frequencies to test
	3
	4  % Generate vector of frequencies to test
	5
	6  omega = pi/8 + [0:num_freqs-1]'/num_freqs*pi/4;
	7
	8  S = zeros(N,num_freqs);                 % matrix to hold FFT results
	9
	10
	11  for i=1:length(omega)                   % loop through freq. vector
	12     s = sin(omega(i)*[0:N-1]');          % generate test sine wave
	13     win = boxcar(N);                     % use rectangular window
	14     s = s.*win;                          % multiply input by window
	15     S(:,i) = (abs(fft(s))).^2;           % generate magnitude of FFT
	16                                          % and store as a column of S
	17  end
	18
	19  clf;
	20  plot(S);                                % plot all spectra on same graph
	21
	]]>
      </code>
      <para id="s1p3">
	Make sure you understand what every line in the script does.
	What signals are plotted?
      </para>
      <para id="s1p4">
	You should be able to describe the tradeoff between mainlobe
	width and sidelobe behavior for the various window functions.
	Does zero-padding increase frequency resolution?  Are we
	getting something for free?  What is the relationship between
	the DFT,
	<m:math>
	  <m:apply>
	    <m:ci type="fn" class="discrete">X</m:ci>
	    <m:ci>k</m:ci>
	  </m:apply>
	</m:math>, and the DTFT,
	<m:math>
	  <m:apply>
	    <m:ci type="fn">X</m:ci>
	      <m:ci>ω</m:ci>
	  </m:apply>
	</m:math>, of a sequence
	<m:math>
	  <m:apply>
	    <m:ci type="fn" class="discrete">x</m:ci>
	    <m:ci>n</m:ci>
	  </m:apply>
	</m:math>?
      </para>
    </section>

    <section id="sec2">
      <name>MATLAB Exercise, Part 2</name>
      <para id="s2p1">
        Download and run the MATLAB file
        <cite src="lab4b.m"><code>lab4b.m</code></cite> to observe direct and
        autocorrelation-based PSD estimates. A pseudo noise generator is
        filtered with a fourth-order IIR filter and various PSD estimates are
        computed and plotted. 
      </para>
      <figure id="plot1">
        <media type="image/png" src="plot1.png"/>
        <caption>
          First plot
        </caption>
      </figure>
      <para id="s2p2">
        The first plot contains PSD estimates, using a 1024-point FFT,
        from the first 512 samples of the 1024-sample sequence. The direct
        method is to take the squared-magnitude of the FFT of the sequence. The
        autocorrelation (AC) method is to take the magnitude of the FFT of the
        autocorrelation of the sequence. In this case rectangular windows were
        used in both FFTs. 
        Why do the estimates look exactly the same? Will the
        estimates be alike if all 1024 samples are used with a 1024-sample
        FFT, with all other conditions being equal? Why or why not?
      </para>
      <figure id="plot2">
        <media type="image/png" src="plot2.png"/>
        <caption>
          Second plot
        </caption>
      </figure>
      <para id="s2p3">
        The second plot contains PSD estimates, using a 1024-point FFT,
        from the first 32 samples of the 1024-sample sequence. The direct
        and AC estimates are computed in the same manner described above,
        except a hamming window has been applied to the sequence in the
        direct-PSD estimate. Why are these estimates different? What will
        make these estimates identical?
      </para>
      <figure id="plot3">
        <media type="image/png" src="plot3.png"/>
        <caption>
          Third plot
        </caption>
      </figure>
      <para id="s2p4">
        The third plot contains PSD estimates, using a 1024-point FFT,
        from all 32-sample blocks of the 1024-sample sequence. The direct-PSD
        estimate is computed by summing the hamming-windowed PSD estimates of
        each 32-sample block. The AC-PSD estimate is computed by taking the
        magnitude of the FFT of 63 samples of the autocorrelation of the
        entire 1024-point sequence. Why are 63 samples used in comparing the
        AC method to the direct method?
      </para>
      <figure id="plot4">
        <media type="image/png" src="plot4.png"/>
        <caption>
          Fourth plot
        </caption>
      </figure>
      <para id="s2p5">
        The fourth plot contains the unfiltered spectrum of the PN sequence
        and the impulse response of the coloring filter. 
      </para>
      <para id="s2p6">
        Try various the block lengths (<m:math><m:ci>Np</m:ci></m:math>) and
        direct-PSD window types. Observe the changes. Are there any
        tradeoffs? Does either the direct method or the autocorrelation method
        have an advantage over the other? Is there a direct-method window that
        results in identical block-based estimates?
        For simplicity, the autocorrelation window in this lab is
        rectangular. Can we, however, consider this an unbiased autocorrelation
        estimate that is windowed by a rectangular window? (Hint: see the
        MATLAB documentation for the <code>xcorr</code> function.) If not,
        how would you create an unbiased autocorrelation estimate before
        windowing, and what is the effective window that we have applied to
        the unbiased autocorrelation?
      </para>
    </section>
  </content>
</document>
