X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fsignal-1.1.3%2Fsquare.m;fp=octave_packages%2Fsignal-1.1.3%2Fsquare.m;h=4051cce699538783249d9ee110de858795b1b66a;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/signal-1.1.3/square.m b/octave_packages/signal-1.1.3/square.m new file mode 100644 index 0000000..4051cce --- /dev/null +++ b/octave_packages/signal-1.1.3/square.m @@ -0,0 +1,31 @@ +## Author: Paul Kienzle (2006) +## This program is granted to the public domain. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{s} =} square(@var{t}, @var{duty}) +## @deftypefnx {Function File} {@var{s} =} square(@var{t}) +## Generate a square wave of period 2 pi with limits +1/-1. +## +## If @var{duty} is specified, the square wave is +1 for +## that portion of the time. +## +## @verbatim +## on time +## duty cycle = ------------------ +## on time + off time +## @end verbatim +## +## @seealso{cos, sawtooth, sin, tripuls} +## @end deftypefn + +function v = square (t, duty = 0.5) + + if (nargin < 1 || nargin > 2) + print_usage; + endif + + t /= 2*pi; + v = ones(size(t)); + v(t-floor(t) >= duty) = -1; + +endfunction