Mercurial > octave
annotate scripts/signal/stft.m @ 27918:b442ec6dda5c
use centralized file for copyright info for individual contributors
* COPYRIGHT.md: New file.
* In most other files, use "Copyright (C) YYYY-YYYY The Octave Project
Developers" instead of tracking individual names in separate source
files. The motivation is to reduce the effort required to update the
notices each year.
Until now, the Octave source files contained copyright notices that
list individual contributors. I adopted these file-scope copyright
notices because that is what everyone was doing 30 years ago in the
days before distributed version control systems. But now, with many
contributors and modern version control systems, having these
file-scope copyright notices causes trouble when we update copyright
years or refactor code.
Over time, the file-scope copyright notices may become outdated as new
contributions are made or code is moved from one file to
another. Sometimes people contribute significant patches but do not
add a line claiming copyright. Other times, people add a copyright
notice for their contribution but then a later refactoring moves part
or all of their contribution to another file and the notice is not
moved with the code. As a practical matter, moving such notices is
difficult -- determining what parts are due to a particular
contributor requires a time-consuming search through the project
history. Even managing the yearly update of copyright years is
problematic. We have some contributors who are no longer
living. Should we update the copyright dates for their contributions
when we release new versions? Probably not, but we do still want to
claim copyright for the project as a whole.
To minimize the difficulty of maintaining the copyright notices, I
would like to change Octave's sources to use what is described here:
https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html
in the section "Maintaining centralized copyright notices":
The centralized notice approach consolidates all copyright
notices in a single location, usually a top-level file.
This file should contain all of the copyright notices
provided project contributors, unless the contribution was
clearly insignificant. It may also credit -- without a copyright
notice -- anyone who helped with the project but did not
contribute code or other copyrighted material.
This approach captures less information about contributions
within individual files, recognizing that the DVCS is better
equipped to record those details. As we mentioned before, it
does have one disadvantage as compared to the file-scope
approach: if a single file is separated from the distribution,
the recipient won't see the contributors' copyright notices.
But this can be easily remedied by including a single
copyright notice in each file's header, pointing to the
top-level file:
Copyright YYYY-YYYY The Octave Project Developers
See the COPYRIGHT file at the top-level directory
of this distribution or at https://octave.org/COPYRIGHT.html.
followed by the usual GPL copyright statement.
For more background, see the discussion here:
https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html
Most files in the following directories have been skipped intentinally
in this changeset:
doc
libgui/qterminal
liboctave/external
m4
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 15:38:17 -0500 |
parents | 00f796120a6d |
children | 1891570abac8 |
rev | line source |
---|---|
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
1 ## Copyright (C) 1995-2019 The Octave Project Developers |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
5 ## |
3426 | 6 ## |
3922 | 7 ## This file is part of Octave. |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
3922 | 10 ## 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
|
11 ## 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
|
12 ## (at your option) any later version. |
3426 | 13 ## |
3922 | 14 ## Octave is distributed in the hope that it will be useful, but |
3191 | 15 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
3426 | 18 ## |
3191 | 19 ## You should have received a copy of the GNU General Public License |
7016 | 20 ## 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
|
21 ## <https://www.gnu.org/licenses/>. |
3191 | 22 |
3449 | 23 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
24 ## @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
|
25 ## @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
|
26 ## @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
|
27 ## @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
|
28 ## @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
|
29 ## @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
|
30 ## Compute the short-time Fourier transform of the vector @var{x} with |
3449 | 31 ## @var{num_coef} coefficients by applying a window of @var{win_size} data |
32 ## points and an increment of @var{inc} points. | |
3191 | 33 ## |
34 ## Before computing the Fourier transform, one of the following windows | |
3449 | 35 ## is applied: |
36 ## | |
37 ## @table @asis | |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
38 ## @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
|
39 ## win_type = 1 |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
40 ## |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
41 ## @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
|
42 ## win_type = 2 |
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{"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
|
45 ## win_type = 3 |
3449 | 46 ## @end table |
47 ## | |
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 ## The window names can be passed as strings or by the @var{win_type} number. |
3191 | 49 ## |
17754
dffb1e9a6d3b
doc: Final spellcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
50 ## The following defaults are used for unspecified arguments: |
3449 | 51 ## @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
|
52 ## @var{win_type} = 1. |
3191 | 53 ## |
20165
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
54 ## @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
|
55 ## Fourier coefficients according to the @var{num_coef} positive frequencies. |
3449 | 56 ## |
25472
9771111f04f4
doc: Use @var rather than @code to mark inputs to functions in docstrings.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
57 ## @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
|
58 ## 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
|
59 ## 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
|
60 ## function. |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
61 ## @seealso{synthesis} |
3449 | 62 ## @end deftypefn |
3191 | 63 |
3457 | 64 ## 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
|
65 ## Description: Short-Time Fourier Transform |
3191 | 66 |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
67 function [y, c] = stft (x, win_size = 80, inc = 24, num_coef = 64, win_type = 1) |
3426 | 68 |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
69 if (nargin < 1 || nargin > 5) |
6046 | 70 print_usage (); |
3191 | 71 endif |
72 | |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
73 if (ischar (win_type)) |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
74 switch (tolower (win_type)) |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
75 case "hanning" win_type = 1; |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
76 case "hamming" win_type = 2; |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
77 case "rectangle" win_type = 3; |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
78 otherwise |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
79 error ("stft: unknown window type '%s'", win_type); |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
80 endswitch |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
81 endif |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
82 |
8506 | 83 ## Check whether X is a vector. |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
84 if (! isvector (x)) |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
85 error ("stft: X must be a vector"); |
3191 | 86 endif |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
87 x = x(:); |
3191 | 88 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
89 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
|
90 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
|
91 win_size = ncoef; |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
92 printf ("stft: window size adjusted to %f\n", win_size); |
3191 | 93 endif |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
94 num_win = fix ((rows (x) - win_size) / inc); |
3191 | 95 |
96 ## compute the window coefficients | |
17718
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
97 switch (win_type) |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
98 case 1 win_coef = hanning (win_size); |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
99 case 2 win_coef = hamming (win_size); |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
100 case 3 win_coef = ones (win_size, 1); |
6ed0a8532bcf
Overhaul stft and synthesis functions
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
101 endswitch |
3426 | 102 |
8506 | 103 ## 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
|
104 z = zeros (ncoef, num_win + 1); |
3191 | 105 start = 1; |
106 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
|
107 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
|
108 start += inc; |
3191 | 109 endfor |
110 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
111 y = fft (z); |
3191 | 112 |
113 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
|
114 y = abs (y(1:num_coef, :)); |
3191 | 115 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
|
116 c = [win_size, inc, win_type]; |
3191 | 117 endif |
118 | |
119 endfunction |