function [sKernel] =ChopByMax(KernelFunction,KLength)

    
      
  sKernel=zeros(1,KLength);
  inKLength=max(size(KernelFunction));

   [EdgeMax MaxIndex]=max(KernelFunction);

    iHalf=floor(KLength/2); 
     iKBegin=MaxIndex-iHalf;
     iKEnd=MaxIndex+iHalf;
    
        
if (iKBegin>0) && (iKEnd<=inKLength)
    sKernel=KernelFunction(iKBegin:iKEnd);
else
    sKernel(1:KLength)=0;
end

end