# ECE 445S Real-Time Digital Signal Processing Lab - Homework 7 Hints

Homework #7: Assignment in Word and PDF formats.
• Please keep all of the work for each problem together. This will make it easier for the grader to grade them and hence assign appropriate partial or full credit for your solutions.

• Problems 7.1 & 7.2. Equalization.

An equalizer compensates distortion experienced by a signal. Examples of distortion:

• Audio system -- distortion introduced by a microphone or an audio speaker.
• Communication systems -- distortion experienced by the baseband discrete-time signal in the transmitter after it passes through the transmitter analog/RF front end, communication channel, and receiver analog/RF front end to become the baseband discrete-time signal in the receiver.
• Image/video processing -- blur introduced by an out-of-focus camera or artifacts introduced by compression and decompression

In the above cases, we can model the LTI distortion as an FIR filter and the additive thermal noise as a Gaussian random signal.

An LTI equalizer compensates the frequency distortion experienced by a signal. FIR equalizers are more common than IIR equalizers in audio, communication and image/video processing systems. IIR equalizers were introduced on slide 6-26 in Lecture 6 IIR Filters. When an equalizer is placed before the distortion, it is called a pre-distortion filter or pre-distorter.

Equalizing frequency distortion in an unknown system has many applications, including display/printing of images, calibrating biomedical instrumentation, compensating phase distortion in an analog-to-digital converter, and communication receivers.

In addition to the coverage of equalization this semester, please watch the video lecture from spring 2014 entitled Digital Quadrature Amplitude Modulation Receivers Part 2 on channel equalization from 34:04 to 50:03 (end).

Please be aware that the "best" FIR equalizer may be of any length. In fact, the "best" FIR equalizer length may be much longer than the length of the channel impulse response. To reduce the computational complexity of your simulations, please limit your search to FIR equalizers having 4 to 41 coefficients.

The bit error rate may appear to be zero if enough bits aren't used in the simulation. For example, if one expects a bit error rate (BER) of 10-2, i.e. one bit error occurs every 100 bits on average, then one would generally have to run 100/BER bits (i.e. 10,000 bits) to have confidence in the measurement of this bit error rate.

It is okay if you cannot drive the number of bit errors to zero.

For this problem, please adapt the Matlab code provided by the book as follows:

• In the first part of the code, generate a maximal length pseudo-noise sequence of length 1023 (i.e. 210 - 1) with entries +1 and -1. Gaussian Waves recommends a connection polynomial with connections at stages 3 and 10. Here's the Matlab code using comsrc.pn to generate a PN sequence for connections at stages 3 and 10:
```pn1023gen = commsrc.pn('GenPoly',       [10 3 0], ...
'InitialStates', [0 0 0 0 0 1 0 0 0 0], ...
'CurrentStates', [0 0 0 0 0 1 0 0 0 0], ...
'Mask',          [0 0 0 0 0 1 0 0 0 0], ...
'NumBitsOut',    1023);
pn1023seq = round(2 * generate(pn1023gen) - 1);
```
Then, concatenate 10 of these length-1023 sequences to create a training signal of length 10230 entries; alternately, one could set NumBitsOut to 10230. (In version 3.5 of the Communications Toolbox, commsrc.pn is called seqgen.pn, which takes the same arguments.) Use the same training signal in problems 7.1 and 7.2.
• If you don't have the Communication Toolbox on your machine, then could download the Matlab data file with the 1023-length PN sequence. or run the Communication Toolbox on the computers in ECJ 1.318. For the latter, generate the 1023 values for the PN sequence as +1 and -1 values, save the values to a file, move the file to your computer, and read it into Matlab.
• Next, initialize the counter for the minimum number of bit errors, errmin, to be large, e.g. twice the number of bits in the training signal.
• Next, set up a nested for loop. The outer loop will enumerate values of n from 3 to 40, where n is the equalizer length minus one. The inner loop will enumerate the possible transmission delays delta from 1 to n, inclusive.
• In the nested for loop, compute the number of errors for every combination of n and delta within the inner loop. If one finds an error smaller than the previously found error, one updates errmin, the corresponding nmin and deltamin, and associated values of Jmin and the equalizer coefficients.

When you plot the frequency response of the equalized channel, please plot the magnitude and phase responses, e.g. by using the `freqz` command.

• Problem 7.2: Please read the hints above for problems 7.1 & 7.2.

A step-by-step derivation of the adaptive LMS equalizer is available in the Ideal Channel section (page 2) and Adaptive FIR Equalizer section (page 3) in the Fall 2020 QAM lecture notes part 1.

In the course reader, please see the following midterm #2 problems and their solutions involving adaptive FIR channel equalizer design:

Please reduce the step size parameter, mu, to be on the order of 0.001 so that the iterations will converge to a reasonable error value.

Please augment the code for problem 7.2 by copying the code to calculate and track the minimum error (errmin) from the code for problem 7.1.

There are two different error calculations in this problem, and they are easy to confuse.

Please estimate the computational complexity in terms of multiplication-accumulation (MAC) operations for the two equalizer design methods. Given m training samples, n equalizer coefficients and fixed delay delta, estimate the computational complexity of the LS squares equalizer design formula

```f=inv(R'*R)*R'*S
```
for vector f, matrix R and vector S. Estimate the computational complexity of the adaptive LMS equalizer design formula
```f=f+mu*e*rr
```
for vector f, scalar mu, scalar e and vector rr. The adaptive LMS design formula is run for each training sample. The following facts may be useful:
• A scalar times a vector of N elements takes N MAC operations.
• The dot/inner product of two vectors of length N takes N multiplications and N-1 additions, or equivalently N MAC operations.
• The product of an N by M matrix and a column vector of M elements (i.e. an M x 1 matrix) requires N dot/inner products of two vectors of length M, which requires N M MAC operations.
• The product of an N by M matrix with an M by N matrix produces an N by N matrix with N2 entries. Each entry in the resulting matrix involves a dot/inner product of two vectors of length M. Therefore, the product of the two matrices requires M N2 MAC operations.
• In the case of problem 7.1, the matrix inverse is rarely used to solve a linear system of equations. That is, with vector x known, we can rewrite
```y = A-1 x
```
as solving the following linear system of equations for y:
```A y = x
```
An N by N system of linear equations can be solved with (2/3) N3 multiplication-addition (MAC) operations, as described by the article "Gaussian elimination". We had also talked about solving linear systems of equations in Lecture 7 Interpolation and Pulse Shaping on Slide 7-9 Curve Fitting for interpolation using a cubic polynomial.

The MATLAB code in LMSequalizer.m would change from

```f=inv(R'*R)*R'*S
```
to
```f=(R'*R) \ (R'*S)
```

Also, please estimate the total memory usage for the calculations in terms of words.

In the course reader, please see the solution for problem 2.4(a) on Midterm #2 in fall 2011 on PDF page 411 for a qualitative comparison between the least squares method and adaptive least mean squares method for equalizer design.

Last updated 08/29/24. Send comments to bevans@ece.utexas.edu