function eo = lat1q(input,d,lambda,eta,order,B);
% Quantized a posteriori-based RLS lattice filter
% returns the a-priori output error sequence
N = max(size(input));
M = order;
% Initialization of M-order vectors
gamma = ones(M+1,1);
b = zeros(M,1);
delta = zeros(M,1);
rho = zeros(M,1);
xif = (1/eta*lambda*lambda)*ones(M,1);
xib = (1/eta*lambda*lambda)*ones(M,1);
for m=0:M-1
xib(m+1) = xib(m+1)/lambda^m;
end
xif = quantize_v(xif,B);
xib = quantize_v(xib,B);
for i=1:N
gammao = gamma;
bo = b;
xibo = xib;
gamma = ones(M,1);
b(1) = input(i);
f(1) = input(i);
r(1) = d(i);
for m=1:M
xif(m) = quantize(quantize(lambda*xif(m),B) + quantize((abs(f(m)))^2/gammao(m),B),B);
xib(m) = quantize(quantize(lambda*xib(m),B) + quantize((abs(b(m)))^2/gamma(m),B),B);
delta(m) = quantize(quantize(lambda*delta(m),B) + quantize((f(m))'*(bo(m))/gammao(m),B),B);
rho(m) = quantize(quantize(lambda*rho(m),B) + quantize((r(m))'*(b(m))/gamma(m),B),B);
gamma(m+1) = quantize(quantize(gamma(m) - quantize(abs(b(m))^2/xib(m),B),B),B);
kappab(m) = quantize(delta(m)/xif(m),B);
kappaf(m) = quantize((delta(m))'/xibo(m),B);
kappa(m) = quantize((rho(m))'/xib(m),B);
b(m+1) = quantize(bo(m) - quantize(kappab(m)*f(m),B),B);
f(m+1) = quantize(f(m) - quantize(kappaf(m)*bo(m),B),B);
r(m+1) = quantize(r(m) - quantize(kappa(m)*b(m),B),B);
end
eo(i) = quantize(r(M+1)/gamma(M+1),B);
end
function eo = lat2q(input,d,lambda,eta,order,B);
% Quantized a priori-based RLS lattice filter
% returns the a-priori output error sequence
N = max(size(input));
M = order;
% Initialization of M-order vectors
gamma = ones(M+1,1);
beta = zeros(M,1);
delta = zeros(M,1);
rho = zeros(M,1);
kappaf = zeros(M,1);
kappab = zeros(M,1);
kappa = zeros(M,1);
xif = (1/eta*lambda*lambda)*ones(M,1);
xib = (1/eta*lambda*lambda)*ones(M,1);
for m=0:M-1
xib(m+1) = xib(m+1)/lambda^m;
end
xif = quantize_v(xif,B);
xib = quantize_v(xib,B);
for i=1:N
gammao = gamma;
betao = beta;
xibo = xib;
gamma = ones(M,1);
beta(1) = input(i);
alpha(1) = input(i);
e(1) = d(i);
for m=1:M
xif(m) = quantize(quantize(lambda*xif(m),B) + quantize((abs(alpha(m)))^2*gammao(m),B),B);
xib(m) = quantize(quantize(lambda*xib(m),B) + quantize((abs(beta(m)))^2*gamma(m),B),B);
delta(m)=quantize(quantize(lambda*delta(m),B)+quantize((alpha(m))'*(betao(m))*gammao(m),B),B);
rho(m) = quantize(quantize(lambda*rho(m),B) + quantize((e(m))'*(beta(m))*gamma(m),B),B);
beta(m+1) = quantize(betao(m) - quantize(kappab(m)*alpha(m),B),B);
alpha(m+1) = quantize(alpha(m) - quantize(kappaf(m)*betao(m),B),B);
e(m+1) = quantize(e(m) - quantize(kappa(m)*beta(m),B),B);
gamma(m+1) = quantize(gamma(m) - quantize(abs(gamma(m)*beta(m))^2/xib(m),B),B);
kappab(m) = quantize(delta(m)/xif(m),B);
kappaf(m) = quantize((delta(m))'/xibo(m),B);
kappa(m) = quantize((rho(m))'/xib(m),B);
end
eo(i) = e(M+1);
end
function eo = lat3q(input,d,lambda,eta,order,B);
% Quantized a priori-based error feedback RLS lattice filter
% returns the a-priori output error sequence
N = max(size(input));
M = order;
% Initialization of M-order vectors
gamma = ones(M,1);
beta = zeros(M,1);
kappaf = zeros(M,1);
kappab = zeros(M,1);
kappa = zeros(M,1);
xif = (1/eta*lambda*lambda)*ones(M,1);
xib = (1/eta*lambda*lambda)*ones(M,1);
for m=0:M-1
xib(m+1) = xib(m+1)/lambda^m;
end
xif = quantize_v(xif,B);
xib = quantize_v(xib,B);
for i=1:N
gammao = gamma;
betao = beta;
xibo = xib;
gamma = ones(M+1,1);
beta(1) = input(i);
alpha(1) = input(i);
e(1) = d(i);
for m=1:M
xif(m) = quantize(quantize(lambda*xif(m),B) + quantize((abs(alpha(m)))^2*gammao(m),B),B);
xib(m) = quantize(quantize(lambda*xib(m),B) + quantize((abs(beta(m)))^2*gamma(m),B),B);
beta(m+1) = quantize(betao(m) - quantize(kappab(m)*alpha(m),B),B);
alpha(m+1) = quantize(alpha(m) - quantize(kappaf(m)*betao(m),B),B);
e(m+1) = quantize(e(m) - quantize(kappa(m)*beta(m),B),B);
kappa(m) = quantize(kappa(m) + quantize((beta(m))'*gamma(m)*e(m+1)/xib(m),B),B);
kappaf(m) = quantize(kappaf(m) + quantize((betao(m))'*gammao(m)*alpha(m+1)/xibo(m),B),B);
kappab(m) = quantize(kappab(m) + quantize((alpha(m))'*gammao(m)*beta(m+1)/xif(m),B),B);
gamma(m+1) = quantize(gamma(m) - quantize(abs(gamma(m)*beta(m))^2/xib(m),B),B);
end
eo(i) = e(M+1);
end
function eo = lat4q(input,d,lambda,eta,order,B);
% Quantized a posteriori-based error feedback RLS lattice filter
% returns the a-priori output error sequence
N = max(size(input));
M = order;
% Initialization of M-order vectors
gamma = ones(M+1,1);
b = zeros(M,1);
kappaf = zeros(M,1);
kappab = zeros(M,1);
kappa = zeros(M,1);
xif = (1/eta*lambda*lambda)*ones(M,1);
xib = (1/eta*lambda*lambda)*ones(M,1);
for m=0:M-1
xib(m+1) = xib(m+1)/lambda^m;
end
xif = quantize_v(xif,B);
xib = quantize_v(xib,B);
xibo = xib;
for i=1:N
gammao = gamma;
bo = b;
xiboo = xibo;
xibo = xib;
xifo = xif;
gamma = ones(M+1,1);
b(1) = input(i);
f(1) = input(i);
r(1) = d(i);
for m=1:M
xif(m) = quantize(quantize(lambda*xif(m),B) + quantize((abs(f(m)))^2/gammao(m),B),B);
xib(m) = quantize(quantize(lambda*xib(m),B) + quantize((abs(b(m)))^2/gamma(m),B),B);
gamma(m+1) = quantize(gamma(m) - quantize(abs(b(m))^2/xib(m),B),B);
a1 = quantize(kappa(m) + quantize(((b(m))'*r(m))/(lambda*gamma(m)*xibo(m)),B),B);
kappa(m) = quantize((gamma(m+1)/gamma(m))*a1,B);
a1 = quantize(kappaf(m) + quantize(((bo(m))'*f(m))/(lambda*gammao(m)*xiboo(m)),B),B);
kappaf(m) = quantize((gammao(m+1)/gammao(m))*a1,B);
a1 = quantize(kappab(m) + quantize(((f(m))'*bo(m))/(lambda*gammao(m)*xifo(m)),B),B);
kappab(m) = quantize((gamma(m+1)/gammao(m))*a1,B);
b(m+1) = quantize(bo(m) - quantize(kappab(m)*f(m),B),B);
f(m+1) = quantize(f(m) - quantize(kappaf(m)*bo(m),B),B);
r(m+1) = quantize(r(m) - quantize(kappa(m)*b(m),B),B);
end
eo(i) = quantize(r(M+1)/gamma(M+1),B);
end
function eo = lat5q(input,d,lambda,eta,order,B);
% Quantized normalized RLS lattice filter
% returns the a-priori output error sequence
N = max(size(input));
M = order;
% Initialization of M-order vectors
b = zeros(M,1);
kappaa = zeros(M,1);
kappac = zeros(M,1);
xi = (1/eta*lambda*lambda); % scalar xi_0(-1)
xib = (1/eta*lambda*lambda); % scalar xi_0^b(-1)
pb = ones(M,1);
xi = quantize(xi,B);
xib = quantize(xib,B);
for i=1:N
bo = b;
pbo = pb;
gamma = ones(M,1); % added only to obtain the a priori error
xib = quantize(quantize(lambda*xib,B) + quantize(abs(input(i))^2,B),B);
xi = quantize(quantize(lambda*xi,B) + quantize(abs(d(i))^2,B),B);
b(1) = quantize(input(i)/sqrt(xib),B);
f(1) = b(1);
r(1) = quantize(d(i)/sqrt(xi),B);
sigma(1) = quantize(sqrt(xi),B);
for m=1:M
pb(m) = quantize(sqrt(1-abs(b(m))^2),B);
pf(m) = quantize(sqrt(1-abs(f(m))^2),B);
p(m) = quantize(sqrt(1-abs(r(m))^2),B);
kappaa(m) = quantize(quantize(kappaa(m)*pbo(m)*pf(m),B) + quantize(f(m)*(bo(m))',B),B);
kappac(m) = quantize(quantize(kappac(m)*pb(m)*p(m),B) + quantize((b(m))'*r(m),B),B);
pa(m) = quantize(sqrt(1-abs(kappaa(m))^2),B);
pc(m) = quantize(sqrt(1-abs(kappac(m))^2),B);
r(m+1) = quantize((1/(pb(m)*pc(m))*quantize(r(m)-quantize(kappac(m)*b(m),B),B)),B);
b(m+1) = quantize((1/(pf(m)*pa(m))*quantize(bo(m)-quantize((kappaa(m))'*f(m),B),B)),B);
f(m+1) = quantize((1/(pbo(m)*pa(m))*quantize(f(m)-quantize(kappaa(m)*bo(m),B),B)),B);
sigma(m+1) = quantize(sigma(m)*pc(m)*pb(m),B);
ro(m+1) = quantize(sigma(m+1)*r(m+1),B); % a posteriori error
gamma(m+1) = quantize(gamma(m)*pb(m)*pb(m),B); % necessary only to recover a priori error
end
eo(i) = quantize(ro(M+1