dl=ones(1,256);
ol=ones(1,255);


for l=0:7,
   for v=0:15,
   m=l*16+v+1;
   dld1(1,m)=2^l*(v+16.0)-16.5;
   old(1,m)=2^l*(v+16.5)-16.5;
end
end
dv=[4079.5];
dld=[dld1 dv];
dl1=dld(1:1,3:129);
dl2=-1.*fliplr(dl1);
dl=[dl2 dld];
ol1=old(1:1,2:128);
ol2=-1.*fliplr(ol1);
ol=[ol2 old];
s=-87.18:5-72.18;
s1=.05.*s;
ss=(2831.31/sqrt(2))*10.^s1;
%x0=[0 7.5 15.5 31.5 39.5 47.5];
%x0=[0 .1 .2 .3 .4 .5];
x0=0:.02:1;
nmin=ones(1,length(s));
nmax=ones(1,length(s));
for u=1:length(x0)
nmin=x0(u)-6.*ss;
nmax=x0(u)+6.*ss;
for j=1:length(ss)
   i(j)=1;
while(i(j)<=255&dl(1,i(j))<nmin(j))
   i(j)=i(j)+1;
end
imin(j)=i(j)-1;
if imin(j)<1
   imin(j)=1;
end
if imin(j)>255
   imin(j)=255;
end
end
for j=1:length(ss)
   i(j)=256;
   while (i(j)>=1&dl(1,i(j))>nmax(j))
      i(j)=i(j)-1;
   end
   imax(j)=i(j);
   if imax(j)<1
      imax(j)=1;
   end
   if imax(j)>255
      imax(j)=255;
   end
end
q=length(ss);
ii=ones(q,255);

for l=1:q
   for k=1:255
      ii(l,k)=gau(dl(1,k),dl(1,k+1),ss(1,l),x0(u),101);
      hh(l,k)=tau(dl(1,k),dl(1,k+1),ss(1,l),x0(u),101);
      gg(l,k)=var(dl(1,k),dl(1,k+1),ss(1,l),x0(u),101);	
end
end
e2=ol.^2;

for l=1:q
   for k=1:255
      jj(l,k)=ii(l,k)* e2(1,k);
      ff(l,k)=ii(l,k)*ol(1,k);
      tt(l,k)=hh(l,k)*ol(1,k);
   end
end
ey2=ones(1,q);ey=ones(1,q);
exy=ones(1,q);disp=ones(1,q);
nn=101;
for j=1:q
   rl=jj(j:j,imin(j)+1:imax(j)-1); rr(j)=sum(rl);
   al=ff(j:j,imin(j)+1:imax(j)-1); aa(j)=sum(al);
   bl=tt(j:j,imin(j)+1:imax(j)-1); bb(j)=sum(bl);
cl=hh(j:j,imin(j)+1:imax(j)-1); cc(j)=sum(cl);
xl=gg(j:j,imin(j)+1:imax(j)-1); dd(j)=sum(xl);
ey2(1,j)=ol(1,imin(1,j))^2*gau(nmin(1,j),dl(1,imin(1,j)+1),ss(1,j),x0(u),nn)+...
ol(1,imax(1,j))^2*gau(dl(1,imax(1,j)),nmax(1,j),ss(1,j),x0(u),nn)+rr(j);
ey(j)=ol(imin(j))*gau(nmin(j),dl(imin(j)+1),ss(j),x0(u),nn)+ol(imax(j))*gau(dl(imax(j)),nmax(j),ss(j),x0(u), nn)+aa(j);
disp(j)=ey2(j)-ey(j)^2;
%zgo(j)=10*log10(2*disp(j)/2831.31^2);
%exy(j)=ol(imin(j))*tau(nmin(j),dl(imin(j)+1),ss(j),x0(u),nn)+ol(imax(j))*tau(dl(imax(j)),nmax(j),ss(j),x0(u), nn)+bb(j);
ex(j)=tau(nmin(j),dl(imin(j)+1),ss(j),x0(u),nn)+tau(dl(imax(j)),nmax(j),ss(j),x0(u), nn)+cc(j);
ex2(j)=var(nmin(j),dl(imin(j)+1),ss(j),x0(u),nn)+var(dl(imax(j)),nmax(j),ss(j),x0(u), nn)+dd(j);

%covxy(j)=exy(j)-x0*ey(j);
%r0(j)=covxy(j)/(ss(j)*sqrt(disp(j)));
%sdr(j)=-10*log10(1-r0(j)^2);
%a(j)=covxy(j)/ss(j)^2;
%(j)=20*log10(a(j));
y1=['zgo',num2str(u),'(j)'];
y2=['=10*log10(2*disp(j)/2831.31^2);'];
y=[y1 y2];
eval(y)
%v1=['sdr',num2str(u),'(j)'];
%v2=['=10*log10(1/(1-r0',num2str(u),'(j)^2));'];
%v=[v1 v2];
%eval(v)


%sdr(j)=10*log10(1/(1-r0(j)));
%a(j)=2*covxy(j)/ss(j)^2;
end
%z=['plot(s,zgo',num2str(u), ') '];
%eval(z)
% plot(s,sdr)
%hold on
end

%t2=s+87.18;f1=87.18+zgo1;f2=87.18+zgo2;f3=87.18+zgo3;f4=87.18+zgo4;f5=87.18+zgo5;f6=87.18+zgo6;
%plot(t2,f1,t2,f2, t2,f3,t2,f4,t2,f5,t2,f6) 



%z(j)=-10*log10(disp(j));
%end
 %plot(s,z)
%hold on
end