clear;
%
% This program implement the 1-D counter example to Julesz's Conjecture
%
sup=3;
n=0:1:sup;
a=4*n.*n;
b=4*n.*n+n+1;
m1=a+b(1);
m2=a-b(1);
for i=2:sup+1
   m1=[m1 a+b(i)];
   m2=[m2 a-b(i)];
end;
m1=sort(m1);
m1=m1-m1(1);
mm1=m1+1;
m2=sort(m2);
m2=m2-m2(1);
mm2=m2+1;

%% 1-D case
i1=zeros(1,80);
i2=zeros(1,80);
for i=1:length(m1)
   i1(mm1(i))=1;
   i2(mm2(i))=1;
end;
r1=AutoCorr(i1);
r2=AutoCorr(i2);
if (r1-r2==zeros(80,1))
   AutoCorrEqual=1
else
   AutoCorrEqual=0
end;

% create bar-code like image 
I1=zeros(4,80);
I2=zeros(4,80);
for i=1:length(mm1)
   I1(1:4,mm1(i))=ones(4,1);
   I2(1:4,mm2(i))=ones(4,1);
end;

R1=AutoCorr2(I1);
R2=AutoCorr2(I2);
if (R1-R2==zeros(4,80))
   AutoCorr2Equal=1
else
   AutoCorr2Equal=0
end;
 
II1=zeros(64,80);
II2=zeros(64,80);
for i=1:length(mm1)
   II1(1:64,mm1(i))=ones(64,1);
   II2(1:64,mm2(i))=ones(64,1);
end;
 
figure(1);
subplot(2,1,1);
AutoImage(II1);
subplot(2,1,2);
AutoImage(II2);
