function [S,K] = konvo(x,y,t,z)
%Laskee funktion y(x) konvoluution ytimen z(t) kanssa.
%
%[Y,Z] = konvo(x,y,t,z)
xmin=min(x);
xmax=max(x);
l=xmax-xmin;
S=linspace(xmin,xmax,1000);
s=linspace(xmin-l,xmax+l,2998);
diff=s(2)-s(1);
y2=[0*y,y,0*y];
tmin=min(t);tmin=max(tmin,xmin);
tmax=max(t);tmax=min(tmax,xmax);
r=tmin:diff:tmax;
L=length(r);
L1=round(L/2);
L2=L-L1;
Z=interp1(t,z,r);Z=fliplr(Z);
for k=1000:1999
Y=y2(k-L1:k+L2-1);
K(k-999)=mean(Y.*Z);
end

h=figure; hold on, axis equal
plot(S,y,'r')
plot(S,K)
axesObjs = get(h, 'Children');
dataObjs = get(axesObjs, 'Children');
legend([dataObjs(2),dataObjs(1)],'funktio','konvoluutio')
end

