function [ladj p] = awaldcirc(z)
% AWALDCIRC Adjusted Wald's type circularity detector assuming random sample from 
%           unspecified  complex elliptically symmetric distribution with finite 4th moment
%
% INPUT PARAMETERS:
%    z       complex sample (vector of lenght n)
% OUTPUT 
%   ladj     value of the test statistic 
%   p        P-value 
% 
% (c) Esa Ollila, contact: esollila AT wooster.hut.fi
%
% If you use this program, please cite 
% E. Ollila, J. Eriksson, V. Koivunen, "Complex univariate elliptically symmetric distributions", 
% submitted to IEEE Transactions on Signal Processing, Dec. 2009. 
%-------------------------------------------------------------------------------

n = length(z);
vz  = var(z,1); % sample variance of z
pvz = mean((z-mean(z)).^2) ; % sample pseudo-variance of z 
cc = abs(pvz)/vz;  % sample circularity coefficient 
l = n*cc^2; 
mom4  = mean(abs(z-mean(z)).^4)/(vz^2);  % stand. 4th-order abs. moment 
adj = mom4/(2+cc^2);
ladj = l/adj; % adjusted Wald's test statistic 

if license('test','statistics_toolbox')
   p = 1- chi2cdf(ladj,2);
else 
   warning('Computation of the p-value requires STATISTICS toolbox'); 
   p = [ ] ;
end
