No BSD License  

Highlights from
Home Networking Basis

Home Networking Basis

by

 

11 Aug 2003 (Updated )

M-files for chapters 2-10 and Simulink models for Ethernet and Wireless Ethernet.

vdecoder.m
%Generating a look up table
for i=1:64
    bn=dec2bin(i-1,6);
    zb(2:6)=bn(1:5);
    zb(1)='0';
    ob(2:6)=bn(1:5);
    ob(1)='1';
    for j=1:6
        bnd(j)=bin2dec(bn(j));
    end
    obd=1;
    zb1=xor(xor(bnd(1),xor(bnd(2),bnd(3))),bnd(6));
    zb2=xor(xor(bnd(2),xor(bnd(3),bnd(5))),bnd(6));
    tbl(1,i)=zb1*2+zb2;
    tbl(2,i)=bin2dec(zb);
    ob1=xor(xor(xor(obd,bnd(1)),xor(bnd(2),bnd(3))),bnd(6));
    ob2=xor(xor(xor(obd,bnd(2)),xor(bnd(3),bnd(5))),bnd(6));
    tbl(3,i)=ob1*2+ob2;
    tbl(4,i)=bin2dec(ob);
end
%Decoding
psta=zeros(1,4);
psum=zeros(1,4);
blenth=2;
%Start with zero state to form 4 paths
%First stage
in1=xy(1);
in2=xy(2);
zout=tbl(1,1);
znxtst=tbl(2,1);
oout=tbl(3,1);
onxtst=tbl(4,1);
zoutb=dec2bin(zout,2);
zout1=bin2dec(zoutb(1));
zout2=bin2dec(zoutb(2));
ooutb=dec2bin(oout,2);
oout1=bin2dec(ooutb(1));
oout2=bin2dec(ooutb(2));
weiz=xor(zout1,in1)+xor(zout2,in2);
weio=xor(oout1,in1)+xor(oout2,in2);
psta(1)=znxtst;
psta(2)=znxtst;
psta(3)=onxtst;
psta(4)=onxtst;
psum(1)=weiz;
psum(2)=weiz;
psum(3)=weio;
psum(4)=weio;
pbits(1,1)=0;
pbits(1,2)=0;
pbits(1,3)=1;
pbits(1,4)=1;
%Second stage
in1=xy(3);
in2=xy(4);
zout=tbl(1,psta(1)+1);
znxtst=tbl(2,psta(1)+1);
oout=tbl(3,psta(1)+1);
onxtst=tbl(4,psta(1)+1);
zoutb=dec2bin(zout,2);
zout1=bin2dec(zoutb(1));
zout2=bin2dec(zoutb(2));
ooutb=dec2bin(oout,2);
oout1=bin2dec(ooutb(1));
oout2=bin2dec(ooutb(2));
weiz=xor(zout1,in1)+xor(zout2,in2);
weio=xor(oout1,in1)+xor(oout2,in2);
psta(1)=znxtst;
psta(2)=onxtst;
psum(1)=psum(1)+weiz;
psum(2)=psum(2)+weio;
pbits(2,1)=0;
pbits(2,2)=1;
zout=tbl(1,psta(3)+1);
znxtst=tbl(2,psta(3)+1);
oout=tbl(3,psta(3)+1);
onxtst=tbl(4,psta(3)+1);
zoutb=dec2bin(zout,2);
zout1=bin2dec(zoutb(1));
zout2=bin2dec(zoutb(2));
ooutb=dec2bin(oout,2);
oout1=bin2dec(ooutb(1));
oout2=bin2dec(ooutb(2));
weiz=xor(zout1,in1)+xor(zout2,in2);
weio=xor(oout1,in1)+xor(oout2,in2);
psta(3)=znxtst;
psta(4)=onxtst;
psum(3)=psum(3)+weiz;
psum(4)=psum(4)+weio;
pbits(2,3)=0;
pbits(2,4)=1;
%Rest stages
for i=3:500
    in1=xy((i-1)*2+1);
    in2=xy(i*2);
    for j=1:4
        zout=tbl(1,psta(j)+1);
        znxtst(j)=tbl(2,psta(j)+1);
        oout=tbl(3,psta(j)+1);
        onxtst(j)=tbl(4,psta(j)+1);
        zoutb=dec2bin(zout,2);
        zout1=bin2dec(zoutb(1));
        zout2=bin2dec(zoutb(2));
        ooutb=dec2bin(oout,2);
        oout1=bin2dec(ooutb(1));
        oout2=bin2dec(ooutb(2));
        weiz=xor(zout1,in1)+xor(zout2,in2);
        weio=xor(oout1,in1)+xor(oout2,in2);
        psumz(j)=psum(j)+weiz;
        psumo(j)=psum(j)+weio;
    end
    [ssum,indx]=sort([psumz psumo]);   
    for j=1:4  
        if indx(j)<5
            psum(j)=psumz(indx(j));
            tbits(1:blenth,j)=pbits(:,indx(j));
            tbits(blenth+1,j)=0;
            psta(j)=znxtst(indx(j));
        else
            psum(j)=psumo(indx(j)-4);
            tbits(1:blenth,j)=pbits(:,indx(j)-4);
            tbits(blenth+1,j)=1;
            psta(j)=onxtst(indx(j)-4);
        end
    end
    blenth=blenth+1;
    pbits=tbits;
end 

Contact us