function Z = rndct(m,n,v,mu,om,unitvar)
% RNDCT  random sample generation from unit dispersion complex t-distribution. 
% 
% INPUT PARAMETERS:
%    m, n    size of the sample
%    v       degrees of freedom (d.f.) parameter of t-distribution (positive integer). 
%            v = 1 corresponds to complex Cauchy distribution 
%    mu      symmetry center (complex-valued). Also equals the mean when v>=2,3,...  
%    om      pseudo-dispersion parameter (complex-valued) with property  |om| inside [0,1].  
%            Since dispersion parameter = 1, om  is equal to the circularity quotient when 
%            the variance exists (i.e. for v>=3,4,5,...)
%    unitvar optional parameter (any value). If exists, then the sample is generated 
%            from standardized (i.e. unit variance) t-distribution
%          
% OUTPUT 
%    Z     random sample of size m X n from  Ct_v(mu,dispersion=1,pseudo-dispersion=om) 
%
% (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, 2009. 
%-------------------------------------------------------------------------------

if (abs(om)>1)  
     error('Input parameter om should have modulus <= 1')
end 

% STEP 1
cc  = abs(om);    % cc = |om| (equals the circularity coefficient provided it exists)
ang = angle(om);  % ang = Arg(om) (equals the circularity angle provided it exists)

% STEP 2
W  = (1/sqrt(2))*(randn(m,n)+j*randn(m,n)); % random sample form CN(0,1) 

if nargin == 6  
  Z0 = sqrt(v-2)*W./sqrt(chi2rnd(v,m,n)); % ramdom sample from standardized Ct_v(0,1)
else 
  Z0 = sqrt(v)*W./sqrt(chi2rnd(v,m,n)); % random sample from Ct_v(0,1)
end 

% STEP 3
a = sqrt(1+cc); 
b = sqrt(1-cc); 
Zp = (1/2)*(a+b)*Z0 + (1/2)*(a-b)*conj(Z0);

% STEP 4
Z = mu + exp(j*ang/2)*Zp; 
