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

📄 f_cc_encoder_tailbiting.m

📁 CC编码的matlab实现
💻 M
字号:
function [output_bits] = f_cc_encoder_tailbiting(input_bits,encoder_rate_num)
% Encodes input_bits with a constraint length 7, rate 1/2, 2/3,
%   3/4, or 5/6 encoder as specified in section 8.4.9.2.1 of 802.16e
%
% input_bits
%       Row vector with one bit per element of value 0
%       or 1.  Length must be a multiple of 8.  
% encoder_rate_num
%      Numerator of encoder rate:  1 for rate 1/2, 2 for rate 2/3,
%       3 for rate 3/4, 5 for rate 5/6.
% output_bits
%      Output of the encoder.  Row vector of length
%       (length(input_data)/rate) with 1 bit per element of value 0 
%       or 1. 
%
%     References
%       [1] IEEE P802.16e
%

% Check if correct number of input arguments
error(nargchk(2,2,nargin));

% Set generator polynomials
g1 = [1  1 1 1  0 0 1];
g2 = [1  0 1 1  0 1 1];

% constraint length
K = length(g1);

% Make sure input_data is an integer number of bytes
% and a multiple of the code rate numerator.
num_input_bits = length(input_bits);
if (mod(num_input_bits, 8) ~= 0)
    error('Number of input bits must be multiple of 8');
end;
if (mod(num_input_bits, encoder_rate_num) ~= 0)
    error('Number of input bits must be multiple of encoder_rate_num');
end;

% Since this is a tail biting code, the input state will be equal
% to the last part of the input bits.
input_state = input_bits((num_input_bits-K+2) : end);

% Concatenate state and input
input = [input_state input_bits];

% Apply the generator polynomials
% Only include the parts where the state registers are completely
% filled (i.e., skip the beginning and the end of the convolution).
parityX = mod(conv(input, g1), 2);
parityX = parityX(K : (K+num_input_bits-1));

parityY = mod(conv(input, g2), 2);
parityY = parityY(K : (K+num_input_bits-1));

% Number of output bits
num_output_bits = num_input_bits * (encoder_rate_num+1) / encoder_rate_num;

% Apply the different puncturing patterns
switch(encoder_rate_num)
    case 1
        tmp_matrix = [parityX; parityY];
        output_bits = reshape(tmp_matrix, 1, num_output_bits);
    case 2
        tmp_matrix = [parityX(1:2:end); parityY(1:2:end); parityY(2:2:end)];
        output_bits = reshape(tmp_matrix, 1, num_output_bits);
    case 3
        tmp_matrix = [parityX(1:3:end); parityY(1:3:end); parityY(2:3:end); parityX(3:3:end)];
        output_bits = reshape(tmp_matrix, 1, num_output_bits);
    case 5
        tmp_matrix = [parityX(1:5:end); parityY(1:5:end); parityY(2:5:end);...
                      parityX(3:5:end); parityY(4:5:end); parityX(5:5:end)];
        output_bits = reshape(tmp_matrix, 1, num_output_bits);
    otherwise
        error('encoder_rate_num must be 1,2,3,or 5');
end;
 

⌨️ 快捷键说明

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