function [coding] = BCC_params(wifi_params, m_stbc, i_mcs)
% Function for computing convolutional coding parameters
% Author: Jiri Milos

coding.type = 'BCC';

LENGTH = wifi_params.general.LENGTH;
service_length = wifi_params.mapping.service_length;

MCS = wifi_params.MCS(i_mcs);

%coding.N_sym = m_stbc*ceil((8*LENGTH+service_length+6*MCS.N_es)/(m_stbc*MCS.N_dbps*MCS.N_ss));
coding.N_sym = m_stbc*ceil((8*LENGTH+service_length+6*MCS.N_es)/(m_stbc*MCS.N_dbps));

%Edited - added *MCS.N_ss -J146
%coding.N_sym = m_stbc*ceil(((8*LENGTH+service_length)*wifi_params.general.n_users(1,2)+6*MCS.N_es)/(m_stbc*MCS.N_dbps));
coding.N_pad_bits = coding.N_sym*MCS.N_dbps-(8*LENGTH)-service_length-(6*MCS.N_es);

coding.K = 7;
coding.trellis = poly2trellis(7,[133, 171]);
coding.tail_length = 6;
% set puncturing patterns '0' signify punctured bit
coding.puncturing(1).CRstr = '1/2';
coding.puncturing(1).CR = 1/2;
coding.puncturing(1).pattern = [1 1];

coding.puncturing(2).CRstr = '2/3';
coding.puncturing(2).CR = 2/3;
coding.puncturing(2).pattern = [1 1 1 0];

coding.puncturing(3).CRstr = '3/4';
coding.puncturing(3).CR = 3/4;
coding.puncturing(3).pattern = [1 1 1 0 0 1];

coding.puncturing(4).CRstr = '5/6';
coding.puncturing(4).CR = 5/6;
coding.puncturing(4).pattern = [1 1 1 0 0 1 1 0 0 1];

% %% PSDU_tx right lenght test and add more pad bits if needed
% rand_tx = 8*LENGTH;
% PSDU_test = rand_tx;
% while ((any(rem(PSDU_test,3))~=0) | (any(rem(PSDU_test,MCS.N_cbps)) ~= 0))
%     OneStream = (2*rem(MCS.N_ss,2))*abs(fix(MCS.N_ss/2)-1);
%     rand_tx = rand_tx + 1;
%     PSDU_test = (2*(rand_tx + coding.N_pad_bits + service_length + coding.tail_length + OneStream))/MCS.N_ss;
%     coding.N_pad_bits = coding.N_pad_bits + 1;
% end

end

