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');
- 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.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
- 207.
- 208.
- 209.
- 210.
- 211.
- 212.
- 213.
- 214.
- 215.
- 216.
- 217.
- 218.
- 219.
- 220.
- 221.
- 222.
- 223.
- 224.
- 225.
- 226.
- 227.
- 228.
- 229.
- 230.
- 231.
- 232.
- 233.
- 234.
- 235.
- 236.
- 237.
- 238.
- 239.
- 240.
- 241.
- 242.
- 243.
- 244.
- 245.
- 246.
- 247.
- 248.
- 249.
- 250.