function [a1,a2] = lsp(wa,p)
% LSP   Line Spectrum Pair (LSP) decomposition 
%    [AP,AQ] = LSP(WA,P) Finds the LPC-coefficients and generates
%    the LSP-decompositions. The coefficients are AP=[1 AP(2) ... AP(P+1)] 
%    and AQ=[1 AQ(2) ... AQ(P+1)].
%
%    This function is an appendix to the two articles presented
%    by Alku and Bäckström (in association with B. Kleijn) at ICASSP'02. 
%
%    See also: WLSP, LSPTD, LSPFIT, LSP, LSPX

% Tom Bäckström / 11.10.2001


% calculate the LPC coefficients

a = lpc(wa,p);


% generate LSP and remove trivial zero(s)

if round((p)/2)*2 == p % if p is even
    [a1,r] = deconv([[a 0] + [0 a(length(a):-1:1)]],[1 1]);
    [a2,r] = deconv([[a 0] - [0 a(length(a):-1:1)]],[1 -1]);
else % p is odd
    a1 = [a 0] + [0 a(length(a):-1:1)];
    [a2,r] = deconv([[a 0] - [0 a(length(a):-1:1)]],[1 0 -1]);
end;

