You are on page 1of 10

Digital Communication Lab

Experiment 9: Software Simulation of Spread


Spectrum Communication System

Department of Electronics and Communication Engineering


National Institute of Technology, Calicut

Submitted by:
K. Subash Chandra B140644EC
K. Dency Daniel B140220EC
M.Tejesh Reddy B140443EC
M. Narendra Reddy B140773EC
M.Pavan Kumar B140493EC
M. Dinesh Sai B140681EC
1 Aim
1. To generate all possible maximal length pseudo-noise (PN)
sequences of length 15, 31 and 63. Plot the discrete autocorrelation of
at least 2 sample sequences and cross correlation between two
sample sequences for each of the sequence lengths.

2. To identlify two maximal length sequences for each of these lengths


and use them as seed sequences for generating gold codes. Plot the
autocorrelation and cross correlation functions of gold codes.

3. To generate Walsh codes of length 32 and 64 and plot the


autocorrela-tion and cross correlation of some sample sequences.

4. To make a comparative study of the autocorrelation and cross


correla-tion properties of these sequences.

5. To modify the BPSK communication systems implemented to


include spreading and despreading assuming perfect mode
synchronisation, i.e spread the random data with m-sequence of
length 31 and 63 and then modulate using BPSK and do the
reverse operation at receiver. Get the BER performance plot.
Repeat the experiment for AWGN chan-nel (0-14 dB) and Rayleigh
fading channel (0-30 dB). To compare the performance with
respective plots obtained without spreading and de-spreading.

2 Theory
2.1 Spreading sequences
In spread spectrum communication, typically in CDMA, the user data is
multiplied with a spreading sequence to obtain spreading. When the
signal is received, the spreading is removed from the desired signal by
multiplying it by the same sequence that is exactly synchronized to the
transmitted PN signal.The desired property of the sequences is low
cross correlation with other spreading sequences.Some well known
sequences are PN sequences, gold codes and Walsh codes.

1
2.2 Pseudo Noise Sequences
These are noise like wideband spread spectrum signals. Pseudo random noise
is a signal similar to noise which satis es one or more of the standard texts for
statistical randomness. PN sequences are deterministically generated how-
ever. They are almost like random sequences which apparently lack a de nite
pattern. In reality, it is a deterministic sequence of pulses that will repeat
periodically. Pseudorandom sequences can be generated using a Linear For-
ward Shift Register (LFSR) based on a Mth degree primitive polynomial.

2.3 Maximal length sequences


Shift register sequences having the maximum possible period of an r-
stage shift register are called maximal length sequences or m-
sequences. A primi-tive generator plynomial always yields an m-
sequence. The maximum period of an r-stage shift register can be
proven to be 2r-1. The m-sequence has three important properties:
Balance property, Run-length property and Shift and Add property.

2.4 Walsh codes


The Walsh code, also known as Hadamard codes are error correcting codes
used over highly noisy or unreliable channels. It is an example of a linear code
over a binary alphabet that maps messages of length k to codewords of length
k
2 . In CDMA it is used to de ne individual communication channels. Since
Walsh codes are orthogonal in nature their cross correlation is zero and other
Walsh codes appear as random noise to a particular Walsh code. A Walsh-
Hadamard matrix of order N is an N*N matrix of 1's and -1's in which
T
HH = NIN .

2.5 Gold codes


Some pairs of m sequences with the same degree can be used to generate
gold codes by linearly combining two m-sequences with di erent o set in Galois
eld. All pairs of m-sequences do not yield gold codes and those which yield
gold codes are called preferred pairs.By xing the seed of an m-sequence
generator as r, 2r gold codes are obtained by changing the second generator

2
from 0 to 2r-1. Theoretical cross-correlation of gold sequences is three valued
and is given by where t(n) is given by
n+1
t(n) = 2 2 + 1; n is odd
n+2
= 2 2 + 1; niseven

3 Code
1. Correlation plotting function
function [corr] = cor(c1,c2)
c1 = [c1 c1];
corr = [];
N = length(c2);
for i=1:N
corr=[corr sum(c1(i:N+i-1).*c2)/N];
end
stem(corr);

2. PN Sequence
function [pnseq] = pnsq(G, m)
S = [1 zeros(1, m-1)];
N = 2^m-1;
pnseq = [];
for i=1:N
pnseq = [pnseq S(1)];
k = mod(sum(S.*G(1:m)), 2);
S = circshift(S', -1)';
S(m) = k;
end
pnseq = 2*pnseq-1;
end

3. Gold Codes
clc;
m = [5 6];
G = [1 0 0 1 0 1 0 1 1 1 1 0 1 0;
1 0 0 0 0 1 1 1 1 0 0 1 1 1];
for i=1:length(m)
c11 = (pnsq(G(i, 1:7), m(i))==1);
c12 = [];
k = 3;
v11 = [c11 c11 c11 c11 c11];
for j=1:(2^m(i)-1)
c12 = [c12 v11(k)];
k = k+5;
end
X1 = 2*xor(c11, circshift(c12', 1)')-1;
X2 = 2*xor(c11, circshift(c12', 2)')-1;
figure;
subplot(211);
cor(X1, X1);
title(['Auto-correlation of ',num2str(2^m(i)-1),' length goldcode']);
xlabel('Time Index');
ylabel('Amplitude');
subplot(212);
cor(X1, X2);
title(['Cross-correlation of ',num2str(2^m(i)-1),' length goldcode']);
xlabel('Time Index');
ylabel('Amplitude');
end

4. Walsh Hadamard Codes

clc;
clear all;
N=32;
H32 = ones(N);
k = N/2;
while k>=1
for i=1:N/k
for j=1:N/k
if mod(i, 2) + mod(j,2)==0
H32((i-1)*k+1:i*k, (j-1)*k+1:j*k) = ~H32((i-1)*k+1:i*k, (j-1)*k+1:j*k);
end
end
end
k = k/2;
end
H32 = 2*H32-1;

N=64;
H64 = ones(N);
k = N/2;
while k>=1
for i=1:N/k
for j=1:N/k
if mod(i, 2) + mod(j,2)==0
H64((i-1)*k+1:i*k, (j-1)*k+1:j*k) = ~H64((i-1)*k+1:i*k, (j-1)*k+1:j*k);
end
end
end
k = k/2;
end
H64 = 2*H64-1;

figure;
subplot(211);
cor([H32(3, :)],[H32(3, :)] );
title('Auto-correlation of 32 length Walsh-Hadamard Code');
xlabel('Time Index');
ylabel('Amplitude');
subplot(212);
cor([H32(3, :)], [H32(15, :)]);
title('Cross correlation of 32 length Walsh Hadamard Code');
xlabel('Time Index');
ylabel('Amplitude');

figure;
subplot(211);
cor(H64(8,:), H64(8,:));
title('Auto-correlation of 64 length Walsh-Hadamard Code');
xlabel('Time Index');
ylabel('Amplitude');
subplot(212);
cor(H64(8,:), H64(15,:));
title('Cross correlation of 64 length Walsh Hadamard Code');
xlabel('Time Index');
ylabel('Amplitude'
4 Inferences
1. A PN generator will produce a periodic sequence that eventually re-
peats but that appears to be random.

2. The m-sequence provides the best periodic auto-correlation in


terms of minimizing the value of the out of phase autocorrelation.

3. The cyclic shift of the m-sequence was also observed to be an m-


sequence.

4. The m-sequence is best utilized if the synchronization window is


longer than the on period.

5. The autocorrelation properties of a PN generator are excellent and


the cros correlation with a time-shifted version of itself is also
equivalent to the same.

6. Gold codes were constructed from a modulo-2 addition of two maximum


length sequences, which helps in generating a large number of code.

7. . The receiver utilizes the autocorrelation property of the gold code


to depict the message.
8. Walsh codes were found to possess excellent cross-correlation
properties as the cross-correlation of one Walsh code with another
is always zero, since they are orthogonal.
9. The autocorrelation property of the Walsh code is poor and hence it
is used only in synchronous CDMA networks where the start of the
codeword can be identi ed.
5. Results
1. The simulation of spread spectrum communication system was
per-formed.

2.The autocorrelation and cross correlation properties of gold


codes, walsh codes and PN sequences were determined and
analysed.

3. BER performance of BPSK scheme with and without frequency


spread-ing was plotted and analysed.

4.The best cross correlation performance is for Walsh Hadamard


sequence.

5. In high SNR region, both Rayleigh and AWGN with spreading


gave better performance.
6 . Graphs

Figure 1: PN sequence of length 15

Figure 2: PN sequence of length 31

1
Figure 3: Gold Code of length 31

Figure 4: Walsh code of length 32