annotate scripts/signal/periodogram.m @ 10984:58c57161626d

extend periodogram, thanks to Alois Schloegl
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 16 Sep 2010 07:37:07 +0200
parents f084ba47812b
children d9c8916bb9dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 ## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2005, 2007
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
2 ## Friedrich Leisch
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
3 ## Copyright (C) 2010 Alois Schloegl
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
4 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
5 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
6 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
7 ## 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
8 ## 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
9 ## 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
10 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
11 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
12 ## 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
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
14 ## 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
15 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
16 ##
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
17 ## 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
18 ## 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
19 ## <http://www.gnu.org/licenses/>.
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
20
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
21 ## -*- texinfo -*-
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
22 ## @deftypefn {Function File} {[Pxx,w]} = periodogram (@var{x})
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
23 ## For a data matrix @var{x} from a sample of size @var{n}, return the
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
24 ## periodogram. w returns the angular frequency.
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
25 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
26 ## [Pxx,w] = periodogram (@var{x}).
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
27 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
28 ## [Pxx,w] = periodogram (@var{x},win).
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
29 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
30 ## [Pxx,w] = periodogram (@var{x},win,nfft).
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
31 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
32 ## [Pxx,f] = periodogram (@var{x},win,nfft,Fs).
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
33 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
34 ## [Pxx,f] = periodogram (@var{x},win,nfft,Fs,"range").
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
35 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
36 ## @itemize
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
37 ## @item x: data; if real-valued a one-sided spectrum is estimated,
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
38 ## if complex-valued or range indicates "twosided", the full spectrum is estimated.
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
39 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
40 ## @item win: weight data with window, x.*win is used for further computation,
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
41 ## if window is empty, a rectangular window is used.
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
42 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
43 ## @item nfft: number of frequency bins, default max(256, 2.^ceil(log2(length(x)))).
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
44 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
45 ## @item Fs: sampleing rate, default 1.
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
46 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
47 ## @item range: "onesided" computes spectrum from [0..nfft/2+1].
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
48 ## "twosided" computes spectrum from [0..nfft-1]. These strings can appear at any
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
49 ## position in the list input arguments after window.
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
50 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
51 ## @item Pxx: one-, or two-sided power spectrum.
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
52 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
53 ## @item w: angular frequency [0..2*pi) (two-sided) or [0..pi] one-sided.
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
54 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
55 ## @item f: frequency [0..Fs) (two-sided) or [0..Fs/2] one-sided.
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
56 ## @end itemize
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
57 ##
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
58 ##
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
59 ## @end deftypefn
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
60
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
61 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at>
3457
e031284eea27 [project @ 2000-01-19 08:49:56 by jwe]
jwe
parents: 3449
diff changeset
62 ## Description: Compute the periodogram
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
63
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
64 function [pxx, f] = periodogram (x, varargin)
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
65
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
66 ## check input arguments
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
67
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
68 if (nargin < 1 || nargin > 5)
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
69 print_usage ();
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
70 endif
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
71
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
72 nfft = []; fs = []; range = []; window = [];
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
73 j = 1;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
74 for k = 1:length (varargin)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
75 if (ischar (varargin{k}))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
76 range = varargin{k};
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
77 else
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
78 switch (j)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
79 case 1
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
80 window = varargin{k};
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
81 case 2
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
82 nfft = varargin{k};
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
83 case 3
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
84 fs = varargin{k};
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
85 case 4
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
86 range = varargin{k};
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
87 endswitch
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
88 j++;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
89 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
90 endfor
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
91
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
92 [r, c] = size (x);
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
93 if (r == 1)
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
94 r = c;
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
95 endif
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
96
10984
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
97 if (ischar (window))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
98 range = window;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
99 window = [];
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
100 endif;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
101 if (ischar (nfft))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
102 range = nfft;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
103 nfft = [];
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
104 endif;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
105 if (ischar (fs))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
106 range = fs;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
107 fs = [];
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
108 endif;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
109
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
110 if (! isempty (window))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
111 if (all (size (x) == size (window)))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
112 x .*= window;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
113 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
114 x .*= window (:,ones (1,c));
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
115 endif;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
116 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
117
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
118 if (numel (nfft)>1)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
119 error ("nfft must be scalar");
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 if (isempty (nfft))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
122 nfft = max (256, 2.^ceil (log2 (r)));
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
123 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
124
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
125 if (strcmp (range, "onesided"))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
126 range = 1;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
127 elseif strcmp (range, "twosided")
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
128 range = 2;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
129 else
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
130 range = 2-isreal (x);
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
131 endif
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 ## compute periodogram
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
134
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
135 if (r>nfft)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
136 Pxx = 0;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
137 rr = rem (length (x), nfft);
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
138 if (rr)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
139 x = [x(:);zeros (nfft-rr, 1)];
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
140 end
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
141 x = sum (reshape (x, nfft, []), 2);
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
142 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
143
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
144 if (isempty (window))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
145 n = r;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
146 else
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
147 n = sumsq (window);
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
148 end;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
149 Pxx = (abs (fft (x, nfft))) .^ 2 / n ;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
150
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
151 if (nargin<4)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
152 Pxx /= 2*pi;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
153 elseif (! isempty (fs))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
154 Pxx /= fs;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
155 endif
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 ## generate output arguments
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
158
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
159 if (range == 1) # onesided
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
160 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
161 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
162
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
163 if (nargout != 1)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
164 if (range == 1)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
165 f = (0:nfft/2)"/nfft;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
166 elseif (range == 2)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
167 f = (0:nfft-1)"/nfft;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
168 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
169 if (nargin<4)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
170 f *= 2*pi; # generate w=2*pi*f
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
171 elseif (! isempty (fs))
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
172 f *= fs;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
173 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
174 endif
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
175
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
176 if (nargout == 0)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
177 if (nargin<4)
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
178 plot (f/(2*pi), 10*log10 (Pxx));
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
179 xlabel ("normalized frequency [x pi rad]");
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
180 ylabel ("Power density [dB/rad/sample]");
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
181 else
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
182 plot (f, 10*log10 (Pxx));
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
183 xlabel ("frequency [Hz]");
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
184 ylabel ("Power density [dB/Hz]");
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
185 end
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
186 grid on;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
187 title ("Periodogram Power Spectral Density Estimate");
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
188 else
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
189 pxx = Pxx;
58c57161626d extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents: 7125
diff changeset
190 endif
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
191
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
192 endfunction