⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decoder.m

📁 802.16 physical layer simulation through diferent SUI Channel.
💻 M
字号:
function [symbolRx,hHat] = decoder (pilots_tx,data_tx,symbol_channel_rx,n_mod_type,codeRS,template,snr,encode,bits_ofdm,channel,SUI);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                       %
%%     Name: decoder.m                                                   %
%%                                                                       %
%%     Description: In this file, the different stages of the WiMAX      %
%%      Receiver are called to undo all the stages realized in the       %
%%      transmitter.(Encoding, Interleaving, Randomization)              %
%%                                                                       %
%%                                                                       %
%%      Parameters: All the parameters that have comprised the           %
%%       transmitter : used modulation, Reed Solomon code, template      %
%%       of puncturing, the SNR, size of the Cyclic Prefix and the       %
%%       Received symbol.                                                %
%%                                                                       %
%%      Result: It gives back the chain of bits corresponding to the     %
%%       sent data.                                                      %
%%                                                                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Parameters that have not been introduced in the call of the function.
  
 BSID = 1;            % These three values comprise the algorithm of the  
 DIUC = 7;            % randomization of data. The are used to calculate
 Frame = 1;           % the seed.
 
 Tx = 0;              % Indicate that we are not transmitting.

% Here the position of the pilots are indicated, since i need to know where
% they are to be able to estimate the channel.

 v_pilots = [41 66 91 116 142 167 192 217]; 
 
% After getting the received symbol, the channel is to be estimated using
% the pilot carriers. This is bypassed for an AWGN channel.

if SUI == 0
    estimate_rx = symbol_channel_rx;
elseif SUI ~= 0
       % ---> pilots_rx =symbol_rx(v_pilots);%%%%%%%%%%%%%%%%%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       % In this case, we calculate the frequency response of each component of the channel.
       v_estimate = fft(channel,256);
       v_estimate = conj(v_estimate');
       % We undo what the channel has done to each of the samples in the symbol.
       estimate_rx = symbol_channel_rx ./ v_estimate;
end









% We have already secured the OFDM symbol in the frequency domain. Now
% we must properly extract the data of this symbol.
% First, the position of the data is located 
 v_data = setxor(1:length(estimate_rx),v_pilots);
 
% Next, the values of the data and pilot carriers are extracted
 data_total = estimate_rx(v_data);
  
% Now the dc carrier must be removed
 data_mapped_rx = [data_total(29:124) data_total(126:221)];
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
% Once the sent bits have been extracted and the channel has been
% estimated, the inverse process for the encoding must be done. In the
% first place, we have to demap the signal.

 data_interleaved_rx = mappingRX(data_mapped_rx,n_mod_type);

 
 
 
 
 
 
 
 
 
 
 
 
 if encode
     % If we have encoded the data, it must be sent to the convolutional
     % decoder after being de-interleaved. First we De-interleave.
    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);
    j = 0:Ncbps-1;
    mj = s*floor(j/s) + mod((j + floor(12*j/Ncbps)),s);          % First permutation
    kj = 12*mj-(Ncbps-1)*floor(12*mj/Ncbps);                     % Second permutation
    % The indices are ordered to know what must be taken.
    [a c]= sort(kj);
    i = 1:Ncbps-1;
    data_convolutional_rx = zeros(1,Ncbps);
    data_convolutional_rx(i) = data_interleaved_rx(c(i));
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     % Now the data is sent to the convolutional decoder.
t=poly2trellis(7, [171 133]);
block = length (template);               % Length of the template
code_final=[];
repeat= length(data_convolutional_rx)/sum(template);  % Times the process needs to be repeated.
lengtht = sum(template);
% Transmitting +1 and -1 to know what bits ahve been cleared.
code = -2*data_convolutional_rx +1; 
% Must fill up the zeros and realize the inverse of puncturing.
for i=0:repeat-1
    sample = code (i*lengtht+1:(i+1)*lengtht);
    k=1;
    for j=1:block            
        if template(j)==1
           code_final = [code_final sample(k)]; 
           k = k+1;
         elseif template(j)==0
                code_final = [code_final 0];
        end
    end
end
tb = 105;
if length(code_final) == 192         % for BPSK
   data_RS_rx = vitdec (code_final,t,96,'trunc','unquant');
elseif length(code_final) ~= 192
       data_RS_rx = vitdec (code_final,t,tb,'trunc','unquant'); 
end



     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     % Now the data is sent to the ReedSolomon decoder.

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_RS_rx = reshape(data_RS_rx,8,length(data_RS_rx)/8)';
data_RS_rx = bi2de(data_RS_rx,'left-msb');
yk = data_RS_rx;            % In the receiver, nothing needs to be completed.
msg = gf([yk],m);           % In this case, the encoding is undone.
if n==k
   codeRS = yk;
elseif n~=k
   codeRS = rsdec(msg',n,k);
   codeRS = codeRS.x;
end
data_random_rx = codeRS(1:end-1);
% The binary data to continue working:
data_random_rx = double (data_random_rx);
data_random_rx = de2bi (data_random_rx,8,'left-msb');
% Serial the data for the next step.
data_random_rx = reshape (data_random_rx', 1, length(data_random_rx)*8);

 
 
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     % The data was first randomized, so now finally we have to
     % de-randomize the data to get the received signal.

seed = zeros (1,15);
seed=[de2bi(BSID,4,'left-msb') 1 1 de2bi(DIUC,4,'left-msb') 1 de2bi(Frame,4,'left-msb')];

symbolRx=zeros(1,length(data_random_rx));

for i=1:length(data_random_rx)
    next = xor(seed(14),seed(15));
    symbolRx(i) = xor( data_random_rx(i),next);
    seed = [next seed(1,1:14)];
end

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
 else
     % If the data was not encoded, it will be enough to only de-interleave
     % the signal.

     symbolRx = data_interleaved_rx;
          
 end

 return;
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -