No BSD License  

Highlights from
Encoded Data Simulator

from Encoded Data Simulator by Bill Higley
A group of m-files that simulate encoded data

makeRLL(in,d,k)
%makeRLL(in,d,k)
%   This function creates a random sequence of a little more than 'in' bits 
%   valued at 0 and 1, which meets a run-length limited (d,k) constraint.
%   This is an NRZI code.

function out = makeRLL(in,d,k)

sum = 0;
for i = d+1:k+1
    sum = sum + exp(-i);
end
K = 1./sum;

M = cell(k-d+1,1);
for i = 1:k-d+1
    M{i} = [zeros(1,d+i-1) , 1];
end

chain = [];
while length(chain) < in
    x = rand;
    likeacdf = 0;
    for i = 1:k-d+1
        likeacdf = likeacdf + K*exp(-length(M{i}));
        if x < likeacdf
            chain = [chain M{i}];
            break            
        end
    end
end

out = chain;

Contact us at files@mathworks.com