function f=npdf3(x,y,z,mu,sigma)

% NPDF3       Tri-variate Normal probability density function.
%
%             Example: npdf3(0,0,0,[0 0 0]',eye(3))
% 
%             NPDF3(X,Y,Z,MU,SIGMA) calculates the tri-variate normal 
%             pdf at (X,Y,Z).  If MU (mean) and SIGMA (covariance matrix) 
%             are omitted, values of (0,0,0) and I_3 are assumed.
%
%             Christian C. Beardah 1996

if nargin==2,
  sigma=eye(3);
  mu=[0 0 0]';
end;

m=inv(sqrtm(sigma));

x=x-mu(1)*ones(size(x));
y=y-mu(2)*ones(size(y));
z=z-mu(3)*ones(size(z));

f=knorm(m(1,1)*x+m(1,2)*y+m(1,3)*z,m(2,1)*x+m(2,2)*y+m(2,3)*z,m(3,1)*x+m(3,2)*y+m(3,3)*z)/sqrt(det(sigma));