3191
|
1 ## Copyright (C) 1995, 1996, 1997 Friedrich Leisch |
3426
|
2 ## |
3922
|
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 |
3191
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
3426
|
9 ## |
3922
|
10 ## Octave is distributed in the hope that it will be useful, but |
3191
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
13 ## General Public License for more details. |
|
14 ## |
3191
|
15 ## You should have received a copy of the GNU General Public License |
3922
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
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 |
4460
|
45 save_warn_empty_list_elements = warn_empty_list_elements; |
3191
|
46 unwind_protect |
4460
|
47 warn_empty_list_elements = 0; |
3426
|
48 |
3191
|
49 if (nargin == 4) |
|
50 n = 100; |
|
51 elseif (nargin == 5) |
4030
|
52 if (!isscalar (t)) |
3426
|
53 error ("arma_rnd: n must be a scalar"); |
3191
|
54 endif |
|
55 else |
3449
|
56 usage ("arma_rnd (a, b, v, t, n)"); |
3191
|
57 endif |
|
58 |
3457
|
59 if ((min (size (a)) > 1) || (min (size (b)) > 1)) |
|
60 error ("arma_rnd: a and b must not be matrices"); |
3191
|
61 endif |
3426
|
62 |
4030
|
63 if (!isscalar (t)) |
3457
|
64 error ("arma_rnd: t must be a scalar"); |
3191
|
65 endif |
3426
|
66 |
3191
|
67 ar = length (a); |
|
68 br = length (b); |
|
69 |
|
70 a = reshape (a, ar, 1); |
|
71 b = reshape (b, br, 1); |
3426
|
72 |
|
73 a = [1; -a]; # apply our notational convention |
3191
|
74 b = [1; b]; |
3426
|
75 |
3191
|
76 n = min (n, ar + br); |
3426
|
77 |
3191
|
78 e = sqrt (v) * randn (t + n, 1); |
3426
|
79 |
3191
|
80 x = filter (b, a, e); |
|
81 x = x(n + 1 : t + n); |
|
82 |
|
83 unwind_protect_cleanup |
4460
|
84 warn_empty_list_elements = save_warn_empty_list_elements; |
3191
|
85 end_unwind_protect |
|
86 |
|
87 endfunction |