3191
|
1 ## Copyright (C) 1995, 1996, 1997 Friedrich Leisch |
3426
|
2 ## |
3191
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
3426
|
7 ## |
3191
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
11 ## General Public License for more details. |
|
12 ## |
3191
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this file. If not, write to the Free Software Foundation, |
|
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
16 |
3449
|
17 ## -*- texinfo -*- |
|
18 ## @deftypefn {Function File} {[@var{a}, @var{v}] =} yulewalker (@var{c}) |
|
19 ## Fit an AR (p)-model with Yule-Walker estimates given a vector @var{c} |
|
20 ## of autocovariances @code{[gamma_0, ..., gamma_p]}. |
3426
|
21 ## |
3449
|
22 ## Returns the AR coefficients, @var{a}, and the variance of white |
|
23 ## noise, @var{v}. |
|
24 ## @end deftypefn |
3426
|
25 |
3457
|
26 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
27 ## Description: Fit AR model by Yule-Walker method |
3426
|
28 |
3191
|
29 function [a, v] = yulewalker (c) |
3426
|
30 |
3191
|
31 p = length (c) - 1; |
3426
|
32 |
3191
|
33 if (columns (c) > 1) |
|
34 c = c'; |
|
35 endif |
3426
|
36 |
3191
|
37 cp = c(2 : p+1); |
|
38 CP = zeros(p, p); |
3426
|
39 |
3191
|
40 for i = 1:p |
|
41 for j = 1:p |
|
42 CP (i, j) = c (abs (i-j) + 1); |
|
43 endfor |
|
44 endfor |
3426
|
45 |
3191
|
46 a = inv (CP) * cp; |
|
47 v = c(1) - a' * cp; |
3426
|
48 |
3191
|
49 endfunction |
|
50 |
|
51 |
3426
|
52 |
|
53 |
|
54 |