基于 DCO-OFDM 的 NOMA的可见光通信系统误码率仿真matlab
时间: 2023-12-14 21:05:08 浏览: 95
多径信道下OFDM通信系统误码率仿真附matlab代码
5星 · 资源好评率100%
以下是基于 DCO-OFDM 的 NOMA 可见光通信系统误码率仿真的 Matlab 代码:
```matlab
clear all;
close all;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = 1024; % 子载波数量
M = 4; % 调制方式
Nsc = 84; % 子载波数量
Np = 4; % 子载波组数
Noma = 2; % NOMA用户数量
Pl = [0.5 0.5]; % NOMA功率分配系数
L = Nsc * Np * Noma; % 总比特数
snr = 0:2:20; % 信噪比范围
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 生成 QPSK 调制的符号集合
QPSK = [-1-1i,-1+1i,1-1i,1+1i]/sqrt(2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 生成随机数据
data = randi([0,1],L,1);
% 生成 QPSK 调制符号
symbo = qammod(data,M);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 信道编码
% interleave
interleaverIndices = reshape(1:L, Nsc, []);
interleavedData = symbo(interleaverIndices);
% DCO-OFDM
% 加载PAM映射表
load('PAM_mapping_7_84.mat');
% 分组
blocks = reshape(interleavedData, Nsc, []);
% PAM 映射
pamMapped = PAM_mapping(blocks,PAM_mapping_table);
% IFFT
ifftOut = ifft(pamMapped, Nsc, 1);
% 循环前缀
CP = ifftOut(end-15:end, :);
ofdmOut = [CP; ifftOut];
% 串并转换
serialOut = ofdmOut(:);
% 光电转换
I = real(serialOut);
Q = imag(serialOut);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NOMA
% 分组
I_blocks = reshape(I, Nsc*Np, []);
Q_blocks = reshape(Q, Nsc*Np, []);
% 矩阵变换
I_new = zeros(Nsc*Np,Noma);
Q_new = zeros(Nsc*Np,Noma);
I_new(:,1) = I_blocks(:,1);
Q_new(:,1) = Q_blocks(:,1);
I_new(:,2) = I_blocks(:,2);
Q_new(:,2) = Q_blocks(:,2);
% NOMA多用户干扰消除
I_Noma = zeros(Nsc*Np,1);
Q_Noma = zeros(Nsc*Np,1);
for i=1:Nsc*Np
I_Noma(i,1) = Pl(1)*I_new(i,1) + Pl(2)*I_new(i,2);
Q_Noma(i,1) = Pl(1)*Q_new(i,1) + Pl(2)*Q_new(i,2);
end
% 串并转换
I_Noma_blocks = reshape(I_Noma, Nsc, Np);
Q_Noma_blocks = reshape(Q_Noma, Nsc, Np);
I_Noma_serialOut = I_Noma_blocks(:);
Q_Noma_serialOut = Q_Noma_blocks(:);
% 光电转换
I_Noma_serialOut = I_Noma_serialOut(:);
Q_Noma_serialOut = Q_Noma_serialOut(:);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% AWGN信道
for i=1:length(snr)
% 信道增益
h = sqrt(0.5)*(randn(1,1)+1i*randn(1,1));
% 加性高斯白噪声
noise = sqrt(0.5/(10^(snr(i)/10)))*(randn(length(serialOut),1)+1i*randn(length(serialOut),1));
% 接收信号
receivedSignal = h*I_Noma_serialOut + noise;
% 光电转换
receivedI = real(receivedSignal);
receivedQ = imag(receivedSignal);
% 串并转换
receivedI_blocks = reshape(receivedI, Nsc, Np);
receivedQ_blocks = reshape(receivedQ, Nsc, Np);
receivedI_ofdmOut = [receivedI_blocks; receivedI_blocks(end-15:end,:)];
receivedQ_ofdmOut = [receivedQ_blocks; receivedQ_blocks(end-15:end,:)];
receivedI_ifftOut = fft(receivedI_ofdmOut, Nsc, 1);
receivedQ_ifftOut = fft(receivedQ_ofdmOut, Nsc, 1);
% PAM解映射
receivedI_index = PAM_demapping(receivedI_ifftOut,PAM_mapping_table);
receivedQ_index = PAM_demapping(receivedQ_ifftOut,PAM_mapping_table);
% 解交织
deinterleavedI = receivedI_index(interleaverIndices);
deinterleavedQ = receivedQ_index(interleaverIndices);
% 解调制
demodulatedI = qamdemod(deinterleavedI,M);
demodulatedQ = qamdemod(deinterleavedQ,M);
% 转回实部和虚部
demodulatedI = real(demodulatedI);
demodulatedQ = real(demodulatedQ);
% 计算误码率
[numErrors(i),ber(i)] = biterr(data,[demodulatedI;demodulatedQ]);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 绘图
semilogy(snr,ber,'-bo','LineWidth',2,'MarkerSize',8);
grid on;
xlabel('SNR(dB)');
ylabel('BER');
title('DCO-OFDM NOMA可见光通信系统误码率仿真');
```
需要注意的是,上述代码中用到了几个辅助函数,需要自行编写或下载相应的实现。具体如下:
1. PAM_mapping.m:用于进行 PAM 映射的函数。
```matlab
function PAM_out = PAM_mapping(PAM_in,PAM_table)
PAM_out = zeros(size(PAM_in));
for i=1:size(PAM_in,2)
PAM_out(:,i) = PAM_table(PAM_in(:,i)+1,i);
end
end
```
2. PAM_demapping.m:用于进行 PAM 解映射的函数。
```matlab
function PAM_out = PAM_demapping(PAM_in,PAM_table)
PAM_out = zeros(size(PAM_in));
for i=1:size(PAM_in,2)
[~,PAM_out(:,i)] = min(abs(PAM_in(:,i)-PAM_table(:,i)),[],1);
PAM_out(:,i) = PAM_out(:,i)-1;
end
end
```
3. PAM_mapping_table.mat:PAM 映射表。可以通过以下代码生成:
```matlab
PAM_table = [-7 -5 -3 -1 1 3 5 7; -3 -1 1 3 -3 -1 1 3];
save('PAM_mapping_table.mat','PAM_table');
```
希望能对您有所帮助!
阅读全文