这次是一个用代码实现的Li-Fi模拟
Li-Fi是一个非常有意思的概念,虽然Li-Fi的未来并不是很明显,而且在我看没有什么应用价值。把Li-Fi应用在公共环境更是无稽之谈。但是模拟一下还是挺有意思的。
本质上和之前写的WLAN模拟十分相似
参数就随便设置了,这里直接贴上模拟的代码
同样是使用For循环来做
for sim_index = 1:Len
Psn = snrVec(sim_index);
snr = 10^(Psn/10);
A_PPM = sqrt(snr*2);
for loops = 1:IterNum
Source = randi([0,1],1,BitNum);
codec_out = convenc(Source,Trellis);
% OOK modulation
Sym_OOK = codec_out;
% waveform shaping
Tx_OOK = WaveForm(Sym_OOK,SamplePerSym*SymbolNum*2);
% get the oversample factor
n_PPM = length(Tx_OOK)/length(Sym_OOK);
% additive noise channel 这里添加一些干扰控制
noise = randn(1,length(Tx_OOK));
Rec_OOK = A_PPM*Tx_OOK + noise(1:length(Tx_OOK));
% decision
Dec_OOK = Hard_Decision(Rec_OOK,n_PPM,Threshold);
% decode
Sink_OOK = VLC_Decode('OOK',Dec_OOK,1);
% decoder
DecoderOut = vitdec(Sink_OOK,Trellis,TraceLen,'trunc','hard');
% ber for PPM
[~,ber] = biterr(DecoderOut,Source);
BER(1,sim_index) = BER(1,sim_index) + ber;
% PER
if(ber)
PER(1,sim_index) = PER(1,sim_index) + 1;
end
end % loop for iteration
end % loop for Psn
里面还应用了一些自己写的函数,就不贴上了,没什么必要