7017
|
1 ## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2005, |
|
2 ## 2007 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} {} spectral_xdf (@var{x}, @var{win}, @var{b}) |
|
22 ## Return the spectral density estimator given a data vector @var{x}, |
|
23 ## window name @var{win}, and bandwidth, @var{b}. |
3426
|
24 ## |
3449
|
25 ## The window name, e.g., @code{"triangle"} or @code{"rectangle"} is |
|
26 ## used to search for a function called @code{@var{win}_sw}. |
3426
|
27 ## |
3449
|
28 ## If @var{win} is omitted, the triangle window is used. If @var{b} is |
|
29 ## omitted, @code{1 / sqrt (length (@var{x}))} is used. |
|
30 ## @end deftypefn |
3426
|
31 |
3457
|
32 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
33 ## Description: Spectral density estimation |
3426
|
34 |
3191
|
35 function retval = spectral_xdf (X, win, b) |
3426
|
36 |
3191
|
37 xr = length (X); |
3426
|
38 |
3191
|
39 if (columns (X) > 1) |
|
40 X = X'; |
|
41 endif |
3426
|
42 |
3191
|
43 if (nargin < 3) |
|
44 b = 1 / ceil (sqrt (xr)); |
|
45 endif |
3426
|
46 |
3191
|
47 if (nargin == 1) |
|
48 w = triangle_sw (xr, b); |
|
49 else |
4348
|
50 win = str2func (strcat (win, "_sw")); |
3191
|
51 w = feval (win, xr, b); |
|
52 endif |
3426
|
53 |
3191
|
54 X = X - sum (X) / xr; |
|
55 |
|
56 retval = (abs (fft (X)) / xr).^2; |
|
57 retval = real (ifft (fft(retval) .* fft(w))); |
3426
|
58 |
3238
|
59 retval = [(zeros (xr, 1)), retval]; |
3191
|
60 retval(:, 1) = (0 : xr-1)' / xr; |
3426
|
61 |
3191
|
62 endfunction |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
3426
|
68 |
|
69 |
|
70 |