1;

clear;

bCode=[+1,+1,+1,+1,+1,-1,-1,+1,+1,-1,+1,-1,+1]; #Barker-Code

function [retval] = korrelation (pattern, signal)
  for i = 0:length(signal)
    retval(end+1) = corr(shift(pattern, i-(floor(length(pattern)/2))), signal);
  endfor
endfunction

function [encoded] = manchester_encode(source)
  encoded = [];
  for i=1:length(source)
    encoded(2*i - 1) = (source(i) == 1);
    encoded(2*i) = (source(i) == 0);
  end
endfunction

#Manchestercodierter bCode
mCode = manchester_encode(bCode);

subplot(2,1,1);
plot (korrelation(bCode, bCode));
title("Autokorrelation Barker");
grid on;

subplot(2,1,2);
plot(korrelation(mCode, mCode));
title("Autokorrelation Manchester(Barker)");
grid on;

print ("png","Autokorrelation.png");