3191
|
1 ## Copyright (C) 1995, 1996, 1997 Friedrich Leisch |
|
2 ## |
|
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. |
|
7 ## |
|
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 |
|
11 ## General Public License for more details. |
|
12 ## |
|
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 |
|
17 ## usage: retval = spectral_adf (c, [win, [b]]) |
|
18 ## |
|
19 ## Returns the spectral density estimator. |
|
20 ## c ....... vector of autocovariances (starting at lag 0) |
|
21 ## win ..... window name, eg. "triangle" or "rectangle" |
|
22 ## spectral_adf searches for a function called win_lw () |
|
23 ## b ....... bandwidth |
|
24 ## |
|
25 ## If win is omitted, the triangle window is used as default. |
|
26 ## If b is omitted, 1 / sqrt( length (c)) is used as default. |
|
27 |
|
28 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
29 ## Description: Spectral density estimation |
|
30 |
|
31 function retval = spectral_adf (c, win, b) |
|
32 |
|
33 cr = length (c); |
|
34 |
|
35 if (columns (c) > 1) |
|
36 c=c'; |
|
37 endif |
|
38 |
|
39 if (nargin < 3) |
|
40 b = 1 / ceil (sqrt (cr)); |
|
41 endif |
|
42 |
|
43 if (nargin == 1) |
|
44 w = triangle_lw (cr, b); |
|
45 else |
|
46 win = [win, "_lw"]; |
|
47 w = feval (win, cr, b); |
|
48 endif |
|
49 |
|
50 c = c .* w; |
|
51 |
|
52 retval = 2 * real (fft (c)) - c(1); |
|
53 retval = [zeros (cr, 1) retval]; |
|
54 retval(:, 1) = (0 : xr-1)' / xr; |
|
55 |
|
56 endfunction |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |