function [x,r] = randlevels2( L,  sigman,pctdD,T);
%function [x,r] = randlevels2( L,  sigman,pctdD,T);
%over [1:T] builds L levels shifts 
%Using [x,r] = randlevels2( 14, 1.6, .3, 950)

oldstart = 0;
%pctdD=1;T=900;
D = floor( (1)*(T/L) );dD = floor( pctdD*D );

%x=zeros(2*T,1);
disp('  ');
disp([ '            No         Start           End      Duration           Amp']);
disp('  ');format bank;
amp =[1:L];[tmp,sindx]=sort(rand(L,1));
amp=amp(sindx);%randomize
for el=1:L
    start(el) = oldstart+1;
    %amp(el) = sqrt( -2*P*log(rand(1,1)) );
    dur(el) = floor(D +dD*(rand(1,1)-1/2));
    oldstart = start(el)+dur(el);
    tindx = [start(el):1:oldstart];
    disp([el start(el) oldstart dur(el) amp(el)]);
    x(tindx) = amp(el)*ones(size(tindx));
    
end
x = x(:);Lx = length(x);
disp(' ');format short e
disp([ D dD]);


t = [1:Lx]';

r = x+ sigman*randn(Lx,1);Lr=length(r);

    
subplot(211);
plot(t,x);grid
subplot(212);
plot(t,r,'r',t,x,'b*');grid
subplot(111)

