0% found this document useful (0 votes)
133 views

Lab 05

This document discusses spread spectrum communication techniques including direct sequence spread spectrum and code division multiplexing. It describes how spreading codes are used in DSSS systems and the importance of code synchronization. It also discusses simulating DSSS and CDM systems as well as implementing a spread spectrum receiver using SDR hardware.

Uploaded by

Nga V. Dao
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views

Lab 05

This document discusses spread spectrum communication techniques including direct sequence spread spectrum and code division multiplexing. It describes how spreading codes are used in DSSS systems and the importance of code synchronization. It also discusses simulating DSSS and CDM systems as well as implementing a spread spectrum receiver using SDR hardware.

Uploaded by

Nga V. Dao
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Laboratory 5: Spread Spectrum Communications

Cory J. Prust, Ph.D.


Electrical Engineering and Computer Science Department
Milwaukee School of Engineering
Last Update: 19 September 2018

Contents
0 Laboratory Objectives and Student Outcomes 2
0.1 Laboratory Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
0.2 Student Outcomes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1 Background 3
1.1 Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Code-Division Multiplexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Direct Sequence Spread Spectrum Simulation 6

3 Code Division Multiplexing Simulation 9

4 DSSS BSPK - Text Message Communication 11

1
0 Laboratory Objectives and Student Outcomes
0.1 Laboratory Objectives
This laboratory will assist students in understanding fundamental concepts of spread spectrum communica-
tion systems. The activities focus on direct sequence spread spectrum (DSSS) techniques such as those used
in the Global Positioning System (GPS) and 3G Code Division Multiple Access (CDMA) cellular phone sys-
tems. Students will use simulation to experiment with and verify the operation of DSSS systems. Students
will then utilize SDR hardware to implement a spread-spectrum receiver capable of decoding a DSSS signal
sent over a wireless channel.

0.2 Student Outcomes


Upon successful completion of this laboratory, the student will:
ˆ Explain how spreading codes are used in direct sequence spread spectrum communication systems.

ˆ Explain the importance of code synchronization in a spread spectrum communication system.

ˆ Simulate a direct sequence spread spectrum communication system.

ˆ Simulate a multi-user communication system that uses code-division multiplexing.

ˆ Implement a spread-spectrum receiver using SDR hardware and verify its operation over a wireless
channel.

2
1 Background
This laboratory concerns direct sequence spread spectrum (DSSS) communication systems. We will consider
the baseband modulator (transmitter) given by the following block diagram
m(t)  g(t)
- × -

6

c(t)

where m(t) is the message signal and c(t) is the spreading signal. The baseband demodulator (receiver) is
given by the following block diagram
g(t)  m̂(t)
- × -

6

c(t)

We will consider DSSS systems described as follows:


ˆ The message signal m(t) represents binary digital information and encodes the message bits as having
values ±1 over the bit interval, Tb . Therefore, m(t) is the complex envelope of a BPSK communication
signal.
ˆ The spreading waveform c(t) has values ±1 over the chip interval, Tc . The sequence of values in c(t) is
given by a pseudo-noise (PN) code of length M . We define c(t) to be a periodic repetition of the PN
sequence, and therefore c(t) has period M Tc .
ˆ We will assume Tc << Tb . That is, the chip rate Rc = 1/Tc is much higher than the bit rate Rb = 1/Tb .
The multiplication by c(t) in the modulator causes a spreading of the message signal spectrum. We
define the spreading factor, L, to be
Rc
L = (1)
Rb
The bandwidth of the spread spectrum signal g(t) is approximately L times larger than the bandwidth
of the message signal m(t).
ˆ Because both m(t) and c(t) have values ±1, g(t) also has values ±1. Therefore, we can consider g(t) to
be the complex envelope of a BSPK communication signal. The passband communication signal can
then be expressed as
s(t) = <{g(t)ej2πfc t }
= m(t)c(t) cos(2πfc t)

ˆ Note that the output of the multiplier in the receiver is


m̂(t) = g(t)c(t)
= m(t)c2 (t)
= m(t)
since the spreading waveform c(t) takes on values ±1. The multiplication in the receiver is often
referred to as a despreading operation.

3
1.1 Synchronization
The DSSS receiver must have knowledge of the PN code in order to generate c(t) for the despreading
operation. Furthermore, the locally generated PN code in the receiver must be synchronized to the PN
code used in the transmitter. Details of the synchronization processes used in real-world DSSS systems are
beyond the scope of this laboratory. However, many of the synchronization processes involve correlating the
received data with the known PN code. These techniques leverage the fact that certain PN codes exhibit
special correlation properties making them useful for synchronization1 . These properties are revealed by
computing the autocorrelation function of the PN code.
Let c[n] denote the periodic spreading sequence having period M . Define the autocorrelation function of
c[n] as
M −1
1 X
Rc [k] = c[n]c[n − k]
M n=0

The autocorrelation function is a measure of similarity between the code and time-shifted versions of the
code. Note that for c[n] taking on values ±1, Rc [0] = 1 is the maximum value of the autocorrelation function.
For purposes of synchronization, it then follows that a code having small autocorrelation values for k 6= 0 is
desirable.
Figure 1 shows an example MATLAB script for computing the autocorrelation function of a given PN code.
The script also demonstrates using the MATLAB function xcorr for correlating a received signal with its
PN code. The issue of synchronization will be further explored in Sections 2 and 4.

1.2 Code-Division Multiplexing


Spread spectrum techniques can be used to transmit multiple message signals simultaneously in the same
frequency band. Such techniques, referred to as code-division multiplexing (CDM), are often used in mobile
phone communications. This form of multiplexing is made possible by assigning each user a unique spreading
code from a set of codes. Then, multiple spread-spectrum signals can be transmitted in the same frequency
band, and the messages can be decoded at each receiver using the unique (and properly synchronized)
spreading code. In this way, the larger bandwidth used by spread-spectrum systems is offset by allowing
multiple users to simultaneously access the frequency band.
One of the best-known sets of spreading codes used in CDM systems are the Walsh-Hadamard codes. These
particular codes have the desirable property that they are mutually orthogonal. That is, when properly
synchronized, the correlation between any one code and any other code is exactly zero. The matrix below
shows the set of length 8 orthogonal Walsh-Hadamard codes, where each row of the matrix is a different
spreading code.
 
+1 +1 +1 +1 +1 +1 +1 +1
 +1 −1 +1 −1 +1 −1 +1 −1 
 
 +1 +1 −1 −1 +1 +1 −1 −1 
 
 +1 −1 −1 +1 +1 −1 −1 +1 
H8 =   +1 +1 +1 +1 −1 −1 −1 −1 

 
 +1 −1 +1 −1 −1 +1 −1 +1 
 
 +1 +1 −1 −1 −1 −1 +1 +1 
+1 −1 −1 +1 −1 +1 +1 −1
Note that each code is orthogonal to every other code (i.e., the inner product of any one row with any other
row is exactly zero). The concept of CDM using DSSS will be further explored in Section 3.
1 The subject of designing and generating PN sequences is beyond the scope of this laboratory. Well-known codes include

m-sequences, Gold codes, and Walsh-Hadamard codes. Students interested in learning more are encouraged to consult the
course textbook or take a follow-on course in communication systems and/or coding theory.

4
1 %% example_correlation .m
2 % Example script that computes the au t oc or re l at io n function of a
3 % PN sequence . The script also demonstrates using the MATLAB " xcorr "
4 % function to correlate a received signal with a PN sequence .
5 %
6 % Cory J . Prust , Ph . D .
7 % Last Modified : 8/3/2018
8
9 close all
10 clear all
11
12 % % Specify PN code
13 code = [ -1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 1] ' ;
14 M = length ( code ) ;
15
16 % % Compute A u to co rr e la ti o n Function
17 % R [ k ] = 1/ M sum_ { n =1}^{ M } c [ n ] c [n - k ]
18 % Note : " circshift " is used because the sequence is assumed periodic
19 R = zeros (M ,1)
20 k = 0:1:( M -1) ;
21 for ii =1: length ( k )
22 R ( ii ) = 1/ M * ( code ' * circshift ( code , k ( ii ) ) ) ; % circshift
23 end
24 stem (k , R )
25
26 % % Simulate received DSSS data and use " xcorr " to correlate it with PN code
27 % Assume spreading factor of M
28 m = [1 1 -1 1] ' ;
29 g = [ m (1) * code ; m (2) * code ; m (3) * code ; m (4) * code ]; % or , use " g = kron (m , code ) ;"
30
31 [r , lag ] = xcorr (g , code ) ;
32 figure
33 stem ( lag , r )

Figure 1: MATLAB example showing calculation of the autocorrelation function of a PN sequence and
use of MATLAB’s xcorr function.

5
2 Direct Sequence Spread Spectrum Simulation
In this portion of the laboratory you will construct a Simulink model for simulating a direct sequence spread
spectrum (DSSS) communication system. The complete model is shown in Figure 2.

Figure 2: Simulink model for simulating a DSSS transceiver.

The following sequence of steps is suggested:


1. Open a new Simulink model and define the following in Model Properties -> Callbacks -> InitFcn.
fs = 1e3; % sampling frequency
Ts = 1/fs; % sample time
Tb = 0.1; % bit time
Tc = 0.01; % chip time
frameSize = 1000; % size of each frame in source blocks
The model will be specified in terms of these parameters.

2. Construct the DSSS BPSK Transmitter portion of the model.


ˆ The Bernoulli Binary Generator block generates random binary numbers using a Bernoulli
distribution. This block acts as our message source in the simulation. Set Sample time to Tb.
Set the Samples per frame to frameSize.
ˆ The BPSK Baseband Modulation block applies BSPK modulation to the message bits. The
output of this block connects to a Ideal Rectangular Filter block, which translates the BPSK
symbols into rectangular pulses. Set Pulse length (number of samples) to Tb/Ts. Set the
Input processing for Columns as frames and set the Rate options for Allow multirate
processing. The output of this block is the complex envelope of our BPSK waveform, m(t).
ˆ The Signal from Workspace block specifies the spreading sequence. Set Signal to

[-1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 1]

set Sample time to Tc, and set Samples per frame to frameSize. The output of this block
connects to a Ideal Rectangular Filter block, which translates the sequence into rectangu-
lar pulses. Set Pulse length (number of samples) to Tc/Ts, set Form output after final
data value by to Cyclic repetition. Set the Input processing for Columns as frames and

6
set the Rate options for Allow multirate processing. The output of this block is the spread-
ing waveform, c(t).
ˆ The Product block creates the complex envelope of the DSSS BPSK signal, m(t)c(t).

Experiment with this portion of the model by adding Time Scope and Spectrum Analyzer blocks.
Hint: You may find it helpful to change the Time Scope to a “stem” plot by selecting View -> Style
and changing the Plot type setting.
3. Add the AWGN Channel block, specifying the Mode as Variance from port and using a Constant
block to control the noise variance. As you experiment with the model, adjust the noise variance (i.e.
the noise power) to see the effects of noise on the system.

4. Construct the DSSS BPSK Receiver portion of the model.


ˆ The Signal from Workspace block and Ideal Rectangular Pulse block create the spreading
sequence (for purposes of despreading), and are identical to those used in the transmitter portion
of the model.
ˆ The Delay block allows you to delay the receiver spreading sequence used relative to the one
used in the transmitter. Set Delay length to Input port and use a Constant block to specify
the delay. Set the Input Processing to Columns as channels (frame based). The delay can
be modified while the model is running. Use only integer values.
ˆ The Product block performs the despreading operation in the receiver.
ˆ The Integrate and Dump block integrates the received pulses, which can be thought of as part
of the ideal correlation receiver (or the matched filtering process). Set the Integration period
(number of samples) parameter to Tb/Ts. The Gain block, set to Ts/Tb, adjusts the amplitude
of the resulting signal to the nominal range of ±1.
For simplicity, the additional blocks required to recover the binary message have been omitted from
the model.

5. Experiment with the model by running it. Add Time Scope and Spectrum Analyzer blocks as
needed. Be sure you understand how it operates before proceeding.

7
Question 2.1: Based on the parameters specified in Step 1 above, what is the spreading factor
of the DSSS system?
Question 2.2: Use MATLAB to compute the autocorrelation function for the sequence given in
Step 2 above. Comment on the properties of the autocorrelation function. Does the sequence
exhibit desirable properties for use in a DSSS communication system? Submit your MATLAB
code and plot of the autocorrelation function.
Question 2.3: In the DSSS BPSK Transmitter, connect a Spectrum Analyzer block to the
BPSK message waveform m(t) and the spread waveform m(t)c(t). Submit a screen capture.
Measure the bandwidth of each signal. Do these bandwidth measurements agree with the
spreading factor of the DSSS system? Hint: Measure the bandwidth as the frequency of the first
spectral null.
Question 2.4: In the DSSS BPSK Receiver, connect a Time Scope and Spectrum Analyzer
block to the recovered message waveform (output of the Product block). Carefully examine
these plots as you adjust the Delay length parameter of the Delay block. You should observe
that the receiver properly recovers the message signal when the Delay length parameter is 0.
Describe what happens to the recovered message when the Delay length parameter is 1.
Describe what happens when the Delay length parameter is 16. Explain the results.

8
3 Code Division Multiplexing Simulation
In this portion of the laboratory you will construct a Simulink model for simulating a communication system
that uses code division multiplexing to send multiple messages simultaneously in the same frequency channel.
The complete model is shown in Figure 3.

Figure 3: Simulink model for simulating code division multiplexing.

The following sequence of steps is suggested:


1. Open a new Simulink model and define the following in Model Properties -> Callbacks -> InitFcn.
fs = 1e4; % sampling frequency
Ts = 1/fs; % sample time
Tb = 0.1; % bit time
Tc = 0.0125; % chip time frameSize = 1000; % size of each frame in source blocks
The model will be specified in terms of these parameters.
2. Construct the Transmitter portion of the model.
ˆ The Bernoulli Binary Generator, BPSK Modulator Baseband, and Ideal Rectangular
Filter blocks are used in the same manner they were in Section 2.
ˆ The sequences

[1 -1 -1 1 -1 1 1 -1]

and

[1 1 -1 -1 1 1 -1 -1]

are the spreading codes for User 1 and User 2, respectively. Note that these codes are members
of the length 8 Walsh-Hadamard codes.
ˆ The Add block is used to sum the User 1 and User 2 coded messages into a single transmission.
3. Construct the User 1 Receiver and User 2 Receiver portions of the model.

9
ˆ The Ideal Rectangular Filter, Product, Integrate and Dump, and Gain blocks are used
in the same manner they were in Section 2.
ˆ Be sure to use the proper sequences for each receiver.

4. Experiment with the model by running it. Add Time Scope and Spectrum Analyzer blocks as
needed. Be sure you understand how it operates before proceeding.

Question 3.1: In the Transmitter, use Time Scope and Spectrum Analyzer blocks to
observe the inputs to and the output of the Add block. That is, observe the User 1 and User 2
DSSS signals, and their sum. Include screen captures and comment on what you observe. In
particular, comment on the signal bandwidths.
Question 3.2: Use a Time Scope block to display the User 1 and User 2 messages in the
transmitter, and the User 1 and User 2 messages recovered in the receiver. Submit screen
captures for simulations where the AWGN noise variance is 0, 1, and 10. Comment on the
results.
Question 3.3: Repeat the previous problem, however now change the User 2 Receiver sequence
to

[1 -1 1 -1 -1 1 -1 1]

10
4 DSSS BSPK - Text Message Communication
In this portion of the laboratory you will receive a DSSS BPSK waveform using your personal SDR device.
You will then despread the signal and recover an ASCII text message.
Construct the Simulink receiver model shown in Figure 4.

Figure 4: Simulink model for receiving a DSSS BPSK message.

Some salient points regarding the DSSS broadcast and the receiver model:
ˆ The DSSS broadcast consists of BPSK symbols. The message information is encoded using BSPK
modulation, giving symbols having values ±1. The chip sequence also contains values of ±1. Therefore,
the complex envelope of the broadcast signal has values of ±1, and can therefore be considered to be
a BSPK waveform.
ˆ The message bits are sent at 1000 bits per second, and the chip rate is 8000 chips per second.
ˆ The chip sequence used in the transmitter is

[-1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 1]

ˆ The transmitter uses rectangular pulse shapes.


ˆ RTL-SDR Receiver configuration:
– Sampling rate: 240e3
– Output data type: single
– Samples per frame: 120000
– “Lost samples output port” enabled. This signal will be non-zero when samples are lost. Connect
this output as shown to Cumulative Sum and Display blocks, which will count any samples that
are lost during the recording. It is important that no samples are lost. Consult your instructor if
samples are being lost.

11
– The center frequency must be corrected according to the calibration performed in our previous
laboratory.
ˆ The FIR Decimation block reduces the sample rate of the receive data by a factor of 3. The output
of the RTL-SDR Receiver block is configured for 240e3 samples per second, therefore the decimation
reduces the rate to 240e3/3 = 80e3 samples per second. This gives 10 samples per chip, or 80 samples
per bit, in the receive data. Confirm the sample rate, and the frequency offset correction, by carefully
viewing the Spectrum Analyzer plot.
ˆ The Carrier Synchronizer block adjusts for carrier frequency and phase offsets. Configure the
Modulation for BPSK and Samples per symbol to 10. This block will synchronize to the chip sequence.
IMPORTANT: This block may synchronize to a constellation that is a 180 degree rotation of the
transmitted signal. We will detect the presence of and correct for any such rotation in a later step.
ˆ The Symbol Synchronizer adjusts for clock drift in the incoming signal, ensuring that the incoming
pulses are sampled at the appropriate time. Configure the Timing error detector for Zero-Crossing
(decision directed) and Samples per symbol to 10. The block will output exactly one sample per
chip.

ˆ The Eye Diagram can be used to confirm that carrier synchronization has occurred. Set Samples
per symbol to 10.
ˆ The Constellation Diagram can be used to confirm the received constellation. Set Samples per
symbol to 1.

ˆ The To Workspace block writes data to the MATLAB workspace. Configure Limit data points
to last to 4000, and Save format to Structure.
– After running the model, you will see a structure named yout in the MATLAB workspace. You
can save the MATLAB workspace, and therefore your recorded data, using the save function in
MATLAB. You can then restore the workspace at a later time using the load function.
– The actual symbols are located within the structure at yout.signals.values

At this point, you should have a vector in MATLAB containing 4000 values, each of which corresponds to a
chip in the DSSS sequence. Your task is to recover the ASCII text message. The following sequence of steps
is suggested:
1. Confirm that the vector of data represents a baseband BSPK signal. You can do so by plotting the
data (e.g., using stem or scatterplot).
2. You will notice that the vector of data is complex-valued. Because the data is BPSK modulated, we
only need its real part. The command
data = real(yout.signals.values);
will extract just the real part of the vector.
3. You must implement the despreading operation. Doing so will require several steps:

ˆ Use the MATLAB xcorr function to correlate the data vector with the spreading sequence. For
example
code = [-1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 1];
[r,lag] = xcorr(code,data);
stem(lag,r)
will compute and plot the cross-correlation between the data vector and the spreading sequence.

12
ˆ Examine the cross-correlation plot carefully. It will tell you how to shift the spreading sequence
so as to properly despread the received data.
ˆ You must create the despreading signal. This can be thought of as a vector where each value
corresponds to a chip. You may find the MATLAB function circshift helpful for shifting the
code sequence. See Figure 1 for an example of using this function. You may find the MATLAB
function repmat helpful for creating the despreading signal. For example
c = repmat(code',250,1);
will create a column vector containing 250 consecutive copies of code representing the despreading
signal. Note that the dimensions of c should exactly match your received data vector.
ˆ The despreading operation is simply the element-by-element product of the received data and the
despreading signal. Plot the resulting waveform. You should be able to clearly see the BSPK
symbols, with 8 consecutive samples of nearly identical amplitude representing each bit.
4. Following proper despreading, it will be convenient to reduce the data vector to one sample per bit. It
is up to you to decide how to achieve this.
Hint: Because the transmitter used rectangular pulses, this operation could be as simple as retaining
every 8th sample. A more robust approach would be to compute the mean of every 8 samples, which
is effectively a matched filter operation for rectangular pulses.
5. You can now perform the BSPK demodulation to recover the binary data sequence.
6. Plot and carefully inspect the binary data sequence. In particular, locate a complete data frame by
identifying the message preamble (described by your instructor). If you see an inverted version of the
preamble, this means that the Carrier Synchronizer locked 180 degrees out of phase relative to the
transmit carrier. You can correct for this by inverting your binary data sequence.
7. After identifying a complete data frame, convert the binary sequence to ASCII characters. This process
is identical to the one used in a previous laboratory.

Question 4.1: Provide a plot of the cross-correlation between your received data and the
spreading sequence. Explain what is seen in the plot. Explain how this information was used in
the despreading operation.
Question 4.2: Provide time-domain stem plots showing the received data before and after the
despreading operation. Explain what is seen in the plot.
Question 4.3: Provide frequency-domain plots showing the signal before and after the
despreading operation. Explain what is seen in the plots. Comment on the relative bandwidth
of the signals.
Question 4.4: Explain how you processed the data vector, after despreading, to retain one
sample per bit (as described in Item 4 above). Include the MATLAB code you used to achieve
this task.
Question 4.5: Provide a time-domain stem plot of the recovered message bit sequence. This
plot must show the message preamble and a complete data frame. Annotate the plot, identifying
the preamble.
Question 4.6: What is the text message? Provide the complete MATLAB code listing you
used in this portion of the lab.

13
References
[1] Mathworks. Communications Toolbox. Online Resource. https://www.mathworks.com/products/communications.html.
[2] Mathworks. USRP Support Package from Communications Toolbox. Online Resource.
http://www.mathworks.com/discovery/sdr/usrp.html.
[3] Mathworks. RTL-SDR Support Package from Communications Toolbox. Online Resource.
https://www.mathworks.com/hardware-support/rtl-sdr.html.

[4] Leon W. Couch III. Modern Communication Systems. 1995.


[5] Simon Haykin. Communication Systems. 4th edition, 2001.
[6] B.P. Lathi and Zhi Ding. Modern Digital and Analog Communication Systems. 5th edition, 2019.

14

You might also like