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

Homework #4: 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 4.1. Part (b) builds on part (a).

In part (b), the `rand` function in Matlab generates random numbers that are uniformly distributed on the interval [0,1]. For part II, you are asked to convert a random variable x that is uniformly distributed on the interval [0,1] to a random variable y that is uniformly distributed on the interval [-1,1]. Let's try an affine mapping (i.e. a linear mapping plus an offset) as used in part I:

y = a x + b

Here, a and b are constants. Due to this affine mapping, y has value b when x = 0, and y has value a + b when x = 1. Hence, y is on the interval [b, a+b]. From here, we can solve for a and b.

In part (c), you can generate the 31-length bit sequence by using one of the tables in Appendix L in the course reader or by using the seqgen.pn command in Matlab. The seqgen.pn command requires the Matlab communications toolbox. Or you could use another 31-length PN sequence. Please make sure that the PN sequence has maximal length (i.e. its smallest period is 31 samples).

In part (c), you are asked to map a bit sequence of 0s and 1s so that 0 maps to -1 and 1 maps to 1. For efficiency in Matlab, it is important to avoid programming using for loops and instead use vector arithmetic. In this case, one way to perform the mapping follows:

```b = (randn(1,100) >= 0);   %%% generate 100 random bits of 1s and 0s
a = round(2 * b - 1);      %%% Map 0 to -1 and 1 to 1
```
The freqz command
```freqz(a);
```
will plot the magnitude response in deciBels.

In answering part (c), please consider the magnitude spectrum in linear units. For a particular PN sequence, I found that the magnitude response varied from 0 dB and 18.6 dB, or equivalently from 1 to 8.6 in linear units.

• Problem 4.2. This problem examines the robustness of detecting a marker embedded in a long sequence of numbers.

Using correlation against a known marker sequence to find the start of frame is generally not perfect; i.e., there is a probability of error. When gathering statistics, it is important to gather enough sample points to have reliability in the results. For each part of this problem, run the simulation 10000 times, which will give accuracy of 10-2 in the calculation of the correct detection rate.

Here are two ways that the simulation could be run 10000 times:

1. Generate one massively long vector that is formed by concatenating 10000 data vectors, correlate, and find all of the peaks.
2. We could put a for loop around the code for one data vector and keep a running sum of the number of correct marker detections.

The problem with the first approach is that by default, Matlab/Mathscript stores each real number in double-precision floating-point format (i.e. in 8 bytes on a 32-bit machine). The first issue comes when constructing the massively long vector by concatenating 10000 data vectors. The 10000 calls to dynamic memory allocation will lead to fragmented memory and also be really slow. A workaround is to allocate the massively long vector first and fill in its values as they are calculated. The second issue is that long vectors will cause long simulations due to management of long vectors by the desktop computer memory system (between L1 and L2 caches as well as RAM).

Hence, the second approach is much more efficient in using computer resources. For the second approach, the resulting Matlab code for part (a) follows:

```totalCorrect = 0;
totalRuns = 10000;
for run = 1:totalRuns
%% Begin code from Software Receiver Design book
loc=30; r=25;          % place header in position loc
data=[ sign(randn(1,loc-1)) header sign(randn(1,r)) ]; % generate signal
sd=0.25; data=data+sd*randn(size(data)) ; % add noise
y=xcorr(header, data) ; % do cross correlation
[m, ind]=max(y);        % location of largest correlation
%% End of code from Software Receiver Design book
if ( loc == headstart )
totalCorrect = totalCorrect + 1;
end
end
totalCorrect / totalRuns
```

In your analysis, compute the probability of correct detection for each marker. For the marker of all 1s, consider what happens if the bit before the marker is one and consider what happens if the bit after the marker is one. For the PN sequence marker, consider the probability that a random sequence of bits prior to the marker could lead to false detection.

• Problem 4.3. This problem examines the robustness of detecting a known marker sequence after it passes through a communication channel. The communication channel is modeled as a finite impulse response (FIR) filter followed by spectrally-flat additive noise.

Before working this problem, it is recommended that you should complete problem 8.17 first.

In generating random 4-PAM symbol amplitudes from the set {-3, -1, 1, 3}, the Matlab/Mathscript command `rand` might be helpful. The `rand` command generates random numbers that follow a uniform distribution on the interval (0,1).

Entries in the marker should be taken from the set {-3, +3}. That is, amplitude should be either +3 or -3. Please use a pseudo-noise marker sequence.

For the "long sequence of random 4-PAM data", use a sequence that is at least ten times the marker length (i.e. set `loc` to be 310).

Run your simulation 10,000 times to gather accurate statistics about the correctness in detecting the marker. See the example code in the hint above for problem 4.2.

If you don't see any bit errors, then increase the standard deviation (`sd`) of the additive noise to 0.5.

In evaluating the difference in marker detection in the receiver, please examine the frequency content of the marker sequence (in magnitude) and the frequency response of each channel (in magnitude).

Last updated 04/03/14. Send comments to bevans@ece.utexas.edu