Mercurial > hg > octave-nkf
annotate scripts/signal/arch_rnd.m @ 10509:ddbd812d09aa
properly compress sparse matrices after assembly
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 12 Apr 2010 12:57:44 +0200 |
parents | 16f53d29049f |
children | a4f482e66b65 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2005, 2006, |
9245 | 2 ## 2007, 2008, 2009 Kurt Hornik |
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 -*- |
3500 | 21 ## @deftypefn {Function File} {} arch_rnd (@var{a}, @var{b}, @var{t}) |
22 ## Simulate an ARCH sequence of length @var{t} with AR | |
3449 | 23 ## coefficients @var{b} and CH coefficients @var{a}. I.e., the result |
3500 | 24 ## @math{y(t)} follows the model |
3191 | 25 ## |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
26 ## @c Set example in small font to prevent overfull line |
7031 | 27 ## @smallexample |
3499 | 28 ## y(t) = b(1) + b(2) * y(t-1) + @dots{} + b(lb) * y(t-lb+1) + e(t), |
7031 | 29 ## @end smallexample |
3449 | 30 ## |
31 ## @noindent | |
3499 | 32 ## where @math{e(t)}, given @var{y} up to time @math{t-1}, is |
33 ## @math{N(0, h(t))}, with | |
3449 | 34 ## |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
35 ## @c Set example in small font to prevent overfull line |
7031 | 36 ## @smallexample |
3499 | 37 ## h(t) = a(1) + a(2) * e(t-1)^2 + @dots{} + a(la) * e(t-la+1)^2 |
7031 | 38 ## @end smallexample |
3449 | 39 ## @end deftypefn |
3191 | 40 |
5428 | 41 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3457 | 42 ## Description: Simulate an ARCH process |
3191 | 43 |
44 function y = arch_rnd (a, b, T) | |
3426 | 45 |
3191 | 46 if (nargin != 3) |
6046 | 47 print_usage (); |
3191 | 48 endif |
3426 | 49 |
3457 | 50 if (! ((min (size (a)) == 1) && (min (size (b)) == 1))) |
51 error ("arch_rnd: a and b must both be scalars or vectors"); | |
3191 | 52 endif |
4030 | 53 if (! (isscalar (T) && (T > 0) && (rem (T, 1) == 0))) |
3457 | 54 error ("arch_rnd: T must be a positive integer"); |
3191 | 55 endif |
3426 | 56 |
3457 | 57 if (! (a(1) > 0)) |
58 error ("arch_rnd: a(1) must be positive"); | |
3191 | 59 endif |
60 ## perhaps add a test for the roots of a(z) here ... | |
3426 | 61 |
3191 | 62 la = length (a); |
63 a = reshape (a, 1, la); | |
64 if (la == 1) | |
65 a = [a, 0]; | |
66 la = la + 1; | |
67 endif | |
7436 | 68 |
3191 | 69 lb = length (b); |
70 b = reshape (b, 1, lb); | |
71 if (lb == 1) | |
72 b = [b, 0]; | |
73 lb = lb + 1; | |
74 endif | |
3238 | 75 M = max([la, lb]); |
3426 | 76 |
3191 | 77 e = zeros (T, 1); |
78 h = zeros (T, 1); | |
79 y = zeros (T, 1); | |
3426 | 80 |
3191 | 81 h(1) = a(1); |
82 e(1) = sqrt (h(1)) * randn; | |
83 y(1) = b(1) + e(1); | |
3426 | 84 |
7436 | 85 for t = 2:M |
3238 | 86 ta = min ([t, la]); |
7436 | 87 h(t) = a(1) + a(2:ta) * e(t-ta+1:t-1).^2; |
3191 | 88 e(t) = sqrt (h(t)) * randn; |
3238 | 89 tb = min ([t, lb]); |
7436 | 90 y(t) = b(1) + b(2:tb) * y(t-tb+1:t-1) + e(t); |
3191 | 91 endfor |
7436 | 92 |
3191 | 93 if (T > M) |
7436 | 94 for t = M+1:T |
95 h(t) = a(1) + a(2:la) * e(t-la+1:t-1).^2; | |
3191 | 96 e(t) = sqrt (h(t)) * randn; |
7436 | 97 y(t) = b(1) + b(2:lb) * y(t-tb+1:t-1) + e(t); |
3191 | 98 endfor |
99 endif | |
3426 | 100 |
3191 | 101 y = y(1:T); |
3426 | 102 |
3191 | 103 endfunction |