CDMA Example with MATLAB Firstly we generate a small random sequence of binary data, that we represent as a sampled waveform with 64 samples per bit. % CDMA example clear all data = randint(1,15,2); for j = 1:64, count = count + 1; data_exp(count) = data(i); data_exp = 2*data_exp - 1; figure(1) plot(data_exp)
Then we generate the spectrum of this signal, to illustrate that it is a fairly narrowband signal. % generate spectrum data_f = fft(data_exp); figure(11) plot(abs(data_f(1:(15*32)))) title('data spectrum') Then we select one of the Walsh codes, and use it to spread our data. The spreading process simply involves multiplying the data line code by the higher rate spreading code (the spreading code here is at 64 times the data rate. That is, chip rate = 64 * data rate). The resultant signal is at a much higher data rate the same as the chip rate. % generate a spreading code for a user codes = hadamard(64); user_code = codes(:,35); spread = zeros(1,15*64); spread((count+1):(count+64)) = data_exp((count+1):(count+64)).*(user_code'); count = count + 64;
figure(2) plot(spread) The resultant spectrum is much wider in bandwidth than the spectrum of the data signal. Note that the code below doesn t give an accurate rition of the spectrum of the spread signal. Why? spread_f = fft(spread); figure(12) plot(abs(spread_f(1:(15*32)))) title('spread spectrum')
We can then recover the data from the spread signal by multiplying by the code waveform and summing every 64 chips (since 1*1 = 1 and -1*-1 = 1, the effect of multiplying by the code twice is to recover the original data sequence. Obviously synchronisation is an issue how do we match the code sequence at the transmitter and the receiver? % recover user data data_desp((count+1):(count+64)) = spread((count+1):(count+64)).*(user_code'); count = count + 64; time_base = 1:(15*64); data_rec(i) = sum(data_desp((count+1):(count+64)))/64; count = count+64; for j = 1:64, count = count + 1; data_rec_exp(count) = data_rec(i);
figure(3) plot(time_base,data_rec_exp,time_base,data_exp) We can add noise to the CDMA spread signal to such an extent that the signal is indistinguishable below the noise floor. % now let's add some noise noise = 5*randn(1,15*64); noisy_cdma = spread + noise; figure(4) plot(noisy_cdma) axis([1,15*64,-12,12])
We can recover our signal in the same way, since our signal is highly correlated to the code, but the code and the noise signal are uncorrelated. % recover the CDMA signal noisy_data_desp((count+1):(count+64)) = noisy_cdma((count+1):(count+64)).*(user_code'); count = count + 64; time_base = 1:(15*64); noisy_data_rec(i) = sum(noisy_data_desp((count+1):(count+64)))/64; count = count+64; if (noisy_data_rec(i) > 0) noise_rec(i) = 1; else noise_rec(i) = -1;
for j = 1:64, count = count + 1; noisy_data_rec_exp(count) = noise_rec(i); figure(5) plot(time_base,noisy_data_rec_exp,time_base,data_exp) This illustrates the basic idea of DS CDMA. The thing we have not represented here is the carrier wave, but all of the above discussion holds true. We can also consider how CDMA can be used to achieve multiple access by assigning users different orthogonal codes. % multiple user CDMA clear all data1 = randint(1,15,2); data2 = randint(1,15,2);
for j = 1:64, count = count + 1; data_exp1(count) = data1(i); data_exp2(count) = data2(i); data_exp1 = 2*data_exp1-1; data_exp2 = 2*data_exp2-1; figure(21) plot(data_exp1) We can then add these spread signals together and transmit them over the AWGN channel (so just add noise). % generate a spreading code for a user codes = hadamard(64); user_code1 = codes(:,35); user_code2 = codes(:,44); spread1 = zeros(1,15*64); spread2 = zeros(1,15*64);
spread1((count+1):(count+64)) = data_exp1((count+1):(count+64)).*(user_code1'); spread2((count+1):(count+64)) = data_exp2((count+1):(count+64)).*(user_code2'); count = count + 64; noise = 2*randn(1,15*64); noisy_cdma = spread1+ spread2 + noise; figure(24) plot(noisy_cdma) axis([1,15*64,-12,12]) We can then recover the CDMA signal of each user as before. The effect of the other user signal does not contribute, since the two codes were chosen to be orthogonal. Once again we ignore here synchronisation issues. % recover the CDMA signal noisy_data_desp((count+1):(count+64)) = noisy_cdma((count+1):(count+64)).*(user_code1'); count = count + 64;
time_base = 1:(15*64); noisy_data_rec(i) = sum(noisy_data_desp((count+1):(count+64)))/64; count = count+64; if (noisy_data_rec(i) > 0) noise_rec(i) = 1; else noise_rec(i) = -1; for j = 1:64, count = count + 1; noisy_data_rec_exp(count) = noise_rec(i); figure(25) plot(time_base,noisy_data_rec_exp,time_base,data_exp1) plot(spread)