OFCDM
This section of MATLAB source code covers OFCDM MATLAB code. OFCDM stands for Orthogonal Frequency Code Division Multiplexing.
OFCDM is a combination of CDMA and OFDM techniques. In this example, OFCDM transmitter is shown with FEC encoder (convolution encoder), BPSK modulator, spreading module and IFFT module with 256 point. The receiver is composed of FFT, despreading, BPSK demodulator and viterbi decoder.
Following is the OFCDM MATLAB code and BER curve. BER curve is obtained after passing the data from AWGN.
OFCDM MATLAB Code
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-*');
BER Curve
DOWNLOAD Source Code
Download OFCDM MATLAB source code files.
Useful Links to MATLAB codes
Refer following as well as links mentioned on left side panel for useful MATLAB codes.
OFDM Preamble generation
Time off estimation corr
Freq off estimation corr
channel estimation
11a WLAN channel
PN sequence generation
OFDMA Tx Rx
AES DES
carrier aggregation
CCDF
FIR Filter
IIR Filter
Low Pass FIR
Viterbi decoder
CRC8 CRC32
RF and Wireless tutorials
WLAN 802.11ac 802.11ad wimax Zigbee z-wave GSM LTE UMTS Bluetooth UWB IoT satellite Antenna RADAR