随机交织的代码
clc;
clear all
frmLen = 1000;
intrlvrIndices = randperm(frmLen);
frmNum=1000;
SNR1=-5:0.25:-3;
K=0;
for Snr=-5:0.25:-3
K=K+1;
noiseVar=0.510^(-0.1Snr);
hTEnc = comm.TurboEncoder('TrellisStructure', poly2trellis(4, ...
[13 15], 13), 'InterleaverIndices', intrlvrIndices);
hMod = comm.BPSKModulator;
hChan = comm.AWGNChannel('EbNo', Snr,'BitsPerSymbol', 1);
hTDec = comm.TurboDecoder('TrellisStructure', poly2trellis(4, ...
[13 15], 13), 'InterleaverIndices', intrlvrIndices, ...
'NumIterations', 5);
for frmIdx = 1:frmNum
data = randi([0 1], frmLen, 1);
encodedData = step(hTEnc, data);
modSignal = step(hMod, encodedData);
receivedSignal = step(hChan, modSignal);
receivedBits = step(hTDec, (-2/(noiseVar/2))*real(receivedSignal));
err(frmIdx)=length(find(data~=receivedBits))/(frmLen);
end
Err1(K)=mean(err);
end
figure
semilogy(SNR1,Err1,'-ko')
grid on
ylabel('BER')
xlabel('信噪比 SNR(dB)')
title('随机交织')
figure
plot(intrlvrIndices,'o')
xlabel('原始位置')
ylabel('随机交织位置')