i need the explanation for the follopwing code for simulation of sc-fdma using qpsk modulation.
Mostrar comentarios más antiguos
clc clear all close all
%% Control Parameters % Number of Bits to be transimitted InputSize = 100; tempIdx = ceil(3*InputSize/16); InputSize = tempIdx*16; % channel type 0-ideal channel and 1 for AWGN channel chlMode = 1;
% Modulation Order % 2- QPSK, 4- 16QAM, 6-64QAM % only QPSK supported in this code ModOrder = 2; % Number of symbols for pusch transmissin nSymbUL = 12; % Number of PRBs allocated numPRBAlloc = 10; % PRB start prbStart = 10; % number of subcarriers per rb numSCPerRB = 12; BER = []; snrCnt = 1; for SNR = 0:5:35
noErrors = 0;
for sysFrmaeNum = 1:100
%%Transmitter
% Digital Random data Generation
InputSequence = randi([0 1],InputSize,1);
%%CRC
% CRC polynomial
gen = crc.generator('Polynomial', '0x8005','ReflectInput', true, 'ReflectRemainder', true);
% CRC Generation
crcEncoded = generate(gen, InputSequence);
%%Convolution Encoder
% Constraint length
Constlength = 7;
% Trellis Structure
trel = poly2trellis(Constlength,[133 171 165]);
% Convolutional Encoder
ConvEncOut = convenc(crcEncoded, trel);
%%Rate Matching
numBitsToTx = numPRBAlloc*nSymbUL*ModOrder*numSCPerRB;
% Repetition factor
repFactor = floor(numBitsToTx/length(ConvEncOut));
% Number of extra bits for padding
numBitsPadding = mod(numBitsToTx,length(ConvEncOut));
% Repetition
repBuff = repmat(ConvEncOut.',1,repFactor);
rateMatchOut = [repBuff repBuff(1:numBitsPadding)]';
%%Block Interleaving
% Write the data in rows first and read out in columns
numColumns = 16;
numRows = ceil(length(rateMatchOut)/numColumns);
% Initialize the Interleaver Buffer
InterleaverOut = zeros(numRows,numColumns);
% find the number of nulls to be added to make the input as divisible of
% number of columns
nNulls = mod(length(rateMatchOut)*numRows, 16);
% Add Null Bits to the input sequence
InterleaverIn = [zeros(1,nNulls); rateMatchOut];
% writing input in rows
Idx = 1;
for rowIdx = 1:numRows
for colIdx = 1:numColumns
InterleaverOut(rowIdx,colIdx) = InterleaverIn(Idx);
% Increment the index
Idx = Idx + 1;
end
end
InterleaverOut = InterleaverOut(:);
%%Scrambler
% PN Sequence generation
h = commsrc.pn('Shift', 0);
set(h, 'NumBitsOut', length(InterleaverOut));
pnSeq = generate(h);
% scrambling
scrOut = mod(InterleaverOut + pnSeq, 2);
%%M-QAM Modulation
% ModIn = bi2de(reshape(scrOut(:),length(scrOut(:))/ModOrder,ModOrder),'left-msb');
ModIn=reshape(scrOut,ModOrder,length(scrOut)/ModOrder)'*[2;1];
load 'QPSKConst.mat'
% LUT based modulation
ModOut = CnstMap(ModIn+1,1);
% ModOut = qammod(ModIn,2^ModOrder)/sqrt(2);
ModOut = reshape(ModOut,numPRBAlloc*numSCPerRB,12);
%%DFT Spreading
dftSpreadOut = fft(ModOut,numPRBAlloc*numSCPerRB);
% Reference signal generation
primeLen = max(primes(numPRBAlloc*numSCPerRB));
m = 0:(numPRBAlloc*numSCPerRB-1);
refSgnlCode = 0.5;
refSgnlGen = exp(1j*pi*refSgnlCode.*m.*(m+1)/primeLen);
%%Resource element mapping
remEleMappOut = zeros(600,14);
remEleMappOut(((prbStart-1)*12+1):((prbStart+numPRBAlloc-1)*12),:) = [dftSpreadOut(:,1:3) refSgnlGen.' dftSpreadOut(:,4:9) refSgnlGen.' dftSpreadOut(:,10:12)];
%%OFDM Processing
ifftOut = ifft(remEleMappOut,1024);
%%CP addition
cpLen = [80 ones(1,6)*72 80 ones(1,6)*72];
ofdmSgnl=[];
for idx = 1:14
ofdmSgnl = [ofdmSgnl ifftOut((1024-cpLen(idx)+1):end,idx).' ifftOut(:,idx).'];
end
%%Channel data
switch chlMode
case 0
channelOut = ofdmSgnl;
case 1
channelOut = awgn(ofdmSgnl,SNR,'measured','dB');
end
% CP Removal
cpLen = [80 ones(1,6)*72 80 ones(1,6)*72];
tempSlot0 = channelOut(1:15360/2);
tempSlot1 = channelOut(15360/2+1:end);
tempSlot0 = tempSlot0(9:end);
tempSlot1 = tempSlot1(9:end);
tempSlot0 = reshape(tempSlot0,1024+72,7);
tempSlot1 = reshape(tempSlot1,1024+72,7);
ofdmRxSgnl = [tempSlot0(73:end,:) tempSlot1(73:end,:)];
%%FFT
fftOut = fft(ofdmRxSgnl);
%%Resource element demapper
remDemappOut = fftOut((prbStart-1)*12+1:((numPRBAlloc+prbStart-1)*12),:);
%%Channel Estimation
% Reference signal generation
primeLen = max(primes(numPRBAlloc*numSCPerRB));
m = 0:(numPRBAlloc*numSCPerRB-1);
refSgnlCode = 0.5;
refSgnlGen = exp(1j*pi*refSgnlCode.*m.*(m+1)/primeLen);
channelEstSlot0 = remDemappOut(:,4)./(refSgnlGen.');
channelEstSlot1 = remDemappOut(:,11)./(refSgnlGen.');
channelEstOut = [repmat(channelEstSlot0,1,6) repmat(channelEstSlot1,1,6)];
%%Channel EQUALIZATION
channelEqlOut = remDemappOut(:,[1:3 5:10 12:14])./channelEstOut;
%%IDFT Despread
idftOut = ifft(channelEqlOut,numPRBAlloc*12);
%%Soft demodulation
[softDemodOut] = SoftDemod(idftOut(:),8);
%%De scrambling
% PN Sequence generation
h = commsrc.pn('Shift', 0);
set(h, 'NumBitsOut', length(InterleaverOut));
pnSeq = generate(h);
% Initialization
deScrOut = zeros(length(softDemodOut),1);
for idx = 1:length(pnSeq)
if(pnSeq(idx) == 1)
deScrOut(idx) = 2^8 - softDemodOut(idx);
else
deScrOut(idx) = softDemodOut(idx);
end
if(deScrOut(idx) < 0)
deScrOut(idx) = 1;
elseif(deScrOut(idx) >= 2^(8))
deScrOut(idx) = 2^(8-1)+60;
end
end
Block Interleaving Write the data in rows first and read out in columns
numColumns = 16;
numRows = ceil(length(deScrOut)/numColumns);
% Initialize the Interleaver Buffer
% deInterleaverOut = zeros(numRows,numColumns);
% find the number of nulls to be added to make the input as divisible of
% number of columns
nNulls = mod(length(deScrOut)*numRows, 16);
% Add Null Bits to the input sequence
deInterleaverIn = [zeros(1,nNulls); deScrOut];
% Re arrange
% deInterleaverIn1 = reshape(deInterleaverIn,numRows,numColumns);
deInterleaverIn = reshape(deInterleaverIn,numRows,numColumns);
% writing input in rows
Idx = 1;
deInterleaverOut = zeros(length(deScrOut),1);
for rowIdx = 1:numRows
for colIdx = 1:numColumns
deInterleaverOut(Idx,1) = deInterleaverIn(rowIdx,colIdx);
% Increment the index
Idx = Idx + 1;
end
end
%%Rate Dematching
vitDecIn = deInterleaverOut(1:length(ConvEncOut));
%%Viterbi Decoder
dec = vitdec(vitDecIn,trel,7,'trunc','soft',8);
%%CRC Detect
det = crc.detector('Polynomial', '0x8005', 'ReflectInput',true, 'ReflectRemainder', true);
[outdata error] = detect(det, dec); % Detect the error
% Number of Errors
noErrors = noErrors + sum(abs(InputSequence-outdata)); % Should be 0
end
BER(snrCnt) = noErrors/(length(outdata)*sysFrmaeNum)
snrCnt = snrCnt + 1;
end
% SNR vs BER Plot
figure(1); semilogy(0:5:35,BER); title('SNR vs BER for QPSK Modulation');
TestEnd = 1;
Respuestas (2)
Val
el 26 de Nov. de 2014
0 votos
Error using load Unable to read file QPSKConst.mat: No such file or directory.
Error in Nice (line 85) load 'QPSKConst.mat'
QPSKConst.mat is missing! Can you upload this file
rissa dolla
el 8 de Abr. de 2016
0 votos
LE CODE Ne s’exécute pas,renvoi nous le bon code si tu la exécuter.
Categorías
Más información sobre Error Detection and Correction en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!