]> Creatis software - CreaPhase.git/blob - octave_packages/signal-1.1.3/square.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / signal-1.1.3 / square.m
1 ## Author: Paul Kienzle <paulkienzle@Avocado.local> (2006)
2 ## This program is granted to the public domain.
3
4 ## -*- texinfo -*-
5 ## @deftypefn {Function File} {@var{s} =} square(@var{t}, @var{duty})
6 ## @deftypefnx {Function File} {@var{s} =} square(@var{t})
7 ## Generate a square wave of period 2 pi with limits +1/-1.
8 ##
9 ## If @var{duty} is specified, the square wave is +1 for
10 ## that portion of the time.
11 ##
12 ## @verbatim
13 ##                     on time
14 ##    duty cycle = ------------------
15 ##                 on time + off time
16 ## @end verbatim
17 ##
18 ## @seealso{cos, sawtooth, sin, tripuls}
19 ## @end deftypefn
20
21 function v = square (t, duty = 0.5)
22
23   if (nargin < 1 || nargin > 2)
24     print_usage;
25   endif
26
27   t /= 2*pi;
28   v = ones(size(t));
29   v(t-floor(t) >= duty) = -1;
30
31 endfunction