You are on page 1of 5

A=['.' '.' '.' '#' '.' '.' '.';'.' '.' '.' '#' '.' '.' '.';...

'.' '.' '#' '.' '#' '.' '.';'.' '.' '#' '.' '#' '.' '.';...
'.' '.' '#' '#' '#' '.' '.';'.' '#' '.' '.' '.' '#' '.';...
'.' '#' '.' '.' '.' '#' '.';'#' '.' '.' '.' '.' '.' '#';...
'#' '.' '.' '.' '.' '.' '#'];
B=['#' '#' '#' '#' '#' '.' '.';'#' '.' '.' '.' '.' '#' '.';...
'#' '.' '.' '.' '.' '.' '#';'#' '.' '.' '.' '.' '#' '.';...
'#' '#' '#' '#' '#' '.' '.';'#' '.' '.' '.' '.' '#' '.';...
'#' '.' '.' '.' '.' '.' '#';'#' '.' '.' '.' '.' '#' '.';...
'#' '#' '#' '#' '#' '.' '.'];
C=['.' '.' '#' '#' '#' '.' '.';'.' '#' '.' '.' '.' '#' '.';...
'#' '.' '.' '.' '.' '.' '#';'#' '.' '.' '.' '.' '.' '.';...
'#' '.' '.' '.' '.' '.' '.';'#' '.' '.' '.' '.' '.' '.';...
'#' '.' '.' '.' '.' '.' '#';'.' '#' '.' '.' '.' '#' '.';...
'.' '.' '#' '#' '#' '.' '.'];
A1 = ['.' '.' '.' '#' '.' '.' '.' '.' '.' '.' '#' '.' '.' '.' ...
'.' '.' '#' '.' '#' '.' '.' '.' '.' '#' '.' '#' '.' '.' ...
'.' '.' '#' '#' '#' '.' '.' '.' '#' '.' '.' '.' '#' '.' ...
'.' '#' '.' '.' '.' '#' '.' '#' '.' '.' '.' '.' '.' '#' ...
'#' '.' '.' '.' '.' '.' '#'];
B1=['#' '#' '#' '#' '#' '.' '.' '#' '.' '.' '.' '.' '#' '.' ...
'#' '.' '.' '.' '.' '.' '#' '#' '.' '.' '.' '.' '#' '.' ...
'#' '#' '#' '#' '#' '.' '.' '#' '.' '.' '.' '.' '#' '.' ...
'#' '.' '.' '.' '.' '.' '#' '#' '.' '.' '.' '.' '#' '.' ...
'#' '#' '#' '#' '#' '.' '.'];
C1=['.' '.' '#' '#' '#' '.' '.' '.' '#' '.' '.' '.' '#' '.' ...
'#' '.' '.' '.' '.' '.' '#' '#' '.' '.' '.' '.' '.' '.' ...
'#' '.' '.' '.' '.' '.' '.' '#' '.' '.' '.' '.' '.' '.' ...
'#' '.' '.' '.' '.' '.' '#' '.' '#' '.' '.' '.' '#' '.' ...
'.' '.' '#' '#' '#' '.' '.'];
A3=['.' '.' '#' '#' '.' '#' '.';'.' '#' '.' '#' '#' '.' '.';...
'#' '.' '#' '#' '#' '.' '#';'.' '.' '.' '.' '#' '#' '.';...
'.' '#' '#' '#' '.' '.' '.';'#' '#' '.' '#' '.' '#' '#';...
'.' '#' '#' '.' '.' '.' '.';'#' '#' '.' '.' '#' '.' '#';...
'.' '.' '.' '#' '.' '.' '.'];
B3=['.'
'#'
'#'
'.'
'#'

'#'
'#'
'#'
'.'
'.'

'#'
'.'
'.'
'.'
'#'

'.'
'.'
'#'
'#'
'#'

'#'
'#'
'#'
'.'
'.'

'.'
'.'
'#'
'.'
'.'

'.';'#'
'#';'.'
'.';'#'
'.';'#'
'.'];

'.'
'.'
'#'
'.'

'#'
'.'
'.'
'#'

'.'
'#'
'.'
'.'

'.'
'.'
'.'
'.'

'.'
'.'
'.'
'.'

'.';...
'.';...
'.';...
'.';...

C3=['#'
'#'
'#'
'.'
'.'

'.'
'#'
'.'
'.'
'#'

'#'
'.'
'#'
'.'
'#'

'.'
'.'
'.'
'#'
'#'

'#'
'#'
'.'
'.'
'.'

'.'
'.'
'#'
'.'
'.'

'#';'.'
'#';'.'
'.';'#'
'.';'.'
'.'];

'#'
'.'
'#'
'#'

'#'
'.'
'.'
'#'

'.'
'#'
'.'
'.'

'.'
'.'
'#'
'.'

'.'
'.'
'.'
'.'

'.';...
'#';...
'.';...
'.';...

A1 = double(A1);
B1 = double(B1);
C1 = double(C1);
for i=1:63
if A1(i)==35
A1(i)=1;
else
A1(i)=-1;

end
end
for i=1:63
if B1(i)==35
B1(i)=1;
else
B1(i)=-1;
end
end
for i=1:63
if C1(i)==35
C1(i)=1;
else
C1(i)=-1;
end
end

yA1=['.' '#' '.' '#' '.' '#' '#' '#' '#' '#' '.' '#' '#' '.' '#'];
yB1=['#' '#' '.' '#' '.' '#' '#' '#' '.' '#' '.' '#' '#' '#' '.'];
yC1=['#' '#' '#' '#' '.' '.' '#' '#' '#' '#' '#' '#' '#' '#' '#'];
yA1 = double(yA1);
yB1 = double(yB1);
yC1 = double(yC1);

for i=1:15
if yA1(i)==35
yA1(i)=1;
else
yA1(i)=-1;
end
end
for i=1:15
if yB1(i)==35
yB1(i)=1;
else
yB1(i)=-1;
end
end
for i=1:15
if yC1(i)==35
yC1(i)=1;
else
yC1(i)=-1;
end

end
wA = A1'*yA1;
wB = B1'*yB1;
wC = C1'*yC1;
w = wA+wB+wC;
disp('The weight matrix is initialised...');
disp('Testing on original input vectors...');
disp('Given input A:');
disp(A);
result = A1*w;
for i=1:15
if result(i)>0
result(i)=1;
else
result(i)=-1;
end
end
%result
if result==yA1
disp('A is recognized');
disp(A);
else
disp('Not recognized');
end
disp('Given input B:');
result = B1*w;
for i=1:15
if result(i)>0
result(i)=1;
else
result(i)=-1;
end
end
%result
if result==yB1
disp('B is recognized');
disp(B);
else
disp('Not recognized');
end

disp('Given input C:');


result = C1*w;
for i=1:15
if result(i)>0
result(i)=1;
else
result(i)=-1;
end
end

%result
if result==yC1
disp('C is recognized');
disp(C);
else
disp('Not recognized');
end
disp('Now, testing on noisy versions of A,B and C');

A31=['.' '.' '#' '#' '.' '#' '.' '.' '#' '.' '#' '#' '.' '.' ...
'#' '.' '#' '#' '#' '.' '#' '.' '.' '.' '.' '#' '#' '.' ...
'.' '#' '#' '#' '.' '.' '.' '#' '#' '.' '#' '.' '#' '#' ...
'.' '#' '#' '.' '.' '.' '.' '#' '#' '.' '.' '#' '.' '#' ...
'.' '.' '.' '#' '.' '.' '.'];
B31=['.' '#' '#' '.' '#' '.' '.' '#' '.' '#' '.' '.' '.' '.' ...
'#' '#' '.' '.' '#' '.' '#' '.' '.' '.' '#' '.' '.' '.' ...
'#' '#' '.' '#' '#' '#' '.' '#' '#' '.' '.' '.' '.' '.' ...
'.' '.' '.' '#' '.' '.' '.' '#' '.' '#' '.' '.' '.' '.' ...
'#' '.' '#' '#' '.' '.' '.'];
C31=['#' '.' '#' '.' '#' '.' '#' '.' '#' '#' '.' '.' '.' '.' ...
'#' '#' '.' '.' '#' '.' '#' '.' '.' '.' '#' '.' '.' '#' ...
'#' '.' '#' '.' '.' '#' '.' '#' '#' '.' '.' '#' '.' '.' ...
'.' '.' '.' '#' '.' '.' '.' '.' '#' '#' '.' '.' '.' '.' ...
'.' '#' '#' '#' '.' '.' '.'];
A31 = double(A31);
B31 = double(B31);
C31 = double(C31);
A31 = bipolar(A31);
B31 = bipolar(B31);
C31 = bipolar(C31);
disp('Given input noisy version of A:');
disp(A3);
result = A31*w;
for i=1:15
if result(i)>0
result(i)=1;
else
result(i)=-1;
end
end
if result==yA1
disp('Recognized as ');
disp(A);
else
disp('Not recognized');
end
disp('Given input noisy version of B:');
disp(B3);
result = B31*w;

for i=1:15
if result(i)>0
result(i)=1;
else
result(i)=-1;
end
end
if result==yB1
disp('Recognized as ');
disp(B);
else
disp('Not recognized');
end
disp('Given input noisy version of C:');
disp(C3);
result = C31*w;
for i=1:15
if result(i)>0
result(i)=1;
else
result(i)=-1;
end
end
if result==yC1
disp('Recognized as :');
disp(C);
else
disp('Not recognized');
end

You might also like