Sie sind auf Seite 1von 3

clc; close all; clear all;

% addpath('.\comm');
% addpath('.\lte');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Performance comparison of NOMA-OFDM system and %
% traditional OFDMA system, % Vision 1.0.0, 2017/4/8. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% ??
order_psk = [2,4,8,16,64]; % PSK????,2??BPSK,4??4PSK,????
for order = 1:length(order_psk)
sym_total = 2.048e4*52; % ????
len_turbo = 1280; % Turbo??
bit_total = sym_total * log2(order_psk(order));
N_ofdma_u1 = 26; % OFDMA??1?????
N_ofdma_u2 = 26; % OFDMA??2?????
p1 = 0.1; % NOMA??1???
p2 = 0.9; % NOMA??2???

N_ofdm = 64; % OFDM????


N_data = 52; % ?????
N_GB = [4; 3]; % ??????
N_P = [12; 26; 40; 54]; % ????
CP = 1/4; % CP??

Ts = 1/10000;
FD = 500; % ??????
SNR = 25:1:60; % ???

%% ???????
if (mod(bit_total, len_turbo)~=0)
error('???????Turbo????????');
end
if (mod((3*len_turbo+12)*bit_total/len_turbo, N_data)~=0)
error('????????OFDM????');
end
if (N_ofdma_u1+N_ofdma_u2~=N_data)
error('OFDMA??????????????????????');
end
if (p1+p2~=1)
error('????p1?p2??????1');
end

%% ?????????????,??Turbo??
[sym_seq_u1, bit_seq_u1] = data_gen(bit_total, len_turbo, order_psk(order));
[sym_seq_u2, bit_seq_u2] = data_gen(bit_total, len_turbo, order_psk(order));
% mean(abs(sym_seq_u1).^2)
% mean(abs(sym_seq_u2).^2)

%% NOMA?OFDMA
sym_seq_noma = noma_enc(sym_seq_u1, sym_seq_u2, p1, p2);
% mean(abs(sym_seq_noma).^2)
% ????????NOMA??
sym_seq_ofdma = ofdma_enc(sym_seq_u1, sym_seq_u2, N_ofdma_u1, N_ofdma_u2);
% mean(abs(sym_seq_ofdma).^2)
% ????????OFDMA??

%% OFDM??
num_ofdmsym_noma = length(sym_seq_noma)/N_data;
mod_ofdm_noma = comm.OFDMModulator(...
'FFTLength',N_ofdm,...
'NumGuardBandCarriers',N_GB,...
'PilotInputPort',true,...
'PilotCarrierIndices',N_P,...
'NumSymbols',num_ofdmsym_noma,...
'CyclicPrefixLength',N_ofdm*CP,...
'InsertDCNull',true);
% ??NOMA?OFDM???
num_ofdmsym_ofdma = length(sym_seq_ofdma)/N_data;
mod_ofdm_ofdma = comm.OFDMModulator(...
'FFTLength',N_ofdm,...
'NumGuardBandCarriers',N_GB,...
'PilotInputPort',true,...
'PilotCarrierIndices',N_P,...
'NumSymbols',num_ofdmsym_ofdma,...
'CyclicPrefixLength',N_ofdm*CP,...
'InsertDCNull',true);
% ??OFDMA?OFDM???

tx_noma = ofdm_tx(sym_seq_noma, mod_ofdm_noma);


% tx_noma = sym_seq_noma;
tx_ofdma = ofdm_tx(sym_seq_ofdma, mod_ofdm_ofdma);
% OFDM??
% mean(abs(tx_noma).^2)
% mean(abs(tx_ofdma).^2)

for snr = 1:length(SNR)


%% ????
% crl = rayleighchan(Ts, FD);
% tx_noma = filter(crl, tx_noma);
% tx_ofdma = filter(crl, tx_ofdma);
cawgn = comm.AWGNChannel('NoiseMethod', 'Signal to noise ratio (SNR)');
cawgn.SNR = SNR(snr);
rx_noma = step(cawgn, tx_noma);
rx_ofdma = step(cawgn, tx_ofdma);
% mean(abs(rx_noma).^2)
% mean(abs(rx_ofdma).^2)
% ?????????????????

%% OFDM??
sym_seq_noma_mat = ofdm_rx(rx_noma, mod_ofdm_noma);
sym_seq_noma = reshape(sym_seq_noma_mat, numel(sym_seq_noma_mat), 1);
% sym_seq_noma = rx_noma;
sym_seq_ofdma_mat = ofdm_rx(rx_ofdma, mod_ofdm_ofdma);
sym_seq_ofdma = reshape(sym_seq_ofdma_mat, numel(sym_seq_ofdma_mat), 1);
% mean(abs(sym_seq_noma).^2)
% mean(abs(sym_seq_ofdma).^2)

%% NOMA?OFDMA??
if (p1>p2)
[bit_u1, bit_u2] = noma_dec(sym_seq_noma, len_turbo, order_psk(order),
p1, p2);
else
[bit_u2, bit_u1] = noma_dec(sym_seq_noma, len_turbo, order_psk(order),
p2, p1);
end

[n1,r1(order, snr)] = biterr(bit_u1,bit_seq_u1);


[n2,r2(order, snr)] = biterr(bit_u2,bit_seq_u2);

% ??????????1???2?????
[bit_u11, bit_u22] = ofdma_dec(sym_seq_ofdma, len_turbo, order_psk(order),
N_ofdma_u1, N_ofdma_u2);

[n11,r11(order,snr)] = biterr(bit_u11,bit_seq_u1(1:length(bit_u11)));
[n22,r22(order,snr)] = biterr(bit_u22,bit_seq_u2(1:length(bit_u22)));
[r1(order,snr), r2(order,snr), r11(order,snr), r22(order,snr)]
end

end
%
save('ber.mat','r1','r2','r11','r22');
plot_ber(order_psk, SNR, N_data, p1, p2, N_ofdma_u1, N_ofdma_u2);

% rmpath('.\comm');
% rmpath('.\lte');