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