# EE445S Real-Time Digital Signal Processing Lab - Homework 2 Hints

Homework #2: Assignment in Word and. PDF formats.

• Please keep all of the work for each problem together. Please don't put the writeup in one place and plots in another. That makes it much more difficult for the grader to grade them.
• Problem 2.1.
• For the magnitude response, poles near the unit circle indicate the passband of the filter, and zeros near or on the unit circle indicate the stopband. Poles on the unit circle correspond to a pure oscillator. See slides 6-7 and 6-8 in the reader, as well as chapter 5 in Lathi's Linear Systems and Signals book, pages 809-812 in Roberts' Signals and Systems book and section 1.05 in Oppenheim & Willsky's Signals and Systems book.

• The Matlab command `zplane` plots the poles and zeros of a transfer function in the z-domain. The Matlab command `freqz` plots the magnitude and phase response for a given transfer function.

• The frequency response of a discrete-time linear time-invariant (LTI) system can be found a number of ways.
• If all of the poles of the LTI system are inside the unit circle, then one can compute the frequency response from the transfer function in the z-domain:
```Hfreq(w) = H(z) |
z = exp(j w)
```
• Otherwise, one could compute the discrete-time Fourier transform of the impulse response to find the frequency response (see slide 5-14).

Using the discrete-time Fourier transform may require you to search for the answer in books, e.g. Linear Systems and Signals by B. P. Lathi (chapter 9) or Signals and Systems by M. J. Roberts (section 5.6) or Signals and Systems by A. V. Oppenheim and A. S. Willsky (section 5.6). Recall that the discrete-time Fourier domain is periodic with period 2 pi.

• Please see the homework hints for problem 1.1 and the solution for problem 1.1.

• The discrete-time integrator, a.k.a. running summation, has an infinite impulse response. Because the discrete-time integrator is not BIBO stable, the discrete-time integrator is not an infinite impulse response (IIR) filter. Nonetheless, it is quite useful.

• When plotting the magnitude response of the bandpass resonator, please use a large value for r such as 0.9 or 0.95 and use a value of w0 between pi/4 and 3 pi/4.

• Problem 2.2: Please use the version of the "specgong.m" MATLAB script on page 139 of Software Receiver Design. The "specgong.m" MATLAB script will read in the "gong" wave file (which returns the sampling rate sr) and plots the frequency content of the gong sound file. The "gong.wav" file is included with the files that accompany Software Receiver Design.

This problem asks you to design a linear time-invariant filter for the gong signal. One possibility is to use a finite impulse response (FIR) filter designed using the Parks-McClellan algorithm via the `firpm` command in MATLAB. This firpm command is introduced on pages 47 and 48. (Octave users should see the footnote on page viii of JSK.) Here is an example template of code to design such a filter to be used immediately after running the MATLAB command `specgong`:

```%% Nyquist frequency, i.e. half the sampling rate sr
%% Sampling rate sr of the sound card is set when reading the
%% gong file using the wavread command.
fnyquist = sr/2;
%% Define the passband frequency in Hz
fpassband = ??;
%% Define the stopband frequency in Hz
fstopband = ??;
ctfrequencies = [0 fpassband fstopband fnyquist];
pmfrequencies = ctfrequencies / fnyquist;
%% Number of coefficients is filter order plus one
filterorder = ??;
lowpassamps = [ 1 1 0 0 ];
lowpassfilter = firpm( filterorder, pmfrequencies, lowpassamps );
```

There are many possible values for the passband frequency, stopband frequency and filter length. Please fill in your choices in the above code template.

Once the FIR filter coefficients have been computed, you could filter the gong signal by using the MATLAB command `conv` or `filter`. You could analyze the resulting signal using the `plotspec` function from the MATLAB files that accompany the Software Receiver Design book. For those using Matlab remotely, you could use the wavwrite command in Matlab to save the signal in wave format and then transfer the wave file back to your computer for playback. For secure file transfer, you could use Secure Shell (SSH), which is available as a free download on the UT Austin Bevoware Web site.

In problem 2.2(e), play back the downsampled filtered signal at the same sampling rate as the original gong file. The Matlab code to downsample a vector `vec` by 2 follows:

```vecDownsampledBy2 = vec(1:2:length(vec));
```

• Problem 2.3(a): The Parks-McClellan filter design algorithm is also known as Remez Exchange and Equiripple FIR. The Parks-McClellan algorithm is an iterative algorithm that attempts to fit a Chebyshev polynomial into the desired magnitude filter design specification to determine the FIR filter coefficients.

For least squares filter design, you might consider using the Matlab command firls to obtain the filter coefficients instead of using `fdatool`. The usage is very similar to `firpm` (remez) you used in problem 2.2. Once you've designed the filter, you can use `freqz` to plot the the magnitude response. The advantage of this method is that you can tweak the filter order and re-run simulations until the filter specification is met.

In certain versions of fdatool, the specification for the Kaiser window method uses cutoff frequencies instead of passband and stopband frequencies. The cutoff frequency is the value of the magnitude response that half of the passband magnitude response, or equivalently 6 dB less than the passband magnitude response. You can estimate the cutoff frequency as the average frequency in transition band, i.e. Fc1 = 3.5 Hz and Fc2 = 42.5 Hz in this problem.

For the Kaiser window method in fdatool, you could use the baseline filter order as a reference. Instead of playing with the filter order itself, I would recommend changing the filter parameters entered in the design tool to see if a lower filter order can be obtained. Instead of making the filter parameters more difficult to meet, one could decrease the stopband attenuation and increase the passband ripple.

You can validate a filter designed in fdatool by zooming into the magnitude response to check the magnitude response in dB at the stopband and passband frequencies, as well as at DC.

(b) In fdatool, you can plot the impulse response by choosing the appropriate option under the Analysis menu. You can also export the impulse response by using the Export option under the File menu to export the impulse response to the Matlab workspace in the variable `Num` (by default). In Matlab, you could plot the impulse response using the `stem` command.

(d) A word simply means the size of the data type needed to store a value. On the DSP board in lab, a word for a single-precision floating-point number (`float` data type in C) is 32 bits or 4 bytes.

Last updated 02/20/14. Send comments to bevans@ece.utexas.edu