annotate scripts/signal/periodogram.m @ 11591:1d13679b587e

Use @nospell macro on certain words in docstrings.
author Rik <octave@nomad.inbox5.com>
date Thu, 20 Jan 2011 19:33:32 -0800
parents 3c6e8aaa9555
children 68ac95d2460c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
1 ## Copyright (C) 1995-2011 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
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
3 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
4 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
5 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
6 ## 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
7 ## 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
8 ## 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
9 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
10 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
11 ## 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
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
14 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
15 ##
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
16 ## 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
17 ## 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
18 ## <http://www.gnu.org/licenses/>.
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
19
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
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
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
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,
11591
1d13679b587e Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11563
diff changeset
37 ## if complex-valued or range indicates "@nospell{twosided}", the full spectrum is estimated.
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
38 ##
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
39 ## @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
40 ## 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
41 ##
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
42 ## @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
43 ##
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
44 ## @item Fs: sampling rate, default 1.
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
45 ##
11591
1d13679b587e Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11563
diff changeset
46 ## @item range: "@nospell{onesided}" computes spectrum from [0..nfft/2+1].
1d13679b587e Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11563
diff changeset
47 ## "@nospell{twosided}" computes spectrum from [0..nfft-1]. These strings can appear at any
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
48 ## 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
49 ##
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
50 ## @item Pxx: one-, or two-sided power spectrum.
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
51 ##
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
52 ## @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
53 ##
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
54 ## @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
55 ## @end itemize
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
56 ## @end deftypefn
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
57
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
58 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at>
3457
e031284eea27 [project @ 2000-01-19 08:49:56 by jwe]
jwe
parents: 3449
diff changeset
59 ## Description: Compute the periodogram
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
60
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
61 function [pxx, f] = periodogram (x, varargin)
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
62
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
63 ## check input arguments
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
64
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
65 if (nargin < 1 || nargin > 5)
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
66 print_usage ();
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
67 endif
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
68
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
69 nfft = []; fs = []; range = []; window = [];
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
70 j = 1;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
71 for k = 1:length (varargin)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
72 if (ischar (varargin{k}))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
73 range = varargin{k};
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
74 else
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
75 switch (j)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
76 case 1
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
77 window = varargin{k};
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
78 case 2
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
79 nfft = varargin{k};
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
80 case 3
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
81 fs = varargin{k};
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
82 case 4
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
83 range = varargin{k};
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
84 endswitch
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
85 j++;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
86 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
87 endfor
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
88
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
89 [r, c] = size (x);
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
90 if (r == 1)
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
91 r = c;
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
92 endif
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
93
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
94 if (ischar (window))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
95 range = window;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
96 window = [];
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
97 endif;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
98 if (ischar (nfft))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
99 range = nfft;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
100 nfft = [];
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
101 endif;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
102 if (ischar (fs))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
103 range = fs;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
104 fs = [];
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
105 endif;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
106
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
107 if (! isempty (window))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
108 if (all (size (x) == size (window)))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
109 x .*= window;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
110 elseif (size (x, 1) == size (window, 1) && size (window, 2) == 1)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
111 x .*= window (:,ones (1,c));
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
112 endif;
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
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
115 if (numel (nfft)>1)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
116 error ("nfft must be scalar");
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
117 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
118 if (isempty (nfft))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
119 nfft = max (256, 2.^ceil (log2 (r)));
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
120 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
121
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
122 if (strcmp (range, "onesided"))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
123 range = 1;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
124 elseif strcmp (range, "twosided")
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
125 range = 2;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
126 else
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
127 range = 2-isreal (x);
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
128 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
129
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
130 ## compute periodogram
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
131
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
132 if (r>nfft)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
133 Pxx = 0;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
134 rr = rem (length (x), nfft);
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
135 if (rr)
11087
f42f6fc27cc0 periodogram.m: fix parse errors
John W. Eaton <jwe@octave.org>
parents: 11033
diff changeset
136 x = [x(:); (zeros (nfft-rr, 1))];
11113
a8ac114ec9ab Stylefixes, replace end by endif.
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 11087
diff changeset
137 endif
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
138 x = sum (reshape (x, nfft, []), 2);
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
139 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
140
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
141 if (isempty (window))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
142 n = r;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
143 else
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
144 n = sumsq (window);
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
145 end;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
146 Pxx = (abs (fft (x, nfft))) .^ 2 / n ;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
147
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
148 if (nargin<4)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
149 Pxx /= 2*pi;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
150 elseif (! isempty (fs))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
151 Pxx /= fs;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
152 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
153
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
154 ## generate output arguments
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
155
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
156 if (range == 1) # onesided
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
157 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
158 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
159
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
160 if (nargout != 1)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
161 if (range == 1)
11087
f42f6fc27cc0 periodogram.m: fix parse errors
John W. Eaton <jwe@octave.org>
parents: 11033
diff changeset
162 f = (0:nfft/2)'/nfft;
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
163 elseif (range == 2)
11087
f42f6fc27cc0 periodogram.m: fix parse errors
John W. Eaton <jwe@octave.org>
parents: 11033
diff changeset
164 f = (0:nfft-1)'/nfft;
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
165 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
166 if (nargin<4)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
167 f *= 2*pi; # generate w=2*pi*f
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
168 elseif (! isempty (fs))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
169 f *= fs;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
170 endif
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
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
173 if (nargout == 0)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
174 if (nargin<4)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
175 plot (f/(2*pi), 10*log10 (Pxx));
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
176 xlabel ("normalized frequency [x pi rad]");
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
177 ylabel ("Power density [dB/rad/sample]");
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
178 else
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
179 plot (f, 10*log10 (Pxx));
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
180 xlabel ("frequency [Hz]");
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
181 ylabel ("Power density [dB/Hz]");
11113
a8ac114ec9ab Stylefixes, replace end by endif.
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 11087
diff changeset
182 endif
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
183 grid on;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
184 title ("Periodogram Power Spectral Density Estimate");
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
185 else
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
186 pxx = Pxx;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
187 endif
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
188
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
189 endfunction