annotate scripts/signal/spectral_adf.m @ 31170:06c76eca5f95 default tip @

maint: merge stable to default
author John W. Eaton <jwe@octave.org>
date Fri, 29 Jul 2022 12:02:42 -0400
parents 5d3faba0342e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
2 ##
30569
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29364
diff changeset
3 ## Copyright (C) 1995-2022 The Octave Project Developers
27923
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26379
diff changeset
4 ##
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
7 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
8 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
14 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
15 ## 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
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
19 ##
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
20 ## 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
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
24 ########################################################################
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
25
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
26 ## -*- texinfo -*-
30880
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
27 ## @deftypefn {} {@var{sde} =} spectral_adf (@var{c})
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
28 ## @deftypefnx {} {@var{sde} =} spectral_adf (@var{c}, @var{win})
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
29 ## @deftypefnx {} {@var{sde} =} spectral_adf (@var{c}, @var{win}, @var{b})
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
30 ## 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: 19833
diff changeset
31 ## @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
32 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17231
diff changeset
33 ## 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
34 ## 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
35 ##
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
36 ## 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: 19833
diff changeset
37 ##
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
38 ## 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
39 ## @seealso{spectral_xdf}
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
40 ## @end deftypefn
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
41
30880
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
42 function sde = spectral_adf (c, win, b)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
43
28794
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27989
diff changeset
44 if (nargin < 1)
17231
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
45 print_usage ();
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
46 endif
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
47
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
48 cr = length (c);
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
49
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
50 if (columns (c) > 1)
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7540
diff changeset
51 c = c';
3191
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 < 3)
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
55 b = 1 / ceil (sqrt (cr));
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
56 endif
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
57
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
58 if (nargin == 1)
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
59 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
60 elseif (! ischar (win))
95a402f56b95 spectral_adf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents: 17229
diff changeset
61 error ("spectral_adf: WIN must be a string");
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
62 else
17229
2736bc7bf8d9 Fix syntax error typos in spectral_adf and spectral_xdf (bug #39766)
Mike Miller <mtmiller@ieee.org>
parents: 16994
diff changeset
63 win = str2func ([win "_lw"]);
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
64 w = feval (win, cr, b);
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
65 endif
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
66
20231
83792dd9bcc1 Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents: 20165
diff changeset
67 c .*= w;
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
68
30880
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
69 sde = 2 * real (fft (c)) - c(1);
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
70 sde = [(zeros (cr, 1)), sde];
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
71 sde(:, 1) = (0 : cr-1)' / cr;
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3374
diff changeset
72
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
73 endfunction
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
74
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17281
diff changeset
75
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
76 ## Test input validation
28891
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28794
diff changeset
77 %!error <Invalid call> spectral_adf ()
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28794
diff changeset
78 %!error <WIN must be a string> spectral_adf (1, 2)
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28794
diff changeset
79 %!error <unable to find function for @invalid_lw> spectral_adf (1, "invalid")