function out=prbs(order);
% out=prbs(order)  This function produces a Pseudo Random Binary Sequence
%                   of the specified order
if nargin==0
    order=0;
end
if (order>1)&(order<12)
    an=[0,0;1,2;2,3;1,4;2,5;1,6;3,7;1,2;4,9;7,10;9,11];
    a8=[3,7];
    %Generate initial values
    out=mod(floor(10*rand(1,order)),2);
    %Eliminate all 0's as initial conditions, which lead to all 0's
    while (out(order+1-an(order,1))==0)&(out(order+1-an(order,2))==0)
        out=mod(floor(10*rand(1,order)),2);
    end
    for i=1+order:2^order-1+order
        if order~=8
            out(i)=mod(out(i-an(order,1))+out(i-an(order,2)),2);
        else
            out(i)=mod(out(i-an(order,1))+out(i-an(order,2))+out(i-a8(1))+out(i-a8(2)),2);
        end
    end
    out=out(1+order:2^order-1+order);
else
    fprintf('ERR: Order must be 2-11 for PRBS. \nUse: prbs(order)')
end        
return
