Mercurial > octave
annotate scripts/signal/stft.m @ 27923:bd51beb6205e
update formatting of copyright notices
* Use <https://octave.org/copyright/> instead of
<https://octave.org/COPYRIGHT.html/>.
* For consistency with other comments in the Octave sources, use
C++-style comments for copyright blocks in C and C++ files.
* Use delimiters above and below copyright blocks that are appropriate
for the language used in the file.
* Eliminate extra spacing inside copyright blocks.
* lex.ll (looks_like_copyright): Also allow newlines and carriage
returns before the word "Copyright".
* scripts/mk-doc.pl (gethelp): Also skip empty comment lines.
* bp-table.cc, type.m: Adjust tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 08 Jan 2020 11:59:41 -0500 |
parents | 1891570abac8 |
children | b09432b20a84 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 1995-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
3426 | 7 ## |
3922 | 8 ## This file is part of Octave. |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
3922 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
3426 | 14 ## |
3922 | 15 ## Octave is distributed in the hope that it will be useful, but |
3191 | 16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
3426 | 19 ## |
3191 | 20 ## You should have received a copy of the GNU General Public License |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
3191 | 25 |
3449 | 26 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
27 ## @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
|
28 ## @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
|
29 ## @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
|
30 ## @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
|
31 ## @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
|
32 ## @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
|
33 ## Compute the short-time Fourier transform of the vector @var{x} with |
3449 | 34 ## @var{num_coef} coefficients by applying a window of @var{win_size} data |
35 ## points and an increment of @var{inc} points. | |
3191 | 36 ## |
37 ## Before computing the Fourier transform, one of the following windows | |
3449 | 38 ## is applied: |
39 ## | |
40 ## @table @asis | |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
41 ## @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
|
42 ## win_type = 1 |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
43 ## |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
44 ## @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
|
45 ## win_type = 2 |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
46 ## |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
47 ## @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
|
48 ## win_type = 3 |
3449 | 49 ## @end table |
50 ## | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
51 ## The window names can be passed as strings or by the @var{win_type} number. |
3191 | 52 ## |
17754
dffb1e9a6d3b
doc: Final spellcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
53 ## The following defaults are used for unspecified arguments: |
3449 | 54 ## @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
|
55 ## @var{win_type} = 1. |
3191 | 56 ## |
20165
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
57 ## @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
|
58 ## Fourier coefficients according to the @var{num_coef} positive frequencies. |
3449 | 59 ## |
25472
9771111f04f4
doc: Use @var rather than @code to mark inputs to functions in docstrings.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
60 ## @code{[@var{y}, @var{c}] = stft (@var{x}, @dots{})} returns the entire |
20165
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
61 ## 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
|
62 ## 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
|
63 ## function. |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
64 ## @seealso{synthesis} |
3449 | 65 ## @end deftypefn |
3191 | 66 |
3457 | 67 ## 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
|
68 ## Description: Short-Time Fourier Transform |
3191 | 69 |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
70 function [y, c] = stft (x, win_size = 80, inc = 24, num_coef = 64, win_type = 1) |
3426 | 71 |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
72 if (nargin < 1 || nargin > 5) |
6046 | 73 print_usage (); |
3191 | 74 endif |
75 | |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
76 if (ischar (win_type)) |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
77 switch (tolower (win_type)) |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
78 case "hanning" win_type = 1; |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
79 case "hamming" win_type = 2; |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
80 case "rectangle" win_type = 3; |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
81 otherwise |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
82 error ("stft: unknown window type '%s'", win_type); |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
83 endswitch |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
84 endif |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
85 |
8506 | 86 ## Check whether X is a vector. |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
87 if (! isvector (x)) |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
88 error ("stft: X must be a vector"); |
3191 | 89 endif |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
90 x = x(:); |
3191 | 91 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
92 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
|
93 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
|
94 win_size = ncoef; |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
95 printf ("stft: window size adjusted to %f\n", win_size); |
3191 | 96 endif |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
97 num_win = fix ((rows (x) - win_size) / inc); |
3191 | 98 |
99 ## compute the window coefficients | |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
100 switch (win_type) |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
101 case 1 win_coef = hanning (win_size); |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
102 case 2 win_coef = hamming (win_size); |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
103 case 3 win_coef = ones (win_size, 1); |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
104 endswitch |
3426 | 105 |
8506 | 106 ## 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
|
107 z = zeros (ncoef, num_win + 1); |
3191 | 108 start = 1; |
109 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
|
110 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
|
111 start += inc; |
3191 | 112 endfor |
113 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
114 y = fft (z); |
3191 | 115 |
116 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
|
117 y = abs (y(1:num_coef, :)); |
3191 | 118 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
|
119 c = [win_size, inc, win_type]; |
3191 | 120 endif |
121 | |
122 endfunction |