递归系统卷积码的状态转移

来源:互联网 发布:淘宝店铺介绍范文 编辑:程序博客网 时间:2024/05/22 01:27

令 生成多项式为:G(7,5)=[1 1 1;1 0 1]    注意是系统码   

第一种方法:

a= poly2trellis(3, [7 5],7);>> a.nextStatesans =     0     2     2     0     3     1     1     3


第二种方法:

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

第三种方法:


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   前向的输出%             --where cinput=1(correspond to 0), 2(correspond to 1)%% chenxiao, 2010.7, SEU, Email: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(2,2^m); % preallocate for speedfor i=1:2^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(1:m-1)];    nstate_index=bi2de(fliplr(state))+1; % see help for details    nstate(1,i)=nstate_index; % next state    lparoutput(1,nstate_index)=2*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(1: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


补充:

如果 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   前向的输出%             --where cinput=1(correspond to 0), 2(correspond to 1)%% chenxiao, 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(2,2^m); % preallocate for speedfor i=1:2^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(1:m-1)];    nstate_index=bi2de(fliplr(state))+1; % see help for details    nstate(1,i)=nstate_index; % next state    lparoutput(1,nstate_index)=2*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(1: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%以下为计算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(:,1:2 ) = sortrows(temp(:,1:2),1) ;temp(:,3:4 ) = sortrows(temp(:,3:4),1) ;nparaout = [temp(:,2).' ; temp(:,4).' ]  ;


原创粉丝点击