function [Tn] = chebypoly(n)

% simple routine to calculate the Chebyshev polynomials based on their
% recursive relationship

if n < 0
    error('n cannot be negative');
    return
end

if n == 0
    Tn = 1;
    return;
elseif n == 1
    Tn = [1 0];
    return;
else
    Tn1 = chebypoly(n-1);
    Tn2 = chebypoly(n-2);

    Tn = 2*conv([1 0], Tn1) - [0 0 Tn2];
end

end

