%This uses correlation and MLE to classify a noisy bank digit as one of digits 0...9.
%It's hard to tell the noisy digit Y is a 3. Note MLE works better than correlation.
clear;load bank.mat;sigma=200;
%Each digit XX(:,:,?) is a 30X18 portion of X. (XX is a 3D array).
%XX(:,:,?) represents digit ?. (XX(:,:,10) represents 0). Noisy digit Y is 3.
XX(:,:,1)=X(:,17:34);XX(:,:,2)=X(:,50:67);XX(:,:,3)=X(:,78:95);
XX(:,:,4)=X(:,111:128);XX(:,:,5)=X(:,140:157);XX(:,:,6)=X(:,170:187);
XX(:,:,7)=X(:,202:219);XX(:,:,8)=X(:,232:249);XX(:,:,9)=X(:,262:279);
XX(:,:,10)=X(:,292:309);N=sigma*randn(30,18);Y=XX(:,:,3)+N;
figure,imagesc(Y),axis off,colormap(gray),title('Noisy digit g[n,m]')
for k=1:10;R(k)=sum(sum(Y.*XX(:,:,k)));
MLE(k)=2*R(k)-sum(sum(XX(:,:,k).*XX(:,:,k)));end;
figure,subplot(211),stem([0:9],[R(10) R(1:9)]),...
title('Correlation \rho_k between noisy digit Y and digit k')
subplot(212),stem([0:9],[MLE(10) MLE(1:9)]),...
title('MLE criterion \Lambda[k] between noisy digit Y and digit k')


