Mercurial > hg > octave-lyh
annotate scripts/signal/spectral_xdf.m @ 14495:319660795df1
Fix gnuplot error when color values are within eps of each other (bug #35761).
* plot/private/__go_draw_axes__.m: Use %.15e for setting cbrange in gnuplot.
author | Marco Caliari <marco.caliari@univr.it> |
---|---|
date | Sun, 25 Mar 2012 13:53:39 -0700 |
parents | 72c96de7a403 |
children | 5d3a684236b0 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1 ## Copyright (C) 1995-2012 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 -*- |
20 ## @deftypefn {Function File} {} spectral_xdf (@var{x}, @var{win}, @var{b}) | |
21 ## Return the spectral density estimator given a data vector @var{x}, | |
22 ## window name @var{win}, and bandwidth, @var{b}. | |
3426 | 23 ## |
3449 | 24 ## The window name, e.g., @code{"triangle"} or @code{"rectangle"} is |
25 ## used to search for a function called @code{@var{win}_sw}. | |
3426 | 26 ## |
3449 | 27 ## If @var{win} is omitted, the triangle window is used. If @var{b} is |
28 ## omitted, @code{1 / sqrt (length (@var{x}))} is used. | |
29 ## @end deftypefn | |
3426 | 30 |
3457 | 31 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
32 ## Description: Spectral density estimation | |
3426 | 33 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
34 function retval = spectral_xdf (x, win, b) |
3426 | 35 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
36 xr = length (x); |
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 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
|
39 x = x'; |
3191 | 40 endif |
3426 | 41 |
3191 | 42 if (nargin < 3) |
43 b = 1 / ceil (sqrt (xr)); | |
44 endif | |
3426 | 45 |
3191 | 46 if (nargin == 1) |
47 w = triangle_sw (xr, b); | |
48 else | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7017
diff
changeset
|
49 win = str2func (cstrcat (win, "_sw")); |
3191 | 50 w = feval (win, xr, b); |
51 endif | |
3426 | 52 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
53 x = x - sum (x) / xr; |
3191 | 54 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
55 retval = (abs (fft (x)) / xr).^2; |
3191 | 56 retval = real (ifft (fft(retval) .* fft(w))); |
3426 | 57 |
3238 | 58 retval = [(zeros (xr, 1)), retval]; |
3191 | 59 retval(:, 1) = (0 : xr-1)' / xr; |
3426 | 60 |
3191 | 61 endfunction |
62 |