function [s]=longcode(n)
%  find the long code Sequence of 2^15 or 2^42
%  s=longcode(n), n: length of code
%
%L=15;  % choose L=15 to generate PN code with max length 2^15
L=42;  % choose L=42 to generate PN code with max length 2^42
if L==15,  
   init=ones(1,L);   
   fdbk=[0 0 1 1 1 1 0 0 0 1 1 1 0 0 1];  % feedback shifting register
elseif L==42
   init=[0 ones(1,L-1)];
      fdbk=[1 1 1 0 1 1 1 0 0 1 0 0 0 0 0 ... % feedback shifting register
            1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 ...
            1 0 0 0 1 0 0 0 0 0 0 1];
end
   
s=zeros(1,n+L);
for i=1:n+L                   % generate PN code sequence
  s(i)=init(L);
  f=fdbk*init.';  
  init(2:L)=init(1:L-1);
  init(1)=mod(f,2);
end 
s=s(L+1:n+L);

s=2*s-1;                      % change code to be +/- 1

