annotate scripts/signal/stft.m @ 20852:516bb87ea72e

2015 Code Sprint: remove class of function from docstring for all m-files.
author Rik <rik@octave.org>
date Sat, 12 Dec 2015 07:31:00 -0800
parents 83792dd9bcc1
children dcf8922b724b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17754
diff changeset
1 ## Copyright (C) 1995-2015 Andreas Weingessel
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
2 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
3 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
4 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
5 ## 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
6 ## 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: 6547
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
8 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
9 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
10 ## 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
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
13 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
14 ##
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
15 ## 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: 6547
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
18
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
19 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20231
diff changeset
20 ## @deftypefn {} {@var{y} =} stft (@var{x})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20231
diff changeset
21 ## @deftypefnx {} {@var{y} =} stft (@var{x}, @var{win_size})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20231
diff changeset
22 ## @deftypefnx {} {@var{y} =} stft (@var{x}, @var{win_size}, @var{inc})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20231
diff changeset
23 ## @deftypefnx {} {@var{y} =} stft (@var{x}, @var{win_size}, @var{inc}, @var{num_coef})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20231
diff changeset
24 ## @deftypefnx {} {@var{y} =} stft (@var{x}, @var{win_size}, @var{inc}, @var{num_coef}, @var{win_type})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20231
diff changeset
25 ## @deftypefnx {} {[@var{y}, @var{c}] =} stft (@dots{})
9072
bd8e388043c4 Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
26 ## Compute the short-time Fourier transform of the vector @var{x} with
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
27 ## @var{num_coef} coefficients by applying a window of @var{win_size} data
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
28 ## points and an increment of @var{inc} points.
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
29 ##
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
30 ## Before computing the Fourier transform, one of the following windows
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
31 ## is applied:
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
32 ##
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
33 ## @table @asis
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
34 ## @item @qcode{"hanning"}
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
35 ## win_type = 1
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
36 ##
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
37 ## @item @qcode{"hamming"}
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
38 ## win_type = 2
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
39 ##
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
40 ## @item @qcode{"rectangle"}
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
41 ## win_type = 3
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
42 ## @end table
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
43 ##
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
44 ## The window names can be passed as strings or by the @var{win_type} number.
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
45 ##
17754
dffb1e9a6d3b doc: Final spellcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents: 17744
diff changeset
46 ## The following defaults are used for unspecified arguments:
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
47 ## @var{win_size} = 80, @var{inc} = 24, @var{num_coef} = 64, and
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
48 ## @var{win_type} = 1.
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
49 ##
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
50 ## @code{@var{y} = stft (@var{x}, @dots{})} returns the absolute values of the
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
51 ## Fourier coefficients according to the @var{num_coef} positive frequencies.
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
52 ##
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
53 ## @code{[@var{y}, @var{c}] = stft (@code{x}, @dots{})} returns the entire
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
54 ## STFT-matrix @var{y} and a 3-element vector @var{c} containing the window
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
55 ## size, increment, and window type, which is needed by the @code{synthesis}
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
56 ## function.
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
57 ## @seealso{synthesis}
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
58 ## @end deftypefn
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
59
3457
e031284eea27 [project @ 2000-01-19 08:49:56 by jwe]
jwe
parents: 3449
diff changeset
60 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
9072
bd8e388043c4 Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
61 ## Description: Short-Time Fourier Transform
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
62
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
63 function [y, c] = stft (x, win_size = 80, inc = 24, num_coef = 64, win_type = 1)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
64
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
65 if (nargin < 1 || nargin > 5)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5443
diff changeset
66 print_usage ();
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
67 endif
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
68
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
69 if (ischar (win_type))
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
70 switch (tolower (win_type))
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
71 case "hanning" win_type = 1;
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
72 case "hamming" win_type = 2;
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
73 case "rectangle" win_type = 3;
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
74 otherwise
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
75 error ("stft: unknown window type '%s'", win_type);
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
76 endswitch
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
77 endif
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
78
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
79 ## Check whether X is a vector.
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
80 if (! isvector (x))
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
81 error ("stft: X must be a vector");
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
82 endif
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
83 x = x(:);
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
84
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
85 ncoef = 2 * num_coef;
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
86 if (win_size > ncoef)
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
87 win_size = ncoef;
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
88 printf ("stft: window size adjusted to %f\n", win_size);
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
89 endif
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
90 num_win = fix ((rows (x) - win_size) / inc);
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
91
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
92 ## compute the window coefficients
17718
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
93 switch (win_type)
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
94 case 1 win_coef = hanning (win_size);
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
95 case 2 win_coef = hamming (win_size);
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
96 case 3 win_coef = ones (win_size, 1);
6ed0a8532bcf Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents: 17338
diff changeset
97 endswitch
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
98
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
99 ## Create a matrix Z whose columns contain the windowed time-slices.
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
100 z = zeros (ncoef, num_win + 1);
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
101 start = 1;
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
102 for i = 0:num_win
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
103 z(1:win_size, i+1) = x(start:start+win_size-1) .* win_coef;
20231
83792dd9bcc1 Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents: 20165
diff changeset
104 start += inc;
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
105 endfor
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
106
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
107 y = fft (z);
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
108
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
109 if (nargout == 1)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
110 y = abs (y(1:num_coef, :));
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
111 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
112 c = [win_size, inc, win_type];
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
113 endif
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
114
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
115 endfunction
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 15467
diff changeset
116