annotate scripts/signal/spectral_adf.m @ 20815:a260a6acb70f

fix test failures introduced by a22d8a2eb0e5 * scripts/ode/private/integrate_adaptive.m: fix stepping backwards, fix invocation of OutputFcn, fix text of some error messages * scripts/ode/private/integrate_const.m: remove use of option OutputSave * scripts/ode/private/integrate_n_steps.m: remove use of option OutputSave
author Carlo de Falco <carlo.defalco@polimi.it>
date Sun, 11 Oct 2015 23:09:01 +0200
parents 83792dd9bcc1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19898
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
1 ## Copyright (C) 1995-2015 Friedrich Leisch
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
2 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
3 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
4 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
8 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
9 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
13 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
14 ##
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
18
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
19 ## -*- texinfo -*-
17231
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
20 ## @deftypefn {Function File} {} spectral_adf (@var{c})
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
21 ## @deftypefnx {Function File} {} spectral_adf (@var{c}, @var{win})
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
22 ## @deftypefnx {Function File} {} spectral_adf (@var{c}, @var{win}, @var{b})
20375
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20038
diff changeset
23 ## Return the spectral density estimator given a vector of autocovariances
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20038
diff changeset
24 ## @var{c}, window name @var{win}, and bandwidth, @var{b}.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
25 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17231
diff changeset
26 ## The window name, e.g., @qcode{"triangle"} or @qcode{"rectangle"} is
17231
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
27 ## used to search for a function called @code{@var{win}_lw}.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
28 ##
20375
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20038
diff changeset
29 ## If @var{win} is omitted, the triangle window is used.
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20038
diff changeset
30 ##
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20038
diff changeset
31 ## If @var{b} is omitted, @code{1 / sqrt (length (@var{x}))} is used.
17231
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
32 ## @seealso{spectral_xdf}
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
33 ## @end deftypefn
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
34
3457
e031284eea27 [project @ 2000-01-19 08:49:56 by jwe]
jwe
parents: 3449
diff changeset
35 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at>
e031284eea27 [project @ 2000-01-19 08:49:56 by jwe]
jwe
parents: 3449
diff changeset
36 ## Description: Spectral density estimation
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
37
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
38 function retval = spectral_adf (c, win, b)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
39
17231
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
40 if (nargin < 1 || nargin > 3)
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
41 print_usage ();
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
42 endif
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
43
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
44 cr = length (c);
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
45
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
46 if (columns (c) > 1)
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7540
diff changeset
47 c = c';
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
48 endif
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
49
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
50 if (nargin < 3)
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
51 b = 1 / ceil (sqrt (cr));
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
52 endif
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
53
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
54 if (nargin == 1)
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
55 w = triangle_lw (cr, b);
17231
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
56 elseif (! ischar (win))
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
57 error ("spectral_adf: WIN must be a string");
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
58 else
17229
2736bc7bf8d9 Fix syntax error typos in spectral_adf and spectral_xdf (bug #39766)
Mike Miller <mtmiller@ieee.org>
parents: 16994
diff changeset
59 win = str2func ([win "_lw"]);
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
60 w = feval (win, cr, b);
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
61 endif
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
62
20441
83792dd9bcc1 Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents: 20375
diff changeset
63 c .*= w;
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
64
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
65 retval = 2 * real (fft (c)) - c(1);
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3191
diff changeset
66 retval = [(zeros (cr, 1)), retval];
3374
89405d9a9b0b [project @ 1999-12-08 06:58:04 by jwe]
jwe
parents: 3238
diff changeset
67 retval(:, 1) = (0 : cr-1)' / cr;
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
68
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
69 endfunction
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
70
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17281
diff changeset
71
20038
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19898
diff changeset
72 ## Test input validation
17231
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
73 %!error spectral_adf ();
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
74 %!error spectral_adf (1, 2, 3, 4);
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
75 %!error spectral_adf (1, 2);
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
76 %!error spectral_adf (1, "invalid");
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17281
diff changeset
77