%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  FileName:            mfTxTrchCoder.m
%  Description:         传输信道编码器
%  Reference:           3GPP TS 25.212, 4.2.3 Channel coding
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Parameter List:       
%       Output Parameter
%           out_data	输出经过信道编码后的数据 
%       Input Parameter
%           input_data	输入待编码的数据
%           input_num	输入数据比特数
%           coder_type  编码器类型，0表示不编码，1表示1/2卷积码，2表示1/3卷积码
%                       3表示Turbo码              
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  History
%    1. Date:           2017-12-1
%       Author:         david.lee
%       Version:        1.0 
%       Modification:   初稿
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [out_data] = mfTxTrchCoder(input_data, input_num, coder_type)

%% 功能实现
switch coder_type
	case 0
        out_data = zeros(1, input_num);     %#ok
        out_data = input_data;
    % 1/2卷积
    case 1
        %添加尾比特（在输入数据后添加8个0）
        temp_data = zeros(1, input_num+8);
        temp_data(1,1:input_num) = input_data;
        input_num = input_num+8;
        %卷积编码
        out_data = zeros(1, input_num*2);     %#ok
        CodeGenerator = [561, 753];
        K = 9;
        trellis = poly2trellis(K, CodeGenerator);
        out_data = convenc(temp_data, trellis);  
    % 1/3卷积
    case 2
        %添加尾比特（在输入数据后添加8个0）
        temp_data = zeros(1, input_num+8);
        temp_data(1,1:input_num) = input_data;
        input_num = input_num+8;
        %卷积编码
        out_data = zeros(1, input_num*3);     %#ok
        CodeGenerator = [557, 663, 711];
        K = 9;
        trellis = poly2trellis(K, CodeGenerator);
        out_data = convenc(temp_data, trellis);  
    case 3
        fprintf('error:函数mfTxTrchCoder的参数coder_type=3暂不支持\n');
    otherwise
        fprintf('error:函数mfTxTrchCoder的参数coder_type输入错误\n');
end    

end