Mercurial > hg > octave-nkf
annotate scripts/signal/arma_rnd.m @ 9051:1bf0ce0930be
Grammar check TexInfo in all .m files
Cleanup documentation sources to follow a few consistent rules.
Spellcheck was NOT done. (but will be in another changeset)
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Fri, 27 Mar 2009 22:31:03 -0700 |
parents | eb63fbe60fab |
children | bd8e388043c4 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2003, 2005, 2006, |
8920 | 2 ## 2007, 2009 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 | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## @group |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
26 ## x(n) = a(1) * x(n-1) + @dots{} + a(k) * x(n-k) |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
27 ## + e(n) + b(1) * e(n-1) + @dots{} + b(l) * e(n-l) |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
28 ## @end group |
3449 | 29 ## @end example |
3191 | 30 ## |
3449 | 31 ## @noindent |
32 ## in which @var{k} is the length of vector @var{a}, @var{l} is the | |
33 ## length of vector @var{b} and @var{e} is gaussian white noise with | |
34 ## variance @var{v}. The function returns a vector of length @var{t}. | |
3191 | 35 ## |
3449 | 36 ## The optional parameter @var{n} gives the number of dummy |
37 ## @var{x}(@var{i}) used for initialization, i.e., a sequence of length | |
38 ## @var{t}+@var{n} is generated and @var{x}(@var{n}+1:@var{t}+@var{n}) | |
39 ## is returned. If @var{n} is omitted, @var{n} = 100 is used. | |
40 ## @end deftypefn | |
3426 | 41 |
3457 | 42 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
43 ## Description: Simulate an ARMA process | |
3191 | 44 |
45 function x = arma_rnd (a, b, v, t, n) | |
46 | |
5568 | 47 if (nargin == 4) |
48 n = 100; | |
49 elseif (nargin == 5) | |
4030 | 50 if (!isscalar (t)) |
5568 | 51 error ("arma_rnd: n must be a scalar"); |
3191 | 52 endif |
5568 | 53 else |
6046 | 54 print_usage (); |
5568 | 55 endif |
3191 | 56 |
5568 | 57 if ((min (size (a)) > 1) || (min (size (b)) > 1)) |
58 error ("arma_rnd: a and b must not be matrices"); | |
59 endif | |
3426 | 60 |
5568 | 61 if (!isscalar (t)) |
62 error ("arma_rnd: t must be a scalar"); | |
63 endif | |
3426 | 64 |
5568 | 65 ar = length (a); |
66 br = length (b); | |
3426 | 67 |
5568 | 68 a = reshape (a, ar, 1); |
69 b = reshape (b, br, 1); | |
3426 | 70 |
8506 | 71 ## Apply our notational convention. |
72 a = [1; -a]; | |
5568 | 73 b = [1; b]; |
74 | |
75 n = min (n, ar + br); | |
3191 | 76 |
5568 | 77 e = sqrt (v) * randn (t + n, 1); |
78 | |
79 x = filter (b, a, e); | |
80 x = x(n + 1 : t + n); | |
3191 | 81 |
82 endfunction |