Forums

Split matrix and split vector quantization in CELP

Started by mata mata August 13, 2003
Dear all,

I have builded matlab functions over split matrix (SMQ) and split vector
quantization (SVQ) in CELP
but I am not so sure about the results....
would you examine my works...please...

my works is in the attachment

thx alot,
arida

ps: the theory is in the quant_theory.doc
m.file of SMQ is in Smq.m
m.file of SVQ is in Svq.m



Attachment (not stored)
quant_theory.doc
Type: application/msword

function [fk,ls]=smq(ls1,ls2,no)

%initialitation of variables
fs00;
nA=[7];
nB=[8];
nC=[9];
nD=[8];
nE=[6]; %q1=ls1';q2=ls2';
F1=zeros(1,no);
F2=zeros(1,no);
R=zeros(no,2);
f=zeros(no,2);
fk=zeros(1,no);
jlk=length(ls1);
R2L=zeros(1,no);
%Two sets of LSF vector
for bt=1:jlk
q1=ls1';q2=ls2';
F1(1,bt)=(fs/(2*pi))*acos(q1(1,bt));
F2(1,bt)=(fs/(2*pi))*acos(q2(1,bt));

%residual LSF vectors
P(1,bt)=0.65*R2L(1,bt);
R2(1,bt)1,bt)-P(1,bt);
R2L(1,bt)=R2(1,bt);
P(1,bt)=0.65*R2L(1,bt);
R1(1,bt)1,bt)-P(1,bt);
R2(1,bt)1,bt)-P(1,bt);
R(bt,1)=R1(1,bt)';
R(bt,2)=R2(1,bt)';

% split matrix
A=R(1:2,1:2);
B=R(3:4,1:2);
C=R(5:6,1:2);
D=R(7:8,1:2);
E=R(9:10,1:2); %---------------------%
%weighting factors
D1(1,1)1,2);
D2(1,1)1,2);
for n=2:9
D1(1,n)1,(n+1))-F1(1,(n-1));
D2(1,n)1,(n+1))-F2(1,(n-1));
end
D1(1,10)@00-F1(1,9);
D2(1,10)@00-F2(1,9);

if (D1(1,1)<450)&(D1(1,2)<450)&(D1(1,3)<450)&(D1(1,4)<450)&(D1(1,5)<450)
w1(1,1)=3.347-((1.547/450)*D1(1,1));
w1(1,2)=3.347-((1.547/450)*D1(1,2));
w1(1,3)=3.347-((1.547/450)*D1(1,3));
w1(1,4)=3.347-((1.547/450)*D1(1,4));
w1(1,5)=3.347-((1.547/450)*D1(1,5));
else
w1(1,1)=1.8-((0.8/1050)*(D1(1,1)-450));
w1(1,2)=1.8-((0.8/1050)*(D1(1,2)-450));
w1(1,3)=1.8-((0.8/1050)*(D1(1,3)-450));
w1(1,4)=1.8-((0.8/1050)*(D1(1,4)-450));
w1(1,5)=1.8-((0.8/1050)*(D1(1,5)-450));
end

if (D1(1,6)<450)&(D1(1,7)<450)&(D1(1,8)<450)&(D1(1,9)<450)&(D1(1,10)<450)
w1(1,6)=3.347-((1.547/450)*D1(1,6));
w1(1,7)=3.347-((1.547/450)*D1(1,7));
w1(1,8)=3.347-((1.547/450)*D1(1,8));
w1(1,9)=3.347-((1.547/450)*D1(1,9));
w1(1,10)=3.347-((1.547/450)*D1(1,10));
else
w1(1,6)=1.8-((0.8/1050)*(D1(1,6)-450));
w1(1,7)=1.8-((0.8/1050)*(D1(1,7)-450));
w1(1,8)=1.8-((0.8/1050)*(D1(1,8)-450));
w1(1,9)=1.8-((0.8/1050)*(D1(1,9)-450));
w1(1,10)=1.8-((0.8/1050)*(D1(1,10)-450));
end

if (D2(1,1)<450)&(D2(1,2)<450)&(D2(1,3)<450)&(D2(1,4)<450)&(D2(1,5)<450)
w2(1,1)=3.347-((1.547/450)*D2(1,1));
w2(1,2)=3.347-((1.547/450)*D2(1,2));
w2(1,3)=3.347-((1.547/450)*D2(1,3));
w2(1,4)=3.347-((1.547/450)*D2(1,4));
w2(1,5)=3.347-((1.547/450)*D2(1,5));
else
w2(1,1)=1.8-((0.8/1050)*(D2(1,1)-450));
w2(1,2)=1.8-((0.8/1050)*(D2(1,2)-450));
w2(1,3)=1.8-((0.8/1050)*(D2(1,3)-450));
w2(1,4)=1.8-((0.8/1050)*(D2(1,4)-450));
w2(1,5)=1.8-((0.8/1050)*(D2(1,5)-450));
end

if (D2(1,6)<450)&(D2(1,7)<450)&(D2(1,8)<450)&(D2(1,9)<450)&(D2(1,10)<450)
w2(1,6)=3.347-((1.547/450)*D2(1,6));
w2(1,7)=3.347-((1.547/450)*D2(1,7));
w2(1,8)=3.347-((1.547/450)*D2(1,8));
w2(1,9)=3.347-((1.547/450)*D2(1,9));
w2(1,10)=3.347-((1.547/450)*D2(1,10));
else
w2(1,6)=1.8-((0.8/1050)*(D2(1,6)-450));
w2(1,7)=1.8-((0.8/1050)*(D2(1,7)-450));
w2(1,8)=1.8-((0.8/1050)*(D2(1,8)-450));
w2(1,9)=1.8-((0.8/1050)*(D2(1,9)-450));
w2(1,10)=1.8-((0.8/1050)*(D2(1,10)-450));
end

%----------------%
%kuantisasi
level_1=2^nA;
level_2=2^nB;
level_3=2^nC;
level_4=2^nD;
level_5=2^nE;
kuan_A=round((A(:))*(level_1-1)/0.5);
kuan_B=round((B(:))*(level_2-1)/0.5);
kuan_C=round((C(:))*(level_3-1)/0.5);
kuan_D=round((C(:))*(level_4-1)/0.5);
kuan_E=round((D(:))*(level_5-1)/0.5);
f(1:2,1:2)=reshape(kuan_A,2,2);
f(3:4,1:2)=reshape(kuan_B,2,2);
f(5:6,1:2)=reshape(kuan_C,2,2);
f(7:8,1:2)=reshape(kuan_D,2,2);
f(9:10,1:2)=reshape(kuan_E,2,2);
f=(f./fs);

%----------------%
% two sets LSF terkuantisasi
f_1=(sort(abs(f(1:10,1))))';
f_2=(sort(abs(f(1:10,2))))';
f=sort(abs(f));

% weighted LSP distortion measure
E11=(((F1(1,1)*w1(1,1))-(f_1(1,1)*w1(1,1)))^2)+(((F1(1,2)*w1(1,2))-(f_1(1,2)*w1(\
1,2)))^2)+(((F1(1,3)*w1(1,3))-(f_1(1,3)*w1(1,3)))^2);
E21=(((F1(1,4)*w1(1,4))-(f_1(1,4)*w1(1,4)))^2)+(((F1(1,5)*w1(1,5))-(f_1(1,5)*w1(\
1,5)))^2)+(((F1(1,6)*w1(1,6))-(f_1(1,6)*w1(1,6)))^2);
E31=(((F1(1,7)*w1(1,7))-(f_1(1,7)*w1(1,7)))^2)+(((F1(1,8)*w1(1,8))-(f_1(1,8)*w1(\
1,8)))^2)+(((F1(1,9)*w1(1,9))-(f_1(1,9)*w1(1,9)))^2);
E41=((F1(1,10)*w1(1,10))-(f_1(1,10)*w1(1,10)))^2;
E1+E21+E31+E41;
E21=(((F2(1,1)*w2(1,1))-(f_2(1,1)*w2(1,1)))^2)+(((F2(1,2)*w2(1,2))-(f_2(1,2)*w2(\
1,2)))^2)+(((F2(1,3)*w2(1,3))-(f_2(1,3)*w2(1,3)))^2);
E22=(((F2(1,4)*w2(1,4))-(f_2(1,4)*w2(1,4)))^2)+(((F2(1,5)*w2(1,5))-(f_2(1,5)*w2(\
1,5)))^2)+(((F2(1,6)*w2(1,6))-(f_2(1,6)*w2(1,6)))^2);
E23=(((F2(1,7)*w2(1,7))-(f_2(1,7)*w2(1,7)))^2)+(((F2(1,8)*w2(1,8))-(f_2(1,8)*w2(\
1,8)))^2)+(((F2(1,9)*w2(1,9))-(f_2(1,9)*w2(1,9)))^2);
E24=((F2(1,10)*w2(1,10))-(f_2(1,10)*w2(1,10)))^2;
E2+E22+E23+E24;
%E1(1,1:10)=((F1(1,1:10).*w1(1,1:10))-(f_1(1,1:10).*w1(1,1:10))).^2;
%E2(1,1:10)=((F2(1,1:10).*w2(1,1:10))-(f_2(1,1:10).*w2(1,1:10))).^2;

% set LSF terkuantisasi yang dipilih
if (E1<E2)
fk(1,1:10)=f_1(1,1:10);
elseif (E2<E1);
fk(1,1:10)=f_2(1,1:10);
end
if fk==f_1
ls=ls1;
elseif fk==f_2
ls=ls2;
end
end


function [f]=svq(ar,ls,no,cmp)

%initialitation of variables
fs00;
if (cmp==7.95)
nA=9;nB=9;nC=9;
elseif (cmp==5.15);
nA=8;nB=8;nC=7;
else
nA=8;nB=9;nC=9;
end %q=ls';
F=zeros(1,no);
R=zeros(no,1);
f=zeros(no,1);
jlk=length(ls);
RL=zeros(1,no);
for bt=1:jlk
q=ls';
%Set of LSF vector
F(1,bt)=(fs/(2*pi))*acos(q(1,bt));

%Residual LSF vector
P(1,bt)=ar(1,bt).*RL(1,bt);
RM(1,bt)=F(1,bt)-P(1,bt);
RL(1,bt)=RM(1,bt);
P(1,bt)=ar(1,bt).*RL(1,bt);
R(bt,1)=(F(1,bt)-P(1,bt))';

% split vector
A=R(1:3,1);
B=R(4:6,1);
C=R(7:10,1);
end

%kuantisasi
level_1=2^nA;
level_2=2^nB;
level_3=2^nC;

kuan_A=round((A(:))*(level_1-1)/0.5);
kuan_B=round((B(:))*(level_2-1)/0.5);
kuan_C=round((C(:))*(level_3-1)/0.5);

f(1:3,1)=kuan_A(1:3,1);
f(4:6,1)=kuan_B(1:3,1);
f(7:10,1)=kuan_C(1:4,1);
f=(sort(abs(f)))';
f=f./fs;