Mercurial > octave-dspies
annotate scripts/signal/periodogram.m @ 17174:c3c1ebfaa7dc
maint: Use common indentation for switch statement.
* scripts/general/interp1.m, scripts/geometry/delaunay.m,
scripts/help/__unimplemented__.m, scripts/image/cmunique.m,
scripts/miscellaneous/edit.m, scripts/optimization/fzero.m,
scripts/optimization/sqp.m, scripts/plot/__gnuplot_drawnow__.m,
scripts/plot/hidden.m, scripts/plot/legend.m, scripts/plot/print.m,
scripts/plot/printd.m, scripts/plot/private/__contour__.m,
scripts/plot/private/__fltk_print__.m,
scripts/plot/private/__gnuplot_print__.m,
scripts/plot/private/__go_draw_axes__.m,
scripts/plot/private/__print_parse_opts__.m, scripts/signal/periodogram.m,
scripts/sparse/bicg.m, test/slice.tst, test/switch.tst:
Use common indentation for switch statement.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 04 Aug 2013 15:11:34 -0700 |
parents | a4969508008e |
children | bc924baa2c4e |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
1 ## Copyright (C) 1995-2012 Friedrich Leisch |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
2 ## Copyright (C) 2010 Alois Schloegl |
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 -*- |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 ## @deftypefn {Function File} {[Pxx, @var{w}] =} periodogram (@var{x}) |
3449 | 22 ## For a data matrix @var{x} from a sample of size @var{n}, return the |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
23 ## periodogram. The angular frequency is returned in @var{w}. |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
24 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
25 ## [Pxx,w] = periodogram (@var{x}). |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
26 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
27 ## [Pxx,w] = periodogram (@var{x},win). |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
28 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
29 ## [Pxx,w] = periodogram (@var{x},win,nfft). |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
30 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
31 ## [Pxx,f] = periodogram (@var{x},win,nfft,Fs). |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
32 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
33 ## [Pxx,f] = periodogram (@var{x},win,nfft,Fs,"range"). |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
34 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
35 ## @itemize |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
36 ## @item x: data; if real-valued a one-sided spectrum is estimated, |
12344
68ac95d2460c
Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
37 ## if complex-valued or range indicates "@nospell{twosided}", the full |
68ac95d2460c
Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
38 ## spectrum is estimated. |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
39 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
40 ## @item win: weight data with window, x.*win is used for further computation, |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
41 ## if window is empty, a rectangular window is used. |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
42 ## |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14552
diff
changeset
|
43 ## @item nfft: number of frequency bins, default max (256, 2.^ceil (log2 (length (x)))). |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
44 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
45 ## @item Fs: sampling rate, default 1. |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
46 ## |
11591
1d13679b587e
Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11563
diff
changeset
|
47 ## @item range: "@nospell{onesided}" computes spectrum from [0..nfft/2+1]. |
12344
68ac95d2460c
Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
48 ## "@nospell{twosided}" computes spectrum from [0..nfft-1]. These strings |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
12344
diff
changeset
|
49 ## can appear at any position in the list input arguments after window. |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
50 ## |
16826
a4969508008e
doc: Periodic spellcheck of the documentation.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
51 ## @item @nospell{Pxx}: one-, or two-sided power spectrum. |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
52 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
53 ## @item w: angular frequency [0..2*pi) (two-sided) or [0..pi] one-sided. |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
54 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
55 ## @item f: frequency [0..Fs) (two-sided) or [0..Fs/2] one-sided. |
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
56 ## @end itemize |
3449 | 57 ## @end deftypefn |
3426 | 58 |
3191 | 59 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
3457 | 60 ## Description: Compute the periodogram |
3191 | 61 |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
62 function [pxx, f] = periodogram (x, varargin) |
3191 | 63 |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
64 ## check input arguments |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
65 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
66 if (nargin < 1 || nargin > 5) |
7125 | 67 print_usage (); |
68 endif | |
69 | |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
70 nfft = []; fs = []; range = []; window = []; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
71 j = 1; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
72 for k = 1:length (varargin) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
73 if (ischar (varargin{k})) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
74 range = varargin{k}; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
75 else |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
76 switch (j) |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
77 case 1 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
78 window = varargin{k}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
79 case 2 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
80 nfft = varargin{k}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
81 case 3 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
82 fs = varargin{k}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
83 case 4 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
84 range = varargin{k}; |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
85 endswitch |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
86 j++; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
87 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
88 endfor |
3191 | 89 |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
90 [r, c] = size (x); |
3191 | 91 if (r == 1) |
92 r = c; | |
93 endif | |
3426 | 94 |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
95 if (ischar (window)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
96 range = window; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
97 window = []; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
98 endif; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
99 if (ischar (nfft)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
100 range = nfft; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
101 nfft = []; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
102 endif; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
103 if (ischar (fs)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
104 range = fs; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
105 fs = []; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
106 endif; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
107 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
108 if (! isempty (window)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
109 if (all (size (x) == size (window))) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
110 x .*= window; |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14868
diff
changeset
|
111 elseif (rows (x) == rows (window) && columns (window) == 1) |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
112 x .*= window (:,ones (1,c)); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
113 endif; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
114 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
115 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
116 if (numel (nfft)>1) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
117 error ("nfft must be scalar"); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
118 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
119 if (isempty (nfft)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
120 nfft = max (256, 2.^ceil (log2 (r))); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
121 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
122 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
123 if (strcmp (range, "onesided")) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
124 range = 1; |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
125 elseif (strcmp (range, "twosided")) |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
126 range = 2; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
127 else |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
128 range = 2-isreal (x); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
129 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
130 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
131 ## compute periodogram |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
132 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
133 if (r>nfft) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
134 Pxx = 0; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
135 rr = rem (length (x), nfft); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
136 if (rr) |
11087
f42f6fc27cc0
periodogram.m: fix parse errors
John W. Eaton <jwe@octave.org>
parents:
11033
diff
changeset
|
137 x = [x(:); (zeros (nfft-rr, 1))]; |
11113
a8ac114ec9ab
Stylefixes, replace end by endif.
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
11087
diff
changeset
|
138 endif |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
139 x = sum (reshape (x, nfft, []), 2); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
140 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
141 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
142 if (isempty (window)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
143 n = r; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
144 else |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
145 n = sumsq (window); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
146 end; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
147 Pxx = (abs (fft (x, nfft))) .^ 2 / n ; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
148 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
149 if (nargin<4) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
150 Pxx /= 2*pi; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
151 elseif (! isempty (fs)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
152 Pxx /= fs; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
153 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
154 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
155 ## generate output arguments |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
156 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
157 if (range == 1) # onesided |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
158 Pxx = Pxx(1:nfft/2+1) + [0; Pxx(end:-1:(nfft/2+2)); 0]; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
159 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
160 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
161 if (nargout != 1) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
162 if (range == 1) |
11087
f42f6fc27cc0
periodogram.m: fix parse errors
John W. Eaton <jwe@octave.org>
parents:
11033
diff
changeset
|
163 f = (0:nfft/2)'/nfft; |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
164 elseif (range == 2) |
11087
f42f6fc27cc0
periodogram.m: fix parse errors
John W. Eaton <jwe@octave.org>
parents:
11033
diff
changeset
|
165 f = (0:nfft-1)'/nfft; |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
166 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
167 if (nargin<4) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
168 f *= 2*pi; # generate w=2*pi*f |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
169 elseif (! isempty (fs)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
170 f *= fs; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
171 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
172 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
173 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
174 if (nargout == 0) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
175 if (nargin<4) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
176 plot (f/(2*pi), 10*log10 (Pxx)); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
177 xlabel ("normalized frequency [x pi rad]"); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
178 ylabel ("Power density [dB/rad/sample]"); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
179 else |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
180 plot (f, 10*log10 (Pxx)); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
181 xlabel ("frequency [Hz]"); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
182 ylabel ("Power density [dB/Hz]"); |
11113
a8ac114ec9ab
Stylefixes, replace end by endif.
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
11087
diff
changeset
|
183 endif |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
184 grid on; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
185 title ("Periodogram Power Spectral Density Estimate"); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
186 else |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
187 pxx = Pxx; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
188 endif |
3426 | 189 |
3191 | 190 endfunction |