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

Homework #1: Assignment in Word and PDF formats.
• For the names of Matlab functions for common signals, please see EE 313 Lecture 2 Slides:
• even symmetric rectangular pulse rect(t) for t in [-1/2, 1/2]: rectpuls(t)
• even symmetric triangular pulse tri(t) for t in [-1, 1]: tripuls(0.5*t)
• step function u(t) with u(0) = 1: stepfun(t, 0)
• sinc pulse sinc(t) = sin(pi t) / (pi t): sinc(t)
The Matlab command heaviside also implements the unit step function but takes an amplitude of 0.5 at the origin instead of 1.

You can receive help on a particular Matlab command by typing

help stepfun

You can also use the lookfor command to find a Matlab command for a given task.

• The Software Receiver Design textbook contains files that define new Matlab functions. For example, plotspec.m defines the function plotspec. The plotspec function takes the time-domain signal and the sampling time as arguments, and plots the time-domain waveform and the magnitude of its Fourier transform. The plotspec command uses the fast Fourier transform (FFT) of the sampled signal values to compute the frequency response. The FFT algorithm takes a vector of N time-domain samples and returns a vector of N frequency-domain samples.

Matlab has its own plotspec function that takes three arguments and plots a time-frequency signal representation called a spectrogram. This is a very different function from the plotspec function in the JSK textbook.

To access the functions provided by the Matlab files that accompany Software Receiver Design textbook, the directory containing the Matlab files would need to placed first on the Matlab search path. Please see the Matlab hints for more information.

• 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 1.1(a). The problem concerns a five-tap (or five-coefficient) discrete-time averaging filter.

The two-tap discrete-time averaging filter, with input x[n] and output y[n], is described by

y[n] = 1/2 x[n] + 1/2 x[n-1]

Two taps means two terms. To compute the current output y[n], we average the current input x[n] and the previous input x[n-1].
y[n] = (x[n] + x[n-1]) / 2

We can alternately use the following unnormalized version with reduced complexity:
y[n] = x[n] + x[n-1]

• Problem 1.1(c). The discrete-time analogy to integration is summation. For the discrete-time integrator, the relationship between the input x[n] and output y[n] for n ≥ 0 becomes
n
---|
\
y[n] =   |  x[m]
/
---|
m = 0

The above equation is not terribly efficient as the amount of memory to store previous input values grows without bound as n increases. A computationally efficient version of the equation is given below:
y[n] = y[n-1] + x[n]
with initial condition y[-1] = 0
The discrete-time integrator, a.k.a. running summation, is an example of an infinite impulse response filter. That is, the impulse response is infinite in non-zero extent.

• Problem 1.2: The Matlab command plotspec is defined by the Matlab file plotspec.m that comes with the JSK book. The plotspec command will accept the vector of amplitude values in the time domain and a sampling period. It will plot the signal in the continuous-time domain (top plot) and the signal's magnitude (bottom plot). The time-domain plot assumes that the time-domain signal starts at t = 0. In this problem, the signals start at t = -4. You could either correct the printout manually, or create your own plotspec function called myplotspec that takes a third argument of the starting time, or you could generate your own plots.

The rectangular pulse rect(t) has an amplitude of 1 over -1/2 ≤ t < 1/2.

• rect(t - 1/2) is a causal rectangular pulse of amplitude 1 from 0 to 1 seconds.
• rect(t/T) is a rectangular pulse of amplitude 1 from -T/2 to T/2 seconds (i.e. the rectangular pulse is of width T seconds)
• rect((t - T/2)/T) is a causal rectangular pulse of amplitude 1 from 0 to T seconds.

Problem 1.2(a) involves a rectangular pulse that has amplitude of 1 from t=-4 (inclusive) and t=4 (not inclusive), i.e. -4 ≤ t < 4. The rectangular pulse can be also be written as

rect(t/8) = u(t+4) - u(t-4)

If u(0) = 1, then rect(t/8) would take a value of 1 over the interval -4 ≤ t < 4.

Problem 1.2(c) involves the continuous-time signal

s(t) = e-a t u(t)
where a = 1. The continuous-time Fourier transform is
S(w) = 1 / (a + j w)
where w is in rad/s, according to page 953 in Roberts' Signals and Systems book. The magnitude response is
|S(w)| = 1 / | a + j w |
One can plot values of |S(w)| for w = 0 and w = a and for w going to infinity to see the trend. The value of |S(w)| at w = 0 is 1/|a|, and the value of |S(w)| at w = a is 1/(2|a|). A convenient measure of bandwidth is the 3 dB power bandwidth, which is equal to a.

Please see the hint below for problems 1.2 and 1.3.

• Problem 1.3: In the problem statement in the Software Receiver Design book, the * operation actually means multiplication and not convolution:
x(t) = x1(t) + 0.5 x2(t) + 2 x3(t)

• Problems 1.2 and 1.3: Sections 3.2 and 3.3 in Software Receiver Design will be particularly helpful in solving this problem.

Each problem asks you to give a sampling rate fs for each continuous-time signal and why you chose that sampling rate.

The Sampling Theorem states to choose fs > 2 fmax, where fmax is the maximum frequency of the continuous-time signal x(t), so that it is possible to reconstruct the continuous-time signal x(t) from its samples (see lecture slide 4-8).

In practice, sampling at a rate that is much higher than 2 fmax is common. To determine the sampling rate, you'll need to estimate fmax for each signal.

Here are three ways to estimate fmax:

• Trial-and-error approach: Use plotspec to plot the magnitude spectrum and pick larger and larger sampling rates until the shape of the spectrum and its associated fmax value do not change.
• Fourier analysis approach: Find the Fourier transform as a formula and analyze the magnitude spectrum.
• Power bandwidth method: This methods estimates the value of fmax for which 90% of the total power resides between 0 and fmax.

Here's example code using plotspec in the trial-and-error approach:

fs = 0.1;
Ts = 1/fs;
t = -20 : Ts : 20;
x = exp(-t.^2);
plotspec(x, Ts);

One could then increase the sampling rate fs by a factor of 10 each time until the shape of the magnitude spectrum stays the same (to within a scaling factor). Note that increasing the sampling rate means more samples will be taken per second, and hence the DC component may increase with increasing sampling rate.

One can automate the power bandwidth method to estimate fmax. The following Matlab commands may be useful.

• cumsum: Finds the cumulative sum of an array. This could be used for doing a "discrete" integration.
• sum: Finds the sum of all elements in an array.
• find: Returns an index from an array which matches a particular criteria.

Example:

x=[1 4 6 10];
find(x>5);

This returns the indices for values in vector x that are greater than 5, i.e. indices 3 and 4. The command
min(find(x>5))

returns the least of these indices which is 3.

Last updated 01/24/14. Send comments to bevans@ece.utexas.edu