## 5.5 Exercises

The exercises in this section were developed by Alan Kamas, Edward Lee, and Kennard White for use in the undergraduate and graduate digital signal processing classes at U. C. Berkeley. If you are assigned these exercises for a class, you should turn in printouts of well-labeled schematics, showing all non-default parameter values, and printouts of relevant plots. Combining multiple plots into one can make comparisons more meaningful, and can save paper. Use the `XMgraph` star with multiple inputs.

### 5.5.1 Modulation

This problem explores amplitude modulation (AM) of discrete-time signals. It makes extensive use of FFTs. These will be used to approximate the discrete-time Fourier transform (DTFT). In subsequent exercises, we will study artifacts that can arise from this approximation. For our purposes here, the output of the `FFTCx` block will be interpreted as samples of the DTFT in the interval from 0 (d.c.) to
.
sampling period). Thus the 0 to
range of frequencies (in radians per sample) translates to a range of 0 to 128kHz. On your output graphs, you should clearly label the units of the x-axis. The xUnits parameter of the `XMGraph` star can be used to do this. If the FFT produces
samples, representing the range from 0 to
kHz., then xUnits should be
Hz. Thus each sample out from the FFT will represent 500Hz. Keep in mind that a DTFT is actually periodic, and that only one cycle will be shown.

With default parameters, the `FFTCx` star will read 256 input samples and produce 256 complex output samples. This gives adequate resolution, so just use the defaults for this exercise. The section "Iterations in SDF" on page 5-3 will tell you, for instance, that you should run your systems for one iteration only. The section "Particle types" on page 2-20 explains how to properly manage complex signals. For this exercise, you should only plot the magnitude of the `FFTCx` output, ignoring the phase.

using AM modulation. The transmitted signal is
. The receiver demodulates y(n) to get the recovered signal
. The system is working if
. Commercial AM radio uses carrier frequencies from 500kHz to 2MHz; however, we will use carriers around 32kHz. This makes the results of the modulation easier to see. The system you will develop (after several intermediate phases) is shown below
:

and
. Plot the magnitude of the DTFT. It would be a good idea at this point to make a galaxy that will output the magnitude of the DTFT of the input signal. Be sure the axis of your graph is labeled with the frequencies in Hz, assuming a sampling frequency of 128kHz.
with narrower bandwidth so that the effects of modulating it can be seen more clearly and so there are fewer artifacts. A distinctive and convenient lowpass signal can be generated by feeding an impulse into the `RaisedCosine` star (found in the "communications" palette). Set the parameters of the `RaisedCosine` star as follows:
length: 256
symbol_interval: 8
excessBW: 0.5
Leave the interpolation parameter on its default value. The detailed functionality of this star is not important: we are just using it to get a signal we can work with conveniently. Plot the time domain signal and its magnitude DTFT. What is the bandwidth (single-sided), in Hz, of the signal? Use the -6dB point (amplitude at 1/2 of the peak) as the band edge. The signal was chosen to have roughly the bandwidth of a typical AM broadcast signal.
generated in part (2) with a sine wave. Construct a 32 kHz sine wave using the `singen` galaxy and let it be the carrier
; then produce
. Graph the DTFT of
. What is the bandwidth of
? Change the carrier to 5 kHz, and graph the FFT of y(n). Explain in words what has happened. Keep the carrier at 5 kHz, and determine what the largest possible bandwidth is for
so that
will not have any significant distortion.
, and plot the magnitude DTFT of the result. Explain in words what about this spectrum is directly attributable to the discrete-time nature of the problem. In other words, what would be different if this problem were solved in continuous time?

### 5.5.2 Sampling and multirate

This exercise explores sampling and multirate systems. As with the previous exercise, this one makes extensive use of FFTs to approximate the DTFT in the interval from 0 (d.c.) to
(normalized) or the sampling frequency
(unnormalized).

Assume as in the exercise
"Modulation" on page 5-70 a sampling frequency of 128kHz. Use the `FFTCx` to compute and plot the magnitude DTFT, properly labeled in absolute frequency. In other words, instead of the normalized sampling frequency
, use the actual sampling frequency, 128kHz. Carefully and completely explain in words what would be different about this plot if the signal were a continuous-time signal and the plot of the spectrum were its Fourier transform instead of a DTFT.
it consumes, the `FFTCx` star that gets its data should have its size parameter proportional to 1/
for each path.

### 5.5.3 Exponential sequences, transfer functions, and convolution

This exercise explores rational Z transform transfer functions.
, with
, and convolve it with a square pulse of width 10. For this problem, use the following brute-force method for generating the exponential sequence. Observe that

.
, feed that constant into the `Log` star, multiply it by the sequence
generated using the `Ramp` star, and feed the result into the `Exp` star. For your display, try the following options to the `XMgraph` star: "-P -nl -bar".

, including negative numbers and values that make the filter unstable.
and
, where
and
. Generate these two sequences using the method above, and convolve them using the convolver block. Now find
without using a convolver block. Print your block diagram, and don't forget to mark the parameter values on it.

,
. Find the poles and zeros of the transfer function and use them to explain the impulse response you observe.

,
is the unit step function. Estimate the peak value of each signal. Note that you can zoom in xgraph by drawing a box around the region of interest.

so that
. Write it down. Use Ptolemy to generate a plot of
. Plot
when
is a rectangular pulse of width 5. Assume
for
.

.
), they don't effect the magnitude frequency response. Hence the name. Although this can be implemented in Ptolemy using the `IIR` star, you are to implement it using only one or more `FIR` star(s) in the standard feedback configuration:
an
to get an overall transfer function of
. Then implement it as a feedback system in Ptolemy and plot the impulse response. Is the impulse response infinite in extent?
) in the loop. Ptolemy needs for this delay to be explicit, not hidden in the tap values of a filter star. For this reason, you should factor a
term out of
and implement it using the delay icon (a small green diamond). Note that the delay is not a star, and is not connected as a star. It just gets placed on top of an arc, as explained in
"Using delays" on page 2-47. Also note that Ptolemy requires you to use an explicit `Fork` (in the control palette) if you are going to put a delay on a net with more than one destination.

### 5.5.4 Linear phase filtering

You can compute the frequency response of a filter in Ptolemy by feeding it an impulse, and connecting the output to an `FFTCx` star. Recall that you will only need to run your system for `one` iteration when you are using an FFT, or you will get several successive FFT computations. The output of the FFT is complex, but may be converted to magnitude and phase using a complex to real (`CxToRect`) followed by a rectangular to polar (`RectToPolar`) converter stars. You can also examine the magnitude in dB by feeding it through the `DB` star before plotting it.
? Experiment with several sets of tap values, maintaining linear phase. Try long filters and short filters. Experiment with the phase unwrapper star (`Unwrap`), which attempts to remove the
ambiguity, keeping continuous phase. Choose your favorite linear-phase filter, and turn in the plots of its frequency response, together a plot of its tap values.
and a filter
, compute the output
as follows:

.
be such that

.
in terms of
. If
is causal, will
also be causal? Find the frequency response
, and express it in terms of
and
. It will help if you assume all signals are real.
used above. However, you can collect a block of samples and reverse them, getting
, using the `Reverse` star. This introduces an extra delay of
samples. Use a first-order IIR filter (with an exponentially decaying impulse response) to implement
. First verify that the above methodology yields an impulse response that is symmetric in time. Then measure the phase response. You can use Ptolemy to adjust the computed phase output to remove the effect of the large delay offset (the center of your symmetric pulse is nowhere near zero). Compare your result against the theoretical prediction in (4).

### 5.5.5 Coefficient quantization

1. `You will experiment with the following transfer function:`

,

.
. Consequently, they are not very well suited to implementing very narrowband lowpass filters.

.

.

### 5.5.6 FIR filter design

This lab explores FIR filter design by windowing and by the Parks-McClellan algorithm.
) of the peak of the first side-lobe. Is the dB drop a function of the length of the window? What about the position?
radians (the Nyquist frequency) for each of the three window lengths. What relationship would you infer between window length and this drop?
has impulse response

.
using the `RaisedCosine `star from the communications subpalette, or the `Sinc` star from the nonlinear subpalette. This star is actually an FIR filter, so feed it a unit impulse. Its output will be shaped like
if you set the "excess bandwidth" to zero. Set its parameters as follows:
length: 64 (the length of the filter you want)
symbol_interval: 8 (the number of samples to the first zero crossing)
excessBW: 0.0 (this makes the output ideally lowpass).
interpolation: 1
given that
is the first zero crossing in the impulse response? Give your answer in Hz, assuming that the sampling interval
.
compared to d.c.?

4. In this problem, you will use the rather primitive FIR filter design software provided with Ptolemy. The program you will use is called "`optfir`"; it uses the Parks-McClellan algorithm to design equiripple FIR filters. See "optfir - equiripple FIR filter design" on page C-1 for an explanation of how to use it. The main objective in this problem will be to compare equiripple designs to the windowed designs of the previous problem.

### 5.5.7 The DFT (discrete Fourier transform)

This exercise explores the DFT, FFT, and circular convolution. Ptolemy has both a `FFTCx` (complex FFT) and a `DTFT` star in the "dsp" palette. The `FFTCx` star has an order parameter and a size parameter. It consumes size input samples and computes the DFT of a periodic signal formed by repeating these samples with period
. Only integer powers of two are supported. If
, then the unspecified samples are given value zero. This can also be viewed as computing samples of the DTFT of a finite input signal of length size, padded with
zeros. These samples are evenly spaced from d.c. to
, with spacing
, where
.

be as given in problem 2. Use the `FFTCx` star to compute the 8 point circular convolution of these two signals. Which points are affected by the overlap caused by circular convolution? Compute the 16 point circular convolution and compare.

### 5.5.8 Whitening filters

This exercise, and all the remaining ones in this chapter, involve random signals.
, where
, one pole at
, and one pole at
. You may use the `Biquad` or `IIR` star in the "dsp" palette. Filter white noise with it to generate an ARMA process. Then design a whitening filter that converts the ARMA process back into white noise. Demonstrate that your system does what is desired by whatever means seems most appropriate.
and
, where

.

### 5.5.9 Wiener filtering

1. Generate an AR (auto-regressive) process
by filtering white Gaussian noise with the following filter:

.

numerator: A list of floats separated by spaces:
...
denominator: A list of floats separated by spaces:
...

.

,
is a white Gaussian noise process with variance 0.5, uncorrelated with
, and
is the impulse response of a filter with the following transfer function:

.
.
from
. Verify that the power of the error signal
is equal to the power of the additive white noise
.

1. Generate random sequence of
using the `IIDUniform` and `Sgn` stars. This represents a random sequence of bits to be transmitted over a channel. Filter this sequence with the following filter (the same filter used in
"Wiener filtering" on page 5-81):

.

.
rule, which means that full scale is equal to four standard deviations.

.

For the same speech file you used in the last assignment, `\$PTOLEMY/src/domains/sdf/demo/speech.lin`, you are to construct an adaptive differential pulse code modulation (ADPCM) coder using the "feedback around quantizer" structure and an LMS filter to form the approximate linear prediction. Be sure to connect your LMS filter so that at the receiver, if there are no transmission errors, an LMS filter can also be used in a feedback path, and the LMS filter will exactly track the one in the transmitter. You will use various amounts of quantization.
bits per sample. You will now measure the signal quality you can achieve with ADPCM compared to simple PCM (pulse code modulation) over the same channel. In PCM, you directly quantize the speech signal to
levels, whereas in ADPCM, you quantize the prediction error to
levels. For a given
, you should choose the quantization levels carefully. In particular, the quantization levels for the ADPCM case should not be the same as those for the PCM case. Given a particular prediction gain
, what should the relationship be? You should use the `Quant` star to accomplish the quantization in both cases. A useful way to set the parameters of the `Quant` star is as follows (shown for
bits, meaning 4 quantization levels):
, you should compare (a) the ADPCM encoded speech signal and (b) the PCM encoded speech signal to the original speech signal. You should make this comparison by measuring the power in the differences between the reconstructed signals and the original. How does this difference compare to the prediction gain?
bits.
bits.

### 5.5.12 Spectral estimation

In the Ptolemy "dsp" palette there are three galaxies that perform three different spectral estimation techniques. These are the (1) periodogram, (2) autocorrelation method using the Levinson-Durbin algorithm, and (3) Burg's method. The latter two compute linear predictor coefficients, and then use these to determine the frequency response of a whitening filter for the random process. The magnitude squared of this frequency response is inverted to get an estimate of the power spectrum of the random process. Study these and make sure you understand how they work. You are going to use all three to construct power spectral estimates of various signals and compare them. In particular, note how many input samples are consumed and produced. If you display all three spectral estimates on the same plot, then you must generate the same number of samples for each estimate. You will begin using only the Burg galaxy.

.
with white noise, excite it with an impulse stream with period 20 samples. Repeat the spectral estimate experiments. Which estimate is best? Does increasing the number of input samples observed help any of the estimates? With the number of input samples observed fixed at 256, try increasing the order of the autocorrelation and Burg's estimates. What is the best order for this particular signal? Note that deciding on an order for such estimates is a difficult problem.
in various ratios and repeat the experiment. Does the noise improve the autocorrelation and Burg estimates, compared to estimates based on pure impulsive excitation? You should be able to get excellent estimates using both the autocorrelation and Burg's methods. You may wish to run some of these experiments with 1024 input samples.

### 5.5.13 Lattice filters

In the Ptolemy "dsp" palette there are four lattice filter stars called: `Lattice`, `RLattice`, `BlockLattice`, and `BlockRLattice`. The "R" refers to "Recursive", so the "`RLattice`" stars are inverse filters (IIR), while the "`Lattice`" stars are prediction-error filters (FIR). The "Block" modifier allows you to connect the `LevDur` or `Burg` stars to the Lattice filters to provide the coefficients. A block of samples is processed with a given set of coefficients, and then new coefficients can be loaded.

, ...,
. Experiment with various methods to estimate the autocorrelation. Turn in your estimates of
, ...,
.
, ...,
has the same transfer function as the lattice filter.