function [phihat,x]=phi2hat(phi,rho)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% function phihat=phi2hat(phi,rho)
%
% phihat = phi^{-1/2} diag(rho) phi^{-1/2}
%

[n,m]=size(rho);
if m~=1, disp('rho must be n by 1'), return, end

x=sqrtm(phi);
phihalfinv=inv(x);
phihat=phihalfinv*diag(rho)*phihalfinv;
