function y=mphase2(x,dim)
% function y=mphase(x)
% circular mean of angle array x
% created by Nai 2008
% updated by Nai 04/26/09

c=mean(cos(x),dim);
s=mean(sin(x),dim);
y=atan2(s,c);

% y=angle(mean(exp(j*x)));