MIMO DCO-OFDM在可见光通信系统中的误码率仿真matlab代码、
时间: 2024-02-03 20:14:20 浏览: 169
以下是MIMO DCO-OFDM在可见光通信系统中的误码率仿真matlab代码:
```matlab
clear all;
close all;
clc;
%% Parameters
N = 64; % FFT size
CP = 16; % Cyclic Prefix
M = 4; % Modulation order
L = 4; % Number of LEDs
nTx = 2; % Number of transmitters
nRx = 2; % Number of receivers
snr = 0:2:20; % Signal to noise ratio
numIter = 10^3; % Number of iterations
ber = zeros(length(snr), 1); % Bit error rate
%% Channel matrix for MIMO
H = (randn(nRx, nTx, L)+1i*randn(nRx, nTx, L))/sqrt(2);
%% LED positions
ledPos = [0 0; 0 1; 1 0; 1 1];
%% Generate random bit stream
txBits = randi([0 1], nTx*N*log2(M), 1);
%% Modulation
txMod = qammod(txBits, M);
%% Serial to Parallel
txS2P = reshape(txMod, [], nTx);
%% OFDM
txOFDM = ifft(txS2P, N, 2);
%% Add Cyclic Prefix
txCP = [txOFDM(:, end-CP+1:end) txOFDM];
%% Parallel to Serial
txP2S = reshape(txCP, [], 1);
%% LED intensity levels
ledInt = sqrt(mean(abs(txP2S).^2));
%% LED positions
ledPos = [0 0; 0 1; 1 0; 1 1];
%% Channel matrix for MIMO
H = (randn(nRx, nTx, L)+1i*randn(nRx, nTx, L))/sqrt(2);
%% Channel matrix for VLC
Hv = zeros(nRx, L);
for i=1:nRx
for j=1:L
Hv(i,j) = sqrt(sum((ledPos(j,:)-[i-1,0]).^2))^(-3/2);
end
end
%% Transmit through VLC channel
rxVLC = Hv*diag(ledInt)*txP2S;
%% Receive through MIMO channel
rxMIMO = zeros(N+CP, nRx);
for i=1:L
rxMIMO(:,i) = awgn(H(:,:,i)*rxVLC(:,i), snr(1), 'measured');
end
%% Remove cyclic prefix
rxNoCP = rxMIMO(CP+1:end,:);
%% FFT
rxFFT = fft(rxNoCP, N, 1);
%% Parallel to serial
rxP2S = reshape(rxFFT, [], 1);
%% Demodulation
rxDemod = qamdemod(rxP2S, M);
%% Calculate BER
ber(1) = sum(xor(rxDemod, txBits))/length(txBits);
%% Repeat for different SNR values
for i=2:length(snr)
for j=1:numIter
%% Generate random bit stream
txBits = randi([0 1], nTx*N*log2(M), 1);
%% Modulation
txMod = qammod(txBits, M);
%% Serial to Parallel
txS2P = reshape(txMod, [], nTx);
%% OFDM
txOFDM = ifft(txS2P, N, 2);
%% Add Cyclic Prefix
txCP = [txOFDM(:, end-CP+1:end) txOFDM];
%% Parallel to Serial
txP2S = reshape(txCP, [], 1);
%% LED intensity levels
ledInt = sqrt(mean(abs(txP2S).^2));
%% Transmit through VLC channel
rxVLC = Hv*diag(ledInt)*txP2S;
%% Receive through MIMO channel
rxMIMO = zeros(N+CP, nRx);
for k=1:L
rxMIMO(:,k) = awgn(H(:,:,k)*rxVLC(:,k), snr(i), 'measured');
end
%% Remove cyclic prefix
rxNoCP = rxMIMO(CP+1:end,:);
%% FFT
rxFFT = fft(rxNoCP, N, 1);
%% Parallel to serial
rxP2S = reshape(rxFFT, [], 1);
%% Demodulation
rxDemod = qamdemod(rxP2S, M);
%% Calculate BER
ber(i) = ber(i) + sum(xor(rxDemod, txBits))/length(txBits);
end
ber(i) = ber(i)/numIter;
end
%% Plot BER vs SNR
figure;
semilogy(snr, ber, 'b-o');
xlabel('SNR (dB)');
ylabel('BER');
title('MIMO DCO-OFDM in VLC System');
grid on;
```