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} {} spectral_adf (@var{c}, @var{win}, @var{b}) |
|
19 ## Return the spectral density estimator given a vector of |
|
20 ## autocovariances @var{c}, window name @var{win}, and bandwidth, |
|
21 ## @var{b}. |
3426
|
22 ## |
3449
|
23 ## The window name, e.g., @code{"triangle"} or @code{"rectangle"} is |
|
24 ## used to search for a function called @code{@var{win}_sw}. |
3426
|
25 ## |
3449
|
26 ## If @var{win} is omitted, the triangle window is used. If @var{b} is |
|
27 ## omitted, @code{1 / sqrt (length (@var{x}))} is used. |
|
28 ## @end deftypefn |
3426
|
29 |
3457
|
30 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
31 ## Description: Spectral density estimation |
3426
|
32 |
3191
|
33 function retval = spectral_adf (c, win, b) |
3426
|
34 |
3191
|
35 cr = length (c); |
3426
|
36 |
3191
|
37 if (columns (c) > 1) |
|
38 c=c'; |
|
39 endif |
|
40 |
|
41 if (nargin < 3) |
|
42 b = 1 / ceil (sqrt (cr)); |
|
43 endif |
|
44 |
|
45 if (nargin == 1) |
|
46 w = triangle_lw (cr, b); |
|
47 else |
|
48 win = [win, "_lw"]; |
|
49 w = feval (win, cr, b); |
|
50 endif |
3426
|
51 |
3191
|
52 c = c .* w; |
3426
|
53 |
3191
|
54 retval = 2 * real (fft (c)) - c(1); |
3238
|
55 retval = [(zeros (cr, 1)), retval]; |
3374
|
56 retval(:, 1) = (0 : cr-1)' / cr; |
3426
|
57 |
3191
|
58 endfunction |
|
59 |
|
60 |
3426
|
61 |
|
62 |
|
63 |