function [hw]=system2_histograms(ai,d0,bb)
n=size(ai);  

%bb=4; d0=1; 

w=d0*0.7; 
dx=2.2;%optimized parameter
v=dx-d0*[0:(bb-1)];v=v/w;
 
for i=1:n(1)%sub
  for j=1:n(2)%f0
    r=2^(j/2);%norm 
    for k=1:n(3)%au
      x=ai(i,j,k,:);x=x(x>0);x=log(x(:));
      for kk=1:bb
	xk=1-(x/w-v(kk)).^2;
	xk=xk(xk>0); 
	hw(i,j,k,kk)=sum(xk)*r;
      end
    end
  end
end

hw=reshape(hw,n(1),n(2)*n(3)*bb);   


  
     



