?? trellis.m
字號:
function [next_out, next_state, last_out, last_state] = trellis(g)% copyright Nov. 1998 Yufei Wu% MPRG lab, Virginia Tech% for academic use only% ########################################% !Note: Modified By YuHua Xing, Seu, 2005% Orignal program compute systematic code trellis, now modify it to compute% non-systematic convolutional code trellis% set up the trellis given code generator g% g given in binary matrix form. e.g. g = [ 1 1 1 1 0 0 1;1 0 1 1 0 1 1 ];% next_out(i,1:2): trellis next_out (parity bit x, parity bit y) when input = 0, state = i; next_out(i,j) = 0 or 1% next_out(i,3:4): trellis next_out (parity bit x, parity bit y) when input = 1, state = i;% next_state(i,1): next state when input = 0, state = i; next_state(i,i) = 0,...2^m-1% next_state(i,2): next state when input = 1, state = i;% last_out(i,1:2): trellis last_out (parity bit x, parity bit y) when input = 0, state = i; last_out(i,j) = 0 or 1% last_out(i,3:4): trellis last_out (parity bit x, parity bit y) 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;% !!Note: State belong to [1 ... 2^m], and parity output belong to [0, 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 = de2bi( state-1, m , 'left-msb'); % when receive a 0 d_k = 0; [out_0, state_0] = encode_bit(g, d_k, state_vector); % when receive a 1 d_k = 1; [out_1, state_1] = encode_bit(g, d_k, state_vector); next_out(state,:) = [out_0 out_1]; next_state(state,:) = [bi2de(state_0,'left-msb'),bi2de(state_1,'left-msb')];end% find out which two previous states can come to present statelast_state = zeros(max_state,2);last_out = zeros(max_state,4);for state=0:max_state-1 if state<32, % state(<32) exist only when last input is 0 last_state(state+1,:)=[2*state,2*state+1]; last_out(state+1, 1:2)=next_out(2*state+1, 1:2); last_out(state+1, 3:4)=next_out(2*state+2, 1:2); else % state(>=32) exist only when last input is 1 last_state(state+1,:)=[2*(state-32),2*(state-32)+1]; last_out(state+1, 1:2)=next_out(2*(state-32)+1, 3:4); last_out(state+1, 3:4)=next_out(2*(state-32)+2, 3:4); endendnext_state=next_state+1;last_state=last_state+1;% savesave next_out.mat next_out;save next_state.mat next_state;save last_out.mat last_out;save last_state.mat last_state;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -