1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
| close all;
clear all;
clc;
n1=1;
n2=14;
FFT_SIZE=256;
%CP=16;
conv_in=[];
%% Data Generator
Data_gen = randint(1,11,255)
Data_IN=dec2bin(Data_gen);
s=0;
%% BER PARAMETERS
EbNo=0:1:15;
BER = zeros(1,length(EbNo));
numPackets=15;
frmLen = 1000;
for idx = 1: length(EbNo)
for packetidx = 1 : numPackets
%% Convolution Encoder
conv_in=[];
for index =1:11
conv_in=[conv_in double(Data_IN(index,:))-48];
end
conv_in=[conv_in 0 0 0 0 0 0 0 0]; %%8 bits padding
DIN=conv_in;
trel = poly2trellis(7, [171 133]); % Define trellis.
code = convenc(conv_in,trel);
inter_out=code;
%% BPSK Data Mapping
mapper_out=mapping(inter_out',1,1);
clear inter_out;
D=mapper_out;
%% CDMA TRANSMITTER
% encode bits and transmit
% CDMA specific parameters
C = [ -1 1 -1 1 ]; % code for the user which will be multiplied %with data stream of the user#1 i.e.mapper_out
M = length(C); % length (number of bits) of code
Y = size(mapper_out);
N = Y(1); % number of unique senders / bit streams
I = Y(2); % number of bits per stream
T = []; % sum of all transmitted and encoded data on channel
RECON = []; % vector of reconstructed bits at receiver
G = zeros(I,M);
for n = 1:N
Z = zeros(I,M);
for i = 1:I
for m = 1:M
Z(i,m) = [D(n,i)*C(n,m)];
end
end
G = G + Z; %G is the data to be transmitted after IFFT
end
ifft_in=zeros(256,4);
for i=1:4
ifft_in(:,i)=[0;G(1:96,i);zeros(32,1);zeros(31,1);G(97:192,i)];
end
for i=1:4
tx_data(:,i)=ifft(ifft_in(:,i));
end
clear ifft_in;
%% Passing the data through AWGN channel
rx_data=zeros(256,4);
rx_data1=zeros(192,4);
for i=1:4
rx_data(:,i)=awgn(tx_data(:,i)./sqrt(16),EbNo(idx),'measured');
end
for i=1:4
rx_data(:,i)=awgn(rx_data(:,i)./sqrt(16),EbNo(idx),'measured');
end
for i=1:4
rx_data(:,i)=awgn(rx_data(:,i)./sqrt(16),EbNo(idx),'measured');
end
%% OFCDM RECEIVER PART:
%% Taking FFT of the noisy data after reception
clear tx_data;
for i=1:4
rx_data(:,i)=fft(rx_data(:,i));
end
for i=1:4
rx_data1(:,i)=[rx_data(2:97,i); rx_data(161:256,i)]; % taking out user#1 symbols for despreading
end
G=rx_data1;
%% CDMA RECEIVER
for n = 1:N
TOT = zeros(1,I);
R = zeros(I,M);
for i = 1:I
for m = 1:M
R(i,m) = G(i,m) * C (n,m);
TOT(i) = TOT(i) + R (i,m);
end
end
RECON = [RECON ; TOT / M];
end
RECON
rx_data1=RECON;
Demap_out=demapper(rx_data1,1,1);
%%viterbi decoder
vit_out=vitdec(Demap_out,trel,7,'trunc','hard');
DOUT=vit_out
[number,ratio] = biterr(DIN,vit_out);
error(packetidx) = biterr(DIN,vit_out);
end % End of for loop for numPackets
BER21(idx) = sum(error)/(log2(4)*numPackets*frmLen);
end
h=gcf;clf(h); grid on; hold on;
set(gca,'yscale','log','xlim',[EbNo(1), EbNo(end)],'ylim',[0 1]);
xlabel('Eb/No (dB)'); ylabel('BER'); set(h,'NumberTitle','off');
set(h,'Name','BER Results');
set(h, 'renderer', 'zbuffer'); title('OFCDM BER PLOTS');
semilogy(EbNo(1:end),BER21(1:end),'b-*'); |