function x = rectsig(N,fp,A,offset,duty) % rectsig --> Sum of square wave sequences. % % % x = rectsig(N,fp) % x = rectsig(N,fp,A) % x = rectsig(N,fp,A,offset) % x = rectsig(N,fp,A,offset,duty) % % % Generates an N-vector, which is a sum of K square wave % sequences. The period frequencies are given by the K-vector % fp, where the elements -0.5 < fp(k) < 0.5 are the normalized % period frequencies, i.e., the 'analog' period frequency divided % by the sampling frequency. The K-vector A is the peak values, % and the K-vector offset is the percents in which the periods % are offset from zero. If any of the input arguments fp, A, % and offset is a scalar, then the value will be applied to all % the square wave sequences. The duty cycle, duty, is the % percent of the period in which the signal is positive. % % % sinsig --> Sum of sinusoidal sequences. % trisig --> Sum of sawtooth wave sequences. % % Peter S.K. Hansen, IMM, Technical University of Denmark % % Last revised: February 7, 2000 %----------------------------------------------------------------------- % Check the required input arguments and set defaults. if (nargin < 2) error('Not enough input arguments.') end if (nargin < 3) A = 1; end if (nargin < 4) offset = 0; end if (nargin < 5) duty = 50; end % Make sure that parameter vectors are column vectors. fp = fp(:); A = A(:); offset = offset(:); % Check the lenght of the input arguments. Larg = [length(fp); length(A); length(offset)]; K = max(Larg); if any((Larg ~= 1) & (Larg < K)) error('Vector valued input arguments must have same dimension.') end if (Larg(1) == 1) fp = fp*ones(K,1); end if (Larg(2) == 1) A = A*ones(K,1); end if (Larg(3) == 1) offset = offset*ones(K,1); end % Generate the sequence. x = A'*square(2*pi*fp*(0:N-1) + 2*pi*offset/100*ones(1,N),duty); %----------------------------------------------------------------------- % End of function rectsig %-----------------------------------------------------------------------