📄 encoder.m
字号:
function [pilot_mapping,data_mapping] = encoder (data_in,codeRS,template,n_mod_type,encode)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %
%% Name: encoder.m %
%% %
%% Description: In this file, all the different stages of %
%% the transmitter is called, which are defined in the r %
%% IEEE802.16-2004 standard. %
%% %
%% Result: It returns the chain of bits, already modulated %
%% in frequency domain, thanks to the IFFT, prepared to be %
%% through the channel. %
%% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BSID = 1; % These three values are for the algorithm of randomization of the data.
DIUC = 7; % They are used to calculate the seed.
Frame = 1;
n_symbol = 1; % At the time of generating the pilots, I need to know what symbol i am simulating
% because the seed to do it depends on it.
Tx = 1; % For some functions, it is necessary to indicate that i am transmitting and not receiving.
if encode
% According to the scheme, i mus introduce the data to transmit by
% diverse phases of encoding. We begin the randomization.
seed = zeros (1,15);
seed=[de2bi(BSID,4,'left-msb') 1 1 de2bi(DIUC,4,'left-msb') 1 de2bi(Frame,4,'left-msb')];
data_random =zeros(1,length(data_in));
for i=1:length(data_in)
next = xor(seed(14),seed(15));
data_random(i) = xor( data_in(i),next);
seed = [next seed(1,1:14)];
end
% Now i encode with Reed-Solomon coding:
m = 8; % Number of bits per symbol
n = codeRS(1); % Length of the codeword
k = codeRS(2); % Number of information symbols
% To realize the Reed-Solomon code, the information is needed in decimal.
data_random = reshape(data_random,8,length(data_random)/8)';
data_random = bi2de(data_random,'left-msb');
% 36 bytes are needed with a stuffed zero at the end of the vector:
yk=[data_random' 0];
% The Galois vector is generated, the generating polynomial of the
% code. Then the symbols are encoded with Reed-Solomon.
msg = gf([yk],m);
if n==k % bypass for BPSK
codeRS = msg;
elseif n~=k
codeRS = rsenc(msg,n,k);
end
data_RS= codeRS.x;
% The binary data to continue working:
data_RS= double (data_RS);
data_RS= de2bi (data_RS,8,'left-msb');
% Serial the data for the next step.
data_RS = reshape (data_RS', 1, length(data_RS)*8);
% Afterwards, the data is sent to th convolutional encoder.
t=poly2trellis(7, [171 133]);
block = length (template); % Length of the template
code_final=[];
% Transmitting --> encode.
code = convenc(data_RS,t);
code_punctured = code;
repeat = length(code)/block; % When the template needs to be applied.
% Depending on the mapping, more or less bits will remain.
% Puncturing is realized.
for i=0:repeat-1
sample = code_punctured (i*block+1:(i+1)*block);
for j=1:block
if template(j)==1
code_final = [code_final sample(j)];
end
end
end
data_convolutional = code_final;
% Finally, we interleave the block:
% The size of the block to use to interleave the sequence is needed.
% This value is taken from table 223 of the standard.
% The value of the used block depends on the mapping that we want.
switch n_mod_type
case 1 % for BPSK
Ncbps=192;
case 2 % for QPSK
Ncbps=384;
case 4 % for 16-QAM
Ncbps=768;
case 6 % for 64-QAM
Ncbps=1152;
end
s=ceil(n_mod_type/2);
% In the following operations, it is necessary to consider the following values:
% k-->index of the bit encoded BEFORE the first permutation
% mk-->index of this bit BEFORE the second permutation and AFTER the first one
% jk-->index after the SECOND permutation, just before the mapping of the sign.
k = 0:Ncbps-1;
mk = ((Ncbps/12)*mod(k,12))+floor(k/12); % First permutation
jk = s*floor(mk/s)+mod(mk+Ncbps-floor(12*mk/Ncbps),s); % Second permutation
% Now I must arrange the indices to know in what order I must take the bits of the entering sequence.
[a c] = sort(jk);
i = 1:Ncbps-1;
data_interleaved = zeros(1,Ncbps);
data_interleaved(i) = data_convolutional(c(i));
else
data_interleaved = data_in;
end
% Once the encoding is done, the data is mapped following the constellation
% in which we are working.
data_mapping = mappingTX (data_interleaved, n_mod_type);
% Before the OFDM symbol is created, the pilot carriers must be inserted,
% which help with channel estimation.
% The values of the pilots are to be modulated on to the carriers. These
% are defined in the standard as such(pp 443) :
% Before beginning, it is necessary to consider that the value to calculate
% depends on 2 factors : the number of symbols and whether we are in the
% uplink or dwnlink. We will consider that we are in the downlink and we
% are transmitting the symbol "1". If we want to consider the other
% connection, the seed would be "10101010101".
seed = [1 1 1 1 1 1 1 1 1 1 1];
for i=1:n_symbol+2
wk(i) = seed (11);
next = xor(seed(9),seed(11));
seed = [next seed(1,1:10)];
end
% Once the value of wk is found(that depends on the number of symbol with
% wihich it is working), the values of the subcarriers must be found and of
% the mapping of them with BPSK constellation.
wk = wk(n_symbol+2);
A = 1 - wk; % Values defined in the standard.
B = 1 - (~wk);
value_carrier = [A B A B B B A A];
% For uplink, the values should be [A B A B A A A A]
pilot_mapping = 2*mappingTX(value_carrier,1);
% The factor of "2" is due to the fact that the pilots are transmitted to a
% double power of the information bits.
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -