1 ## Copyright (C) 1995-2012 Friedrich Leisch
3 ## This file is part of Octave.
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.
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.
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/>.
20 ## @deftypefn {Function File} {} arma_rnd (@var{a}, @var{b}, @var{v}, @var{t}, @var{n})
21 ## Return a simulation of the ARMA model
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)
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}.
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.
41 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at>
42 ## Description: Simulate an ARMA process
44 function x = arma_rnd (a, b, v, t, n)
50 error ("arma_rnd: N must be a scalar");
56 if ((min (size (a)) > 1) || (min (size (b)) > 1))
57 error ("arma_rnd: A and B must not be matrices");
61 error ("arma_rnd: T must be a scalar");
67 a = reshape (a, ar, 1);
68 b = reshape (b, br, 1);
70 ## Apply our notational convention.
76 e = sqrt (v) * randn (t + n, 1);