function y = hat(x, x0, w)

m=length(x)
% This returns the hat function at some x centered at x0, with width w and unity amplitude
for i=1:m
    if x(i)>=x0
       y(i)=(2*(x0-x(i))+w)/w;
    else
       y(i)=(2*(x(i)-x0)+w)/w;
   end
   if y(i)<0
      y(i)=0;
   end
end
