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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) 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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3191
|
18 |
3449
|
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 ## x(n) = a(1) * x(n-1) + ... + a(k) * x(n-k) |
|
25 ## + e(n) + b(1) * e(n-1) + ... + b(l) * e(n-l) |
|
26 ## @end example |
3191
|
27 ## |
3449
|
28 ## @noindent |
|
29 ## in which @var{k} is the length of vector @var{a}, @var{l} is the |
|
30 ## length of vector @var{b} and @var{e} is gaussian white noise with |
|
31 ## variance @var{v}. The function returns a vector of length @var{t}. |
3191
|
32 ## |
3449
|
33 ## The optional parameter @var{n} gives the number of dummy |
|
34 ## @var{x}(@var{i}) used for initialization, i.e., a sequence of length |
|
35 ## @var{t}+@var{n} is generated and @var{x}(@var{n}+1:@var{t}+@var{n}) |
|
36 ## is returned. If @var{n} is omitted, @var{n} = 100 is used. |
|
37 ## @end deftypefn |
3426
|
38 |
3457
|
39 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
40 ## Description: Simulate an ARMA process |
3191
|
41 |
|
42 function x = arma_rnd (a, b, v, t, n) |
|
43 |
5568
|
44 if (nargin == 4) |
|
45 n = 100; |
|
46 elseif (nargin == 5) |
4030
|
47 if (!isscalar (t)) |
5568
|
48 error ("arma_rnd: n must be a scalar"); |
3191
|
49 endif |
5568
|
50 else |
6046
|
51 print_usage (); |
5568
|
52 endif |
3191
|
53 |
5568
|
54 if ((min (size (a)) > 1) || (min (size (b)) > 1)) |
|
55 error ("arma_rnd: a and b must not be matrices"); |
|
56 endif |
3426
|
57 |
5568
|
58 if (!isscalar (t)) |
|
59 error ("arma_rnd: t must be a scalar"); |
|
60 endif |
3426
|
61 |
5568
|
62 ar = length (a); |
|
63 br = length (b); |
3426
|
64 |
5568
|
65 a = reshape (a, ar, 1); |
|
66 b = reshape (b, br, 1); |
3426
|
67 |
5568
|
68 a = [1; -a]; # apply our notational convention |
|
69 b = [1; b]; |
|
70 |
|
71 n = min (n, ar + br); |
3191
|
72 |
5568
|
73 e = sqrt (v) * randn (t + n, 1); |
|
74 |
|
75 x = filter (b, a, e); |
|
76 x = x(n + 1 : t + n); |
3191
|
77 |
|
78 endfunction |