function [size, crc, chCode, C, control] = dl_start(nCode, c_type, Kindex, nFrames,tx_ch)
%
%
% FUNCTION: dl_start
% AUTHOR: Maarit Melvasalo
% DATE: April 21, 1999
%
% DESC: This fuction set values for downlink transport channels
% defined in Simulink library: utra_lib
% These values have been obtained from ETSI UTRA
% for ITU-R RTT.
%
% NOTE: Parameter value may be changed, but be carefully!
% Do not change the calcutions.
%
% HISTORY: June 17,1999 Maarit Melvasalo
% Comments added
% Copyright disclaimer:
% This software was developed at the National Institute of Standards
% and Technology by employees of the Federal Government in the course
% of their official duties. Pursuant to title 17 Section 105 of the
% United States Code this software is not subject to copyright
% protection and is in the public domain.
%
% We would appreciate acknowledgement if the software is used.
%
% *******************************************************************
%
% INPUTS:
%
% nCode =[code_length, index ] =
% spreading factor and index (NOTE index is not required!!)
% If the code has been pre set i.e nCode = C, nothing is done
% c_type = mode indicating the channel coding scheme
% 1 = Convolutional coding with
% 3 = Turbo coding (NOT YET)
% K_index = Coding ratio (input values: (1,2)
% nFrames = number of frames in each block interleaver
% tx_ch = transport channel type
% 1 = Dedicated transport channel
% 2 = Primarly common control physical cahnnel (NO CRC)
% 3 = Secondary common control physical channel (FACH or PCH)
%
% OUTPUTS:
%
% size = [N = input_block_size bits_in_frame nFrames N_offset nSlot]
% input_block_size= number of bits in each input block (calculated)
% bits_in_frame = number of coded bits in frame (calculated)
% Note that this does not include contorl bits
% nFrames = number of frames in each block (calculated)
% N_offset = offset required to obtain correct blocksize (calculated)
% after channel coding (and before interleaving)
% nSlot = number of slots in frame (set by user)
% chips_in_slot = number of slots in frame (constant for given bit bandwidth)
%
% crc = [nCRC poly]
% nCRC = number of CRC bits (set by user) different for different
% physical channels
% poly = generating polynomial for CRC (set by user)
%
% chCode = [c_type K tail poly]
% c_type = channel type (given in function call = set by user)
% K = Coding gain (given in function call = set by user)
% tail = Coding tail length (set by user)
% poly = Generating polynomials for channel coding (set by user)
%
% C = spreading code
% spreading code depends on given parameters (calculated / given by user)
%
% control = [nPilot TPC TFI]
% nPilot = number of Pilot bits (given by user)
% TPC = number of Power control bits (given by user)
% TFI = number of Transport Format Indicator bits (given by user)
%
%
%
%
% ***************************************************************
%
% Common parameters to all Downlink transport channels
%
% ***************************************************************
R = 4096000; % chips rate 1/s
nSlot = 16; % Number of slots per frame same as
% wcdma_config.h = SLOTS_IN_FRAME
tFrame = 1/100; % 10 ms = frame time
% Simulink s-functions use TD_FRAME = 1
% defined in wcdma_config.h
chips_in_slot = R/nSlot*tFrame;
% Number of chips in each slot (constant)
% ***************************************************************
% If only only one argument is given at the function call
% only the basic parameters are returned to the user
if(nargin == 1)
size = [nSlot,chips_in_slot];
crc =0;
C = 0;
chCode = 0;
control =0;
return
end;
% ***************************************************************
%
% CRC Basic settings
%
% ***************************************************************
nCRC = 16 ; % Number of CRC bits;
crc_q = '1021'; % ARIB in decimal presentation 4129
CRCQ = base2dec(crc_q,16); % same in decimal representation
crc = [nCRC CRCQ];
% ***************************************************************
%
% CONVOLUTIONAL CODING PARAMETERS
%
% ***************************************************************
if (c_type == 1)
% CODING RATIO
% Kindex == 1 -> K = 2;
% Kindex == 2 -> K = 3;
K = Kindex + 1 ; tail = 8;
%*****************************************
% The Generator polynomials for convolutional coding and decoding
% see UTRA specification chapter 5.2.1.1.1
Base = 8; % indicates the base in which the numbers are given/**/
if (K == 3)
p1_o = '557'; % desimal: 367;
p2_o = '663'; % desimal: 435;
p3_o = '711'; % desimal: 457;
else
p1_o = '561'; % desimal: 367;
p2_o = '753'; % desimal: 435;
p3_o = '0'; % desimal: N/A;
end;
poly = [base2dec(p1_o,Base) base2dec(p2_o,Base) base2dec(p3_o,Base)];
% ***************************************************************
%
% NUMBER OF CONTROL BITS
%
% ***************************************************************
nPilot = 8; TPC = 3; TFI = 2;
% If not Dedicated transport channel update the following parameters:
if(tx_ch == 3)
TPC = 0; TFI = 0; % Secondary common control
end;
if (tx_ch == 2)
TPC = 0; TFI = 0; nCRC = 0; % Primary common control
crc = [nCRC CRCQ];
if (nCode(1) < 256)
disp('Only Spreading ratio 256 allowed for Primary common control channel');
nCode(1)=256;
end;
end;
% ***************************************************************
% Update return values
chCode = [c_type K tail poly];
control = [nPilot TPC TFI];
% ***************************************************************
%
% SPREADING CODE
%
% ***************************************************************
% if the spreading code has not been assigned
if ( length(nCode) < 3)
% set the code index for a inital value
index = nCode(1) / 2 ;
% If the code index has been defined by the use
% in thefunction call check that is valid index
if ((length(nCode) == 2) & ((index <= nCode) & (index >0) ))
index = nCode(2); end;
% Call a matalb mex function which returns the code
C = get_ovsf_code(nCode(1),index);
end;
if ( length(nCode) > 2) % if the spreading code has already been assigned
C = nCode;
nCode = length(C);
end;
% ***************************************************************
%
% NUMBER OF BITS IN BLOCK, FRAME AND SLOT ETC
%
% DO NOT CHANGE!!!!!!!!
%
% ***************************************************************
total_bits = R/nCode(1) * 2 ;
bits_in_slot = total_bits * tFrame / nSlot ;
coded_bits_frame = (bits_in_slot - nPilot -TPC - TFI) * nSlot ;
% NOTE:
% Size of the inputblock to CRC must be * 8
N_total = nFrames * coded_bits_frame - tail ;
N_tmp = floor(N_total / K);
if( nCRC > 0)
N_tmp = 8 * floor(N_tmp / 8) ;
end;
N = N_tmp - nCRC ;
N_offset = N_total - N_tmp*K;
size =[N coded_bits_frame nFrames