function xV = ARmStudent(phiV,n,sdnoise,dof)
% xV = ARmStudent(phiV,n,sdnoise,dof)
% Generate an AR(m) time series of length 'n' with input noise from the 
% Student distribution for a given degrees of freedom 'dof'. 
% Note that phiV = [phi_0 phi_1 ... phi_m]' and phi_0 is the constant term
% and sdnoise is the SD of the input noise (if left out then sdnoise=1)
if nargin==3
    dof=1;
elseif nargin==2
    dof=1;
    sdnoise=1;
end
ntrans = 100;
m = length(phiV)-1;

phiV = phiV(:);
a0 = phiV(1);
aV = phiV(2:m+1);
x0V = sdnoise*trnd(dof,m,1);
wV = trnd(dof,n+ntrans,1) * sdnoise;
xV = NaN*ones(n+ntrans,1);
xV(1:m) = x0V;
for i=m+1:n+ntrans
    xV(i) = a0 + aV' * flipud(xV(i-m:i-1)) + wV(i);
end
xV = xV(ntrans+1:n+ntrans);
