function lsf = poly2lsf(p)
% Convert a linear prediction polynomial to a vector of the equivalent
% line spectral frequencies.
%
% If A(z) = 1 + a1*z^-1 + ... + am*z^-M is
% a linear prediction polynomial, the corresponding line
% spectral frequencies are the angles of the roots in the upper half
% plane of the two polynomials
% P_sym(z) = A(z) + (z^-(M+1))*A(z^-1) and
% P_asym(z) = A(z) - (z^-(M+1))*A(z^-1), ignoring the roots 1 and -1,
% which are always present and so don't need to be listed.
% P_sym and P_asym are known as the symmetric and asymmetric polynomials,
% respectively.
if(not(isreal(p)))
error("linear prediction coefficients must be real");
end
if(size(p,1) == 1)
p = p';
end
p_rev = [0; flipud(p)];
rts = [roots([p; 0] + p_rev); roots([p; 0] - p_rev)];
lsf = sort(angle(rts(imag(rts) > 0)));
end