The generated polynomials are: G () = [1 1 1; 1 0 1] system code.
Method 1:
a= poly2trellis(3, [7 5],7);>> a.nextStatesans = 0 2 2 0 3 1 1 3
Method 2:
function [next_out, next_state, last_out, last_state] = trellis(g)% copyright Nov. 1998 Yufei Wu% MPRG lab, Virginia Tech% for academic use only% set up the trellis given code generator g% g given in binary matrix form. e.g. g = [ 1 1 1; 1 0 1 ];% next_out(i,1:2): trellis next_out (systematic bit; parity bit) when input = 0, state = i; next_out(i,j) = -1 or 1% next_out(i,3:4): trellis next_out (systematic bit; parity bit) when input = 1, state = i;% next_state(i,1): next state when input = 0, state = i; next_state(i,i) = 1,...2^m% next_state(i,2): next state when input = 1, state = i;% last_out(i,1:2): trellis last_out (systematic bit; parity bit) when input = 0, state = i; last_out(i,j) = -1 or 1% last_out(i,3:4): trellis last_out (systematic bit; parity bit) when input = 1, state = i;% last_state(i,1): previous state that comes to state i when info. bit = 0;% last_state(i,2): previous state that comes to state i when info. bit = 1;[n,K] = size(g);m = K - 1;max_state = 2^m;% set up next_out and next_state matrices for systematic codefor state=1:max_state state_vector = bin_state( state-1, m ); % when receive a 0 d_k = 0; a_k = rem( g(1,:)*[0 state_vector]', 2 ); [out_0, state_0] = encode_bit(g, a_k, state_vector); out_0(1) = 0; % when receive a 1 d_k = 1; a_k = rem( g(1,:)*[1 state_vector]', 2 ); [out_1, state_1] = encode_bit(g, a_k, state_vector); out_1(1) = 1; next_out(state,:) = 2*[out_0 out_1]-1; next_state(state,:) = [(int_state(state_0)+1) (int_state(state_1)+1)];end% find out which two previous states can come to present statelast_state = zeros(max_state,2);for bit=0:1 for state=1:max_state last_state(next_state(state,bit+1), bit+1)=state; last_out(next_state(state, bit+1), bit*2+1:bit*2+2) ... = next_out(state, bit*2+1:bit*2+2); end end
g = [ 1 1 1; 1 0 1 ];>> [next_out, next_state, last_out, last_state] = trellis(g)next_out = -1 -1 1 1 -1 -1 1 1 -1 1 1 -1 -1 1 1 -1next_state = 1 3 3 1 4 2 2 4last_out = -1 -1 1 1 -1 1 1 -1 -1 -1 1 1 -1 1 1 -1last_state = 1 2 4 3 2 1 3 4
Method 3:
Function [lstate, nstate, lparoutput] = gen_trellis (g) % generate trellis % output: % lstate -- 2 by X matrix, lstate (linput, cstate) = laststate % -- where linput = 1 (correspond to 0), 2 (correspond to 1) % nstate -- 2 by X matrix, nstate (cinput, cstate) = nextstate % lparoutput -- 2 by X matrix, lparoutput (cinput, cstate) = lastparityoutput forward Output % -- where cinput = 1 (correspond to 0), 2 (correspond to 1) % chenxiao, 2010. 7, seu, E-mail: chenxiao20072008@gmail.com [~, K] = size (g); M = k-1; % determine the memorynstate = zeros (2,2 ^ m); % preallocate for speedlstate = zeros (2,2 ^ m ); % preallocate for speedlparoutput = zeros (^ m); % preallocate for speedfor I = ^ m state_temp = de2bi (I-1, m); % decimal to binary, see Help for details % input 0 state = fliplr (state_temp); % state, corresponding to decimal value 1, 2 ,..., 2 ^ m in = XOR (REM (G (1, 2: End) * State', 2), 0); % input 0 paroutput = REM (G (2, :) * [in State] ', 2); State = [IN, state (m-1)]; nstate_index = bismuth de (fliplr (State) + 1; % See Help for details nstate (1, I) = nstate_index; % Next state lparoutput (1, nstate_index) = 2 x paroutput-1; % last parity output lstate (1, nstate_index) = I; % last State % input 1 State = fliplr (state_temp); In = XOR (REM (G (1, 2: End) * State', 2), 1 ); % input 1 paroutput = REM (G (2, :) * [in State] ', 2); State = [IN, state (m-1)]; nstate_index = bi2de (fliplr (State) + 1; % See Help for details nstate (2, I) = nstate_index; % Next state lparoutput (2, nstate_index) = 2 * paroutput-1; % last parity output lstate (2, nstate_index) = I; % last stateend
>> g = [ 1 1 1; 1 0 1 ];>> [ lstate ,nstate ,lparoutput ] = gen_trellis(g)lstate = 1 4 2 3 2 3 1 4nstate = 1 3 4 2 3 1 2 4lparoutput = -1 1 -1 1 1 -1 1 -1
Supplement:
If G (13, 15) = [1 0 1 1; 1 1 0 1]
Poly2trellis (4, [13 15], 13)
Function [lstate, nstate, lparoutput, nparaout] = gen_trellis (g) % generate trellis % output: % lstate -- 2 by X matrix, lstate (linput, cstate) = laststate % -- where linput = 1 (correspond to 0), 2 (correspond to 1) % nstate -- 2 by X matrix, nstate (cinput, cstate) = nextstate % lparoutput -- 2 by X matrix, lparoutput (cinput, cstate) = lastparityoutput forward Output % -- where cinput = 1 (correspond to 0), 2 (correspond to 1) % chenxia O, 2010.7, seu, email: chenxiao20072008@gmail.com % G = [1 0 1 1; 1 1 0 1]; [~, K] = size (g); M = k-1; % determine the memorynstate = zeros (2,2 ^ m); % preallocate for speedlstate = zeros (2,2 ^ m ); % preallocate for speedlparoutput = zeros (^ m); % preallocate for speedfor I = ^ m state_temp = de2bi (I-1, m); % decimal to binary, see Help for details % input 0 state = fliplr (state_temp); % state, corresponding to decimal value 1, 2 ,..., 2 ^ m in = XOR (REM (G (1, 2: End) * State', 2), 0); % input 0 paroutput = REM (G (2, :) * [in State] ', 2); State = [IN, state (m-1)]; nstate_index = bismuth de (fliplr (State) + 1; % See Help for details nstate (1, I) = nstate_index; % Next state lparoutput (1, nstate_index) = 2 x paroutput-1; % last parity output lstate (1, nstate_index) = I; % last State % input 1 State = fliplr (state_temp); In = XOR (REM (G (1, 2: End) * State', 2), 1 ); % input 1 paroutput = REM (G (2, :) * [in State] ', 2); State = [IN, state (m-1)]; nstate_index = bi2de (fliplr (State) + 1; % See Help for details nstate (2, I) = nstate_index; % Next state lparoutput (2, nstate_index) = 2 * paroutput-1; % last parity output lstate (2, nstate_index) = I; % last stateend % calculate next paraout [M, N] = size (lparoutput); temp = zeros (n, 2 * m); temp (:, 1: 2 * m) = [lstate (1 ,:). 'lparoutput (1 ,:). 'lstate (2 ,:). 'lparoutput (2 ,:). ']; nparaout = zeros (m, n); temp (:,) = sortrows (temp (:,), 1); temp) = sortrows (temp (:, 3: 4), 1); nparaout = [temp (:, 2 ). '; temp (:, 4 ). '];