% Nandakishore Ramaswamy
% EE 5356 Project 4A
% 3/27/03
% Build the correlation matrix
l=1;
p=0.9;
for r=1:16
k=r-1;
m=1;
for c=1:16
if k~=0
P(r,c)=p^k;
k=k-1;
elseif m~=17
P(r,c)=p^(m-1);
m=m+1;
end;
end;
end;
% Compute the variances for DCT transform.
A=dct2(P);
size(A)
N=size(A);
k1=1;
for T=0.1:0.1:max(max(A))
S1=0;
M1=0;
for j=1:N(1)
S1=S1+max(0,(log2((A(j,j))/T))/2);
M1=M1+min(T,abs(A(j,j)));
end;
R1(k1)=S1/(N(1));
D1(k1)=M1/N(1);
k1=k1+1;
end;
R1=(R1)/1.44;
%% Compute the variances for DST transform.
for k2=1:16
for l2=1:16
Su=0;
for i=1:16
for j=1:16
Su=Su+((P(i,j)*sin(i*k2*pi/17)*sin(j*l2*pi/17))*0.1176);
end;
end;
Xs(k2,l2)=Su;
end;
end;
size(Xs)
k3=1;
for T=0.1:0.1:max(max((Xs)))
S2=0;
M2=0;
for j=1:16
S2=S2+max(0,(log2((Xs(j,j)/T)))/2);
M2=M2+min(T,abs(Xs(j,j)));
end;
R2(k3)=S2/(16);
D2(k3)=M2/16;
k3=k3+1;
end;
R2=(R2)/1.44;
% Compute the variances for DFT transform.
E=fft2(P);
E=abs(E)/N(1);
N=size(E)
k4=1;
for T=0.1:0.1:max(max(E))
S3=0;
M3=0;
for j=1:N(1)
S3=S3+max(0,(log2((E(j,j))/T))/2);
M3=M3+min(T,abs(E(j,j)));
end;
R3(k4)=S3/(N(1));
D3(k4)=M3/(N(1));
k4=k4+1;
end;
R3=(R3)/(1.44);
D3=D3/max(D3);
% Compute the variances for KLT transform.
l=1;
p=0.9;
for r=1:16
k=r-1;
m=1;
for c=1:16
if k~=0
P(r,c)=p^k;
k=k-1;
elseif m~=17
P(r,c)=p^(m-1);
m=m+1;
end;
end;
end;
[K,M]=eig(P);
size(M)
N=size(M)
k5=1;
for T=0.1:0.1:max(max(M))
S4=0;
M4=0;
for j=1:N(1)
S4=S4+max(0,(log2((M(j,j))/T))/2);
M4=M4+min(T,abs(M(j,j)));
end;
R4(k5)=S4/(N(1));
D4(k5)=M4/(N(1));
k5=k5+1;
end;
R4=(R4)/(1.44);
D4=D4/max(D4);
semilogy(D1,R1,'xb',D2,R2,'og',D3,R3,'pm',D4,R4,'rd');
% Part-2
l=1;
for p=0.1:0.1:0.9
for r=1:16
k=r-1;
m=1;
for c=1:16
if k~=0
P(r,c)=p^k;
k=k-1;
elseif m~=17
P(r,c)=p^(m-1);
m=m+1;
end;
end;
end;
% DCT
A=dct2(P);
N=size(A);
S=0;
for i=1:N(1)
for k=1:N(1)
if i~=k
S=S+A(i,k);
end;
end;
end;
R(l)=(S*100)/(N(1)*(N(1)-1));
l=l+1;
end;
figure
plot(0.1:0.1:0.9,(R/max(R)),'b-')
hold on
%DST
l=1;
for p=0.1:0.1:0.9
for r=1:16
k=r-1;
m=1;
for c=1:16
if k~=0
P(r,c)=p^k;
k=k-1;
elseif m~=17
P(r,c)=p^(m-1);
m=m+1;
end;
end;
end;
for k2=1:16
for l2=1:16
Su=0;
for i=1:16
for j=1:16
Su=Su+((P(i,j)*sin(i*k2*pi/17)*sin(j*l2*pi/17))*0.1176);
end;
end;
Xs(k2,l2)=Su;
end;
end;
N=size(Xs);
S=0;
for i=1:N(1)
for k=1:N(1)
if i~=k
S=S+Xs(i,k);
end;
end;
end;
R(l)=(S*100)/(N(1)*(N(1)-1));
l=l+1;
end;
plot(0.1:0.1:0.9,R,'r:')
hold on
% DFT
l=1;
for p=0.1:0.1:0.9
for r=1:16
k=r-1;
m=1;
for c=1:16
if k~=0
P(r,c)=p^k;
k=k-1;
elseif m~=17
P(r,c)=p^(m-1);
m=m+1;
end;
end;
end;
E=fft2(P);
E=abs(E)/N(1);
N=size(E);
S=0;
for i=1:N(1)
for k=1:N(1)
if i~=k
S=S+E(i,k);
end;
end;
end;
R(l)=(S*100)/(N(1)*(N(1)-1));
l=l+1;
end;
plot(0.1:0.1:0.9,(R/max(R)),'k-.')
hold on
% KLT
l=1;
for p=0.1:0.1:0.9
for r=1:16
k=r-1;
m=1;
for c=1:16
if k~=0
P(r,c)=p^k;
k=k-1;
elseif m~=17
P(r,c)=p^(m-1);
m=m+1;
end;
end;
end;
[K,M]=eig(P);
N=size(M);
S=0;
for i=1:N(1)
for k=1:N(1)
if i~=k
S=S+M(i,k);
end;
end;
end;
R(l)=(S*100)/(N(1)*(N(1)-1));
l=l+1;
end;
plot(0.1:0.1:0.9,(R/max(R)),'c')
hold on
评论0