function output_signal=kernel_meshsmooth(input_signal,tri,coord,nbr,sigma,n_smooth)
%(C) Moo K. Chung, Feb 5. 2004.

tic

K=inline('exp(-x/(2*sigma^2))/sum(exp(-x/(2*sigma^2)))');
n_vertex=size(nbr,1);


weight=zeros(n_vertex,7);
%weight computation
for i=1:n_vertex    
    if (i<=12)
        current_nbr=nbr(i,1:5);
        pipo=coord(:,current_nbr(1:5))-kron(ones(1,5),coord(:,i));
        distance=sum(pipo.*pipo);
        weight(i,:)=[K(sigma,[0 distance]) 0];
    else
        current_nbr=nbr(i,1:6);
        pipo=coord(:,current_nbr(1:6))-kron(ones(1,6),coord(:,i));
        distance=sum(pipo.*pipo);
        weight(i,:)=K(sigma,[0 distance]);
    end;
end;

toc

%iterated smoothing
signal=input_signal;
for j=1:n_smooth
    Y=[[signal(nbr(1:12,1:5)) zeros(12,1)]; signal(nbr(13:n_vertex,:))];
    signal=sum(weight.*[signal Y],2);
end;
      
output_signal=signal;
toc
return;
