Mercurial > octave
annotate scripts/signal/spectral_xdf.m @ 21581:6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
* testfun.txi: Document Octave conventions for use of semicolon in BIST tests.
* cellfun.cc, ellipj.cc, file-io.cc, gcd.cc, hash.cc, nproc.cc,
utils.cc, fftw.cc, ov-usr-fcn.cc, oct-parse.in.yy, md5sum.m, wavread.m, wavwrite.m,
cplxpair.m, rat.m, im2double.m, rref.m, stem3.m, rotate.m, pchip.m, blackman.m,
hamming.m, hanning.m, spectral_adf.m, spectral_xdf.m, assert.m, fail.m,
etime.m, build-sparse-tests.sh, classes.tst, ctor-vs-method.tst, index.tst,
io.tst, struct.tst: Follow Octave conventions for use of semicolon in BIST
tests.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 01 Apr 2016 18:16:01 -0700 |
parents | 516bb87ea72e |
children | bac0d6f07a3e |
rev | line source |
---|---|
19697
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 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3191 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3191 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3191 | 18 |
3449 | 19 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
20 ## @deftypefn {} {} spectral_xdf (@var{x}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
21 ## @deftypefnx {} {} spectral_xdf (@var{x}, @var{win}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
22 ## @deftypefnx {} {} spectral_xdf (@var{x}, @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
|
23 ## Return the spectral density estimator given a data vector @var{x}, window |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
24 ## name @var{win}, and bandwidth, @var{b}. |
3426 | 25 ## |
20165
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
26 ## The window name, e.g., @qcode{"triangle"} or @qcode{"rectangle"} is used to |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
27 ## search for a function called @code{@var{win}_sw}. |
3426 | 28 ## |
20165
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
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:
19833
diff
changeset
|
30 ## |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
31 ## If @var{b} is omitted, @code{1 / sqrt (length (@var{x}))} is used. |
17230
86c45a04990f
spectral_xdf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents:
17229
diff
changeset
|
32 ## @seealso{spectral_adf} |
3449 | 33 ## @end deftypefn |
3426 | 34 |
3457 | 35 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
36 ## Description: Spectral density estimation | |
3426 | 37 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
38 function retval = spectral_xdf (x, win, b) |
3426 | 39 |
17230
86c45a04990f
spectral_xdf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents:
17229
diff
changeset
|
40 if (nargin < 1 || nargin > 3) |
86c45a04990f
spectral_xdf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents:
17229
diff
changeset
|
41 print_usage (); |
86c45a04990f
spectral_xdf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents:
17229
diff
changeset
|
42 endif |
86c45a04990f
spectral_xdf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents:
17229
diff
changeset
|
43 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
44 xr = length (x); |
3426 | 45 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
46 if (columns (x) > 1) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
47 x = x'; |
3191 | 48 endif |
3426 | 49 |
3191 | 50 if (nargin < 3) |
51 b = 1 / ceil (sqrt (xr)); | |
52 endif | |
3426 | 53 |
3191 | 54 if (nargin == 1) |
55 w = triangle_sw (xr, b); | |
17230
86c45a04990f
spectral_xdf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents:
17229
diff
changeset
|
56 elseif (! ischar (win)) |
86c45a04990f
spectral_xdf.m: Add input validation, add %!tests, and fix docstring
Mike Miller <mtmiller@ieee.org>
parents:
17229
diff
changeset
|
57 error ("spectral_xdf: WIN must be a string"); |
3191 | 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 "_sw"]); |
3191 | 60 w = feval (win, xr, b); |
61 endif | |
3426 | 62 |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
63 x -= sum (x) / xr; |
3191 | 64 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
65 retval = (abs (fft (x)) / xr).^2; |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
66 retval = real (ifft (fft (retval) .* fft (w))); |
3426 | 67 |
3238 | 68 retval = [(zeros (xr, 1)), retval]; |
3191 | 69 retval(:, 1) = (0 : xr-1)' / xr; |
3426 | 70 |
3191 | 71 endfunction |
72 | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
73 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
74 ## Test input validation |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
75 %!error spectral_xdf () |
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
76 %!error spectral_xdf (1, 2, 3, 4) |
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
77 %!error spectral_xdf (1, 2) |
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
78 %!error spectral_xdf (1, "invalid") |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
79 |