function y=brownian(scale,N,mute)
%Simulated Brownian motion on [0,1] from random midpoint displacement.  -JJL
if nargin<3,mute=1;end     %If mute>1, decrease size of variation with increasing steps.
if nargin<2,N=10;end
if nargin<1,scale=.5;end   %Scale of variation.
x=[0 1];  %Initial x-values.
y=[0 0];  %Initial y-values.
for i=1:N,
ymp=.5*(y(1:end-1)+y(2:end))+scale*(rand([1,length(y)-1])-1)/(mute^i);
y=weave(y,ymp);
x=weave(x,diff(x)/2+x(1:end-1));
end
plot(x,y)


function out=weave(in1,in2)
%Weave in1 and in2 together.  -JJL
n=length(in1);if length(in2)~=n-1,error('Improper lengths.'),end
out=zeros([1,2*n-1]);
out(1:2:2*n-1)=in1;out(2:2:2*n-2)=in2;
