www.pudn.com > communicationmatlab.rar > SIMRDBIT.M


function [sys, x0, str, ts] = simrdbit(t, x, u, flag, n, prob, seed) 
%SIMRDBIT outputs a zero vector with rand bit ones. 
%       When the inptu is non-zero, this block outputs the calculted output. 
%       When the input is zero, this block outputs zero vector. 
 
%       Wes Wang 
%       Copyright (c) 1995-96 by The MathWorks, Inc. 
 
if flag == 3 
    sys = zeros(1, n); 
    if u 
        len_prob = length(prob); 
        dividing = prob(len_prob); 
        if len_prob > 1 
            for i = 1 : len_prob - 1 
                dividing = [dividing(1) + prob(len_prob - i), dividing]; 
            end; 
        end;         
        indx = find(dividing >= rand(1,1)); 
        if ~isempty(indx) 
            for i = 1 : length(indx) 
                ind_zeros = find(sys == 0); 
                len_ind_zeros = length(ind_zeros); 
                if len_ind_zeros > 1 
                    % assign zeros 
                    div_zeros = [0 : len_ind_zeros-1]/len_ind_zeros; 
                    ind_loc = find(div_zeros <= rand(1,1)); 
                    sys(ind_zeros(length(ind_loc))) = 1; 
                end; 
            end; 
        end; 
    end; 
elseif flag == 0 
    rand('uniform'); 
    rand('seed',seed'); 
    sys(1) = 0; 
    sys(2) = 0; 
    sys(3) = n; 
    sys(4) = 1; 
    sys(5) = 0; 
    sys(6) = 1; 
    sys(7) = 1; 
    x0 = []; 
    ts = [-1. 0]; 
else 
    sys = []; 
end;