function L=sremset( law, harmonic)
% L=sremset( law, harmonic)
%
% Hadamard process linear maximal sequences
%

% For AST, set harmonic=3, for all others harmonic=1;

if nargin==1
  % states associated with generator polynomial
  law = [ 1 0 1 1];                % 13 oct
  law = [ 1 0 0 1 1 ];             % 23 oct
  law = [ 1 0 0 1 0 1];            % 45 oct
  law = [ 1 0 0 0 0 1 1];          % 103 oct
  law = [ 1 0 0 0 0 0 1 1];        % 203 oct
  law = [ 1 0 0 0 1 1 1 0 1];      % 435 oct
  law = [ 1 0 0 0 0 1 0 0 0 1];    % 1021 oct
  law = [ 1 0 0 0 0 0 1 1 0 1 1];  % 2033 oct
  harmonic=1;
elseif nargin==2
  harmonic=1;
end

law=law(:);

nr=length(law)-1;             % length of sequence register
L = 2.^nr - 1;                % digits per period
thetamod=-atan(sqrt(L));      % modulation angle
thetamod = -pi/4;             % testing HIFT angle...KM
thetamod=harmonic*thetamod;   % trick for AST 84Hz 3rd harmonic only

% ssrg (simple shift register generator)
G=[ law(2:nr+1)'; [eye(nr-1) zeros(nr-1,1)] ];
Q=zeros(nr,L); Q(1,1)=1;
for il=1:L-1
   Q(:,il+1) = rem(G*Q(:,il),2);
end
Q=[Q(:,L-nr+2:L), Q(:,1:L-nr+1)]; %delay to match KM
Qp=2.^[0:nr-1]*Q;

% msrg (modular shift register generator)
G=[ [zeros(1,nr-1); eye(nr-1)] law(1:nr) ];
P=zeros(nr,L); P(1,1) = 1;
for il=1:L-1
   P(:,il+1)=rem(G*P(:,il),2);
end
Pp=2.^[0:nr-1]*P;

j=sqrt(-1);
u=1/tan(thetamod); v=j;

% integer Hadamard ( faster)

R=[ 0; L];
M=[ u-v/L -u/L-v/L; u-v/L -u/L+v];
M=conj(M); U=M\R;

global sr_L sr_u sr_v sr_Qp sr_Pp sr_U
sr_L=L; sr_u=u; sr_v=v; sr_Qp=Qp; sr_Pp=Pp; sr_U=U;

return












