% function that generates a gold code of length 127 chips 
% with samp_chip samples per chip 



function code=gold1(samp_chip)

g11=[1 1 1 1 1 1 1];
g12=[1 1 1 1 1 1 1];

for i=1:8

   aux1=rem(g11(2)+g11(5)+g11(6)+g11(7),2);
   aux2=rem(g12(1)+g12(3)+g12(6)+g12(7),2);
   g11(2:7)=g11(1:6);
   g12(2:7)=g12(1:6);
   g11(1)=aux1;
   g12(1)=aux2;

end



for i=1:8
   aux=rem(g12(2)+g12(3)+g12(4)+g12(7),2);
   g12(2:7)=g12(1:6);
   g12(1)=aux;

end

for i=1:127

   code((i-1)*samp_chip+1:i*samp_chip)=ones(1,samp_chip)*rem(g11(7)+g12(7),2); 

   aux1=rem(g11(1)+g11(2)+g11(3)+g11(7),2);
   aux2=rem(g12(2)+g12(3)+g12(4)+g12(7),2);
   g11(2:7)=g11(1:6);
   g12(2:7)=g12(1:6);
   g11(1)=aux1;
   g12(1)=aux2;

end
code=code*2-1;