% funtion to generate samples of LMS modulated waveform
%
% seqgen(law, Q, angle, sam_cyc, VonC, N, sw)
%
%   Function to generate sample values of sequence modulated waveforms
%
% law = sequence law written as if it were an octal value
% Q   = number of carrier cycles per sequence bit
% angle = modulation angle +- from zero degrees .. in degrees
% sam_cyc =  number of samples per carrier cycle
% VonC    =  velocity/speed_of_sound
% N       =  number of values to produce
% sw      = -1     samples of negative freq complex exponential .. complex
%         =  0     samples of modulated cosine waveform .. real 
%         =  1     samples of positive freq complex exponential .. complex
%         =  2     samples of complex baseband waveform .. complex
%         =  else  samples of hard clipped modulated cosine waveform .. real
%
% All values derived from unit magnitude cosine wave.  This means that the
% positive and negative frequency components are magnitude 1/2.
%
% KM 5/08/97
% KM 5/14/00  added Doppler
% KM 3/04/01  updated comments

function [samples]=seqgen(law, Q, angle, sam_cyc, VonC, N, sw)
bits=seq(law);
Lseq=length(bits);
if angle>180
   angle=atan(sqrt(Lseq));
else
   angle=angle*pi/180.0;
end
index = [0:N-1]'*(1+VonC);
samples = (2*bits(floor(mod(index/(sam_cyc*Q), Lseq)+1))-1)*angle;
if sw == -1
   samples=j*exp(-j*(2*pi*index/sam_cyc-samples))/2;
elseif sw == 0
   samples=cos(2*pi*index/sam_cyc+samples);
elseif sw == 1
   samples=exp(j*(2*pi*index/sam_cyc+samples))/2;
elseif sw == 2
   samples=exp(j*samples);
else
   samples=sign(cos(2*pi*index/sam_cyc+samples));
end