PN sequences are widely used to
The first application is to use a PN sequence to estimate an impulse response of an unknown subsystem, e.g. the cascade of a source, empty chamber, and receiver in a biomedical instrument. Once the impulse response is known, calibration of the system can proceed by means of a linear time-invariant filter in the probe/transmitter (known as a predistorter) or detector/receiver (known as an equalizer) to compensate for the distortion in the subsystem.
As a training signal, the PN sequence would be the digital data to be transmitted over the unknown communication channel. The receiver knows the bits that had been transmitted, and can use that knowledge to adapt receiver settings to improve communication performance (signal quality). This is the application explored in homework #4.
Reading assignment:
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:
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 or by using the sequence you generated in lab 4. The seqgen.pn command requires the Matlab communications toolbox. 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:
pn = [ 1 0 1 0 0 1 1 ]; pnOnes = round(2*pn - 1);The freqz command
freqz(pnOnes);will plot the magnitude response in deciBels.
In answering part (c), please consider the magnitude spectrum
in linear units, which you can plot using plotspec
.
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.
For part (c), in addition to plotting the discrete-time Fourier transform of the PN sequence, here's Matlab code to plot the discrete Fourier transform of a PN sequence. The magnitude of all DFT coefficents are the same except the DC coefficient which 1/Nth of the magnitude of the other coefficients.
pn = [ 1 0 1 0 0 1 1 ]; pnOnes = round(2*pn - 1); y = fft(pnOnes); m = abs(y); Ny = length(y); %%% Different approach if length is odd or even if floor(Ny/2) == Ny/2 %% even kstart = -Ny/2; kend = (Ny/2) - 1; else %% odd kstart = -(Ny-1)/2; kend = (Ny-1)/2; end kshift = kstart : kend; stem(kshift, fftshift(m));
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:
The problem with the first approach is that by default, Matlab 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 level 1 and level 2 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 header = ones(1,31); % header is a predefined string 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 headstart=length(data)-ind+1; % place where header is detected %% End of code from Software Receiver Design book if ( loc == headstart ) totalCorrect = totalCorrect + 1; end end totalCorrect / totalRuns
In this approach, the amplitudes of the noise signal sd*randn(size(data)) will change with each run but the noise power will remain the same.
In answering this problem, please provide the Matlab code you developed.
In your analysis, compute the probability of correct detection for each marker for different values of the standard deviation sd and put the results in a table. 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.
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 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).