Mercurial > octave-nkf
annotate scripts/signal/periodogram.m @ 17281:bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Macro handles options ("on") or properties ("position") more elegantly
than @code{"text"}.
* doc/interpreter/macros.texi: Add new @qcode macro.
* doc/interpreter/tips.txi: Add documentation about @qcode macro.
* doc/interpreter/basics.txi, doc/interpreter/container.txi,
doc/interpreter/emacs.txi, doc/interpreter/errors.txi,
doc/interpreter/eval.txi, doc/interpreter/expr.txi,
doc/interpreter/external.txi, doc/interpreter/func.txi,
doc/interpreter/grammar.txi, doc/interpreter/image.txi,
doc/interpreter/install.txi, doc/interpreter/interp.txi,
doc/interpreter/io.txi, doc/interpreter/matrix.txi,
doc/interpreter/numbers.txi, doc/interpreter/oop.txi,
doc/interpreter/package.txi, doc/interpreter/plot.txi,
doc/interpreter/quad.txi, doc/interpreter/sparse.txi,
doc/interpreter/strings.txi, doc/interpreter/system.txi,
doc/interpreter/vectorize.txi, libinterp/corefcn/balance.cc,
libinterp/corefcn/bitfcns.cc, libinterp/corefcn/cellfun.cc,
libinterp/corefcn/conv2.cc, libinterp/corefcn/data.cc,
libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc,
libinterp/corefcn/dirfns.cc, libinterp/corefcn/dlmread.cc,
libinterp/corefcn/error.cc, libinterp/corefcn/file-io.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc,
libinterp/corefcn/graphics.cc, libinterp/corefcn/help.cc,
libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc,
libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc,
libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lu.cc,
libinterp/corefcn/luinc.cc, libinterp/corefcn/matrix_type.cc,
libinterp/corefcn/oct-hist.cc, libinterp/corefcn/pager.cc,
libinterp/corefcn/pr-output.cc, libinterp/corefcn/pt-jit.cc,
libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc,
libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sparse.cc,
libinterp/corefcn/spparms.cc, libinterp/corefcn/str2double.cc,
libinterp/corefcn/svd.cc, libinterp/corefcn/symtab.cc,
libinterp/corefcn/syscalls.cc, libinterp/corefcn/toplev.cc,
libinterp/corefcn/tril.cc, libinterp/corefcn/typecast.cc,
libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc,
libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/chol.cc,
libinterp/dldfcn/colamd.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc,
libinterp/dldfcn/symbfact.cc, libinterp/octave-value/ov-base.cc,
libinterp/octave-value/ov-fcn-handle.cc,
libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc,
libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-struct.cc,
libinterp/octave-value/ov-usr-fcn.cc, libinterp/parse-tree/oct-parse.in.yy,
libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-eval.cc,
libinterp/parse-tree/pt-mat.cc, scripts/@ftp/ftp.m,
scripts/deprecated/java_convert_matrix.m, scripts/deprecated/java_debug.m,
scripts/deprecated/java_unsigned_conversion.m, scripts/deprecated/shell_cmd.m,
scripts/general/dblquad.m, scripts/general/display.m,
scripts/general/genvarname.m, scripts/general/idivide.m,
scripts/general/interp1.m, scripts/general/interp2.m,
scripts/general/interp3.m, scripts/general/interpn.m, scripts/general/isa.m,
scripts/general/profexplore.m, scripts/general/profile.m,
scripts/general/quadgk.m, scripts/general/randi.m, scripts/general/structfun.m,
scripts/general/subsindex.m, scripts/general/triplequad.m,
scripts/geometry/griddata.m, scripts/geometry/griddata3.m,
scripts/geometry/griddatan.m, scripts/geometry/voronoi.m, scripts/help/help.m,
scripts/help/lookfor.m, scripts/image/cmpermute.m, scripts/image/colormap.m,
scripts/image/image.m, scripts/image/imagesc.m, scripts/image/imfinfo.m,
scripts/image/imformats.m, scripts/image/imread.m, scripts/image/imshow.m,
scripts/image/imwrite.m, scripts/image/ind2gray.m, scripts/image/lines.m,
scripts/image/rgb2ind.m, scripts/image/spinmap.m, scripts/io/dlmwrite.m,
scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m,
scripts/java/javaclasspath.m, scripts/java/usejava.m,
scripts/miscellaneous/bzip2.m, scripts/miscellaneous/computer.m,
scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m,
scripts/miscellaneous/dos.m, scripts/miscellaneous/edit.m,
scripts/miscellaneous/gzip.m, scripts/miscellaneous/license.m,
scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/movefile.m,
scripts/miscellaneous/parseparams.m, scripts/miscellaneous/unix.m,
scripts/optimization/fminbnd.m, scripts/optimization/fminsearch.m,
scripts/optimization/fminunc.m, scripts/optimization/fsolve.m,
scripts/optimization/fzero.m, scripts/optimization/glpk.m,
scripts/optimization/lsqnonneg.m, scripts/optimization/optimset.m,
scripts/optimization/pqpnonneg.m, scripts/pkg/pkg.m, scripts/plot/allchild.m,
scripts/plot/ancestor.m, scripts/plot/area.m, scripts/plot/axis.m,
scripts/plot/bar.m, scripts/plot/barh.m, scripts/plot/box.m,
scripts/plot/caxis.m, scripts/plot/cla.m, scripts/plot/clabel.m,
scripts/plot/clf.m, scripts/plot/close.m, scripts/plot/colorbar.m,
scripts/plot/daspect.m, scripts/plot/ezmesh.m, scripts/plot/ezmeshc.m,
scripts/plot/ezsurf.m, scripts/plot/ezsurfc.m, scripts/plot/findall.m,
scripts/plot/findobj.m, scripts/plot/gcbo.m, scripts/plot/gcf.m,
scripts/plot/gco.m, scripts/plot/grid.m, scripts/plot/guihandles.m,
scripts/plot/hdl2struct.m, scripts/plot/hidden.m, scripts/plot/hold.m,
scripts/plot/isonormals.m, scripts/plot/isosurface.m, scripts/plot/legend.m,
scripts/plot/mesh.m, scripts/plot/meshc.m, scripts/plot/meshz.m,
scripts/plot/newplot.m, scripts/plot/orient.m, scripts/plot/pareto.m,
scripts/plot/patch.m, scripts/plot/pbaspect.m, scripts/plot/pcolor.m,
scripts/plot/plot.m, scripts/plot/print.m,
scripts/plot/private/__add_default_menu__.m, scripts/plot/quiver.m,
scripts/plot/quiver3.m, scripts/plot/refreshdata.m, scripts/plot/saveas.m,
scripts/plot/scatter.m, scripts/plot/scatter3.m, scripts/plot/shading.m,
scripts/plot/shrinkfaces.m, scripts/plot/slice.m, scripts/plot/stem.m,
scripts/plot/stem3.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m,
scripts/plot/surf.m, scripts/plot/surfc.m, scripts/plot/surfl.m,
scripts/plot/tetramesh.m, scripts/plot/uigetfile.m, scripts/plot/uimenu.m,
scripts/plot/uiputfile.m, scripts/plot/waterfall.m, scripts/plot/whitebg.m,
scripts/plot/xlim.m, scripts/plot/ylim.m, scripts/plot/zlim.m,
scripts/polynomial/conv.m, scripts/polynomial/polyout.m,
scripts/polynomial/splinefit.m, scripts/set/ismember.m, scripts/set/powerset.m,
scripts/set/setdiff.m, scripts/set/union.m, scripts/set/unique.m,
scripts/signal/detrend.m, scripts/signal/filter2.m, scripts/signal/freqz.m,
scripts/signal/periodogram.m, scripts/signal/spectral_adf.m,
scripts/signal/spectral_xdf.m, scripts/sparse/eigs.m, scripts/sparse/svds.m,
scripts/specfun/legendre.m, scripts/special-matrix/gallery.m,
scripts/statistics/base/mean.m, scripts/statistics/base/moment.m,
scripts/statistics/tests/cor_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test_2.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/sign_test.m,
scripts/statistics/tests/t_test.m, scripts/statistics/tests/t_test_2.m,
scripts/statistics/tests/t_test_regression.m,
scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m,
scripts/statistics/tests/welch_test.m,
scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m,
scripts/statistics/tests/z_test_2.m, scripts/strings/base2dec.m,
scripts/strings/index.m, scripts/strings/isstrprop.m,
scripts/strings/mat2str.m, scripts/strings/regexptranslate.m,
scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m,
scripts/strings/strjust.m, scripts/strings/strmatch.m,
scripts/strings/validatestring.m, scripts/testfun/demo.m,
scripts/testfun/example.m, scripts/testfun/test.m, scripts/time/addtodate.m,
scripts/time/asctime.m, scripts/time/datestr.m, scripts/time/datetick.m,
scripts/time/weekday.m, scripts/ui/errordlg.m, scripts/ui/helpdlg.m,
scripts/ui/inputdlg.m, scripts/ui/listdlg.m, scripts/ui/msgbox.m,
scripts/ui/questdlg.m, scripts/ui/warndlg.m: Use new @qcode macro.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 19 Aug 2013 20:46:38 -0700 |
parents | c3c1ebfaa7dc |
children | 1c89599167a6 |
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, |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
37 ## if complex-valued or range indicates @qcode{"@nospell{twosided}"}, the full |
12344
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 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
47 ## @item range: @qcode{"@nospell{onesided}"} computes spectrum from [0..nfft/2+1]. |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
48 ## @qcode{"@nospell{twosided}"} computes spectrum from [0..nfft-1]. These |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
49 ## strings can appear at any position in the list input arguments after |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
50 ## window. |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
51 ## |
16826
a4969508008e
doc: Periodic spellcheck of the documentation.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
52 ## @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
|
53 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
54 ## @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
|
55 ## |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
56 ## @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
|
57 ## @end itemize |
3449 | 58 ## @end deftypefn |
3426 | 59 |
3191 | 60 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
3457 | 61 ## Description: Compute the periodogram |
3191 | 62 |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
63 function [pxx, f] = periodogram (x, varargin) |
3191 | 64 |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
65 ## check input arguments |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
66 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
67 if (nargin < 1 || nargin > 5) |
7125 | 68 print_usage (); |
69 endif | |
70 | |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
71 nfft = []; fs = []; range = []; window = []; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
72 j = 1; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
73 for k = 1:length (varargin) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
74 if (ischar (varargin{k})) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
75 range = varargin{k}; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
76 else |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
77 switch (j) |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
78 case 1 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
79 window = varargin{k}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
80 case 2 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
81 nfft = varargin{k}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
82 case 3 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
83 fs = varargin{k}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
84 case 4 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
85 range = varargin{k}; |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
86 endswitch |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
87 j++; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
88 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
89 endfor |
3191 | 90 |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
91 [r, c] = size (x); |
3191 | 92 if (r == 1) |
93 r = c; | |
94 endif | |
3426 | 95 |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
96 if (ischar (window)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
97 range = window; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
98 window = []; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
99 endif; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
100 if (ischar (nfft)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
101 range = nfft; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
102 nfft = []; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
103 endif; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
104 if (ischar (fs)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
105 range = fs; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
106 fs = []; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
107 endif; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
108 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
109 if (! isempty (window)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
110 if (all (size (x) == size (window))) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
111 x .*= window; |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14868
diff
changeset
|
112 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
|
113 x .*= window (:,ones (1,c)); |
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 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
116 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
117 if (numel (nfft)>1) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
118 error ("nfft must be scalar"); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
119 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
120 if (isempty (nfft)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
121 nfft = max (256, 2.^ceil (log2 (r))); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
122 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
123 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
124 if (strcmp (range, "onesided")) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
125 range = 1; |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
126 elseif (strcmp (range, "twosided")) |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
127 range = 2; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
128 else |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
129 range = 2-isreal (x); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
130 endif |
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 ## compute periodogram |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
133 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
134 if (r>nfft) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
135 Pxx = 0; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
136 rr = rem (length (x), nfft); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
137 if (rr) |
11087
f42f6fc27cc0
periodogram.m: fix parse errors
John W. Eaton <jwe@octave.org>
parents:
11033
diff
changeset
|
138 x = [x(:); (zeros (nfft-rr, 1))]; |
11113
a8ac114ec9ab
Stylefixes, replace end by endif.
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
11087
diff
changeset
|
139 endif |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
140 x = sum (reshape (x, nfft, []), 2); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
141 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
142 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
143 if (isempty (window)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
144 n = r; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
145 else |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
146 n = sumsq (window); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
147 end; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
148 Pxx = (abs (fft (x, nfft))) .^ 2 / n ; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
149 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
150 if (nargin<4) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
151 Pxx /= 2*pi; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
152 elseif (! isempty (fs)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
153 Pxx /= fs; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
154 endif |
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 ## generate output arguments |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
157 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
158 if (range == 1) # onesided |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
159 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
|
160 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
161 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
162 if (nargout != 1) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
163 if (range == 1) |
11087
f42f6fc27cc0
periodogram.m: fix parse errors
John W. Eaton <jwe@octave.org>
parents:
11033
diff
changeset
|
164 f = (0:nfft/2)'/nfft; |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
165 elseif (range == 2) |
11087
f42f6fc27cc0
periodogram.m: fix parse errors
John W. Eaton <jwe@octave.org>
parents:
11033
diff
changeset
|
166 f = (0:nfft-1)'/nfft; |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
167 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
168 if (nargin<4) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
169 f *= 2*pi; # generate w=2*pi*f |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
170 elseif (! isempty (fs)) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
171 f *= fs; |
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 endif |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
174 |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
175 if (nargout == 0) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
176 if (nargin<4) |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
177 plot (f/(2*pi), 10*log10 (Pxx)); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
178 xlabel ("normalized frequency [x pi rad]"); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
179 ylabel ("Power density [dB/rad/sample]"); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
180 else |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
181 plot (f, 10*log10 (Pxx)); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
182 xlabel ("frequency [Hz]"); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
183 ylabel ("Power density [dB/Hz]"); |
11113
a8ac114ec9ab
Stylefixes, replace end by endif.
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
11087
diff
changeset
|
184 endif |
10984
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
185 grid on; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
186 title ("Periodogram Power Spectral Density Estimate"); |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
187 else |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
188 pxx = Pxx; |
58c57161626d
extend periodogram, thanks to Alois Schloegl
Jaroslav Hajek <highegg@gmail.com>
parents:
7125
diff
changeset
|
189 endif |
3426 | 190 |
3191 | 191 endfunction |