]> Creatis software - CreaPhase.git/blob - octave_packages/m/signal/arma_rnd.m
update packages
[CreaPhase.git] / octave_packages / m / signal / arma_rnd.m
1 ## Copyright (C) 1995-2012 Friedrich Leisch
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} arma_rnd (@var{a}, @var{b}, @var{v}, @var{t}, @var{n})
21 ## Return a simulation of the ARMA model
22 ##
23 ## @example
24 ## @group
25 ## x(n) = a(1) * x(n-1) + @dots{} + a(k) * x(n-k)
26 ##      + e(n) + b(1) * e(n-1) + @dots{} + b(l) * e(n-l)
27 ## @end group
28 ## @end example
29 ##
30 ## @noindent
31 ## in which @var{k} is the length of vector @var{a}, @var{l} is the
32 ## length of vector @var{b} and @var{e} is Gaussian white noise with
33 ## variance @var{v}.  The function returns a vector of length @var{t}.
34 ##
35 ## The optional parameter @var{n} gives the number of dummy
36 ## @var{x}(@var{i}) used for initialization, i.e., a sequence of length
37 ## @var{t}+@var{n} is generated and @var{x}(@var{n}+1:@var{t}+@var{n})
38 ## is returned.  If @var{n} is omitted, @var{n} = 100 is used.
39 ## @end deftypefn
40
41 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at>
42 ## Description: Simulate an ARMA process
43
44 function x = arma_rnd (a, b, v, t, n)
45
46   if (nargin == 4)
47     n = 100;
48   elseif (nargin == 5)
49     if (!isscalar (n))
50       error ("arma_rnd: N must be a scalar");
51     endif
52   else
53     print_usage ();
54   endif
55
56   if ((min (size (a)) > 1) || (min (size (b)) > 1))
57     error ("arma_rnd: A and B must not be matrices");
58   endif
59
60   if (!isscalar (t))
61     error ("arma_rnd: T must be a scalar");
62   endif
63
64   ar = length (a);
65   br = length (b);
66
67   a = reshape (a, ar, 1);
68   b = reshape (b, br, 1);
69
70   ## Apply our notational convention.
71   a = [1; -a];
72   b = [1; b];
73
74   n = min (n, ar + br);
75
76   e = sqrt (v) * randn (t + n, 1);
77
78   x = filter (b, a, e);
79   x = x(n + 1 : t + n);
80
81 endfunction