Mercurial > octave-nkf
annotate scripts/signal/stft.m @ 10821:693e22af08ae
Grammarcheck documentation of m-files
Add newlines between @item fields for readability.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 26 Jul 2010 21:25:36 -0700 |
parents | 3140cb7a05a1 |
children | c776f063fefe |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2005, 2006, 2007, 2009 |
7017 | 2 ## Andreas Weingessel |
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 -*- |
6547 | 21 ## @deftypefn {Function File} {[@var{y}, @var{c}] =} stft (@var{x}, @var{win_size}, @var{inc}, @var{num_coef}, @var{w_type}) |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
22 ## Compute the short-time Fourier transform of the vector @var{x} with |
3449 | 23 ## @var{num_coef} coefficients by applying a window of @var{win_size} data |
24 ## points and an increment of @var{inc} points. | |
3191 | 25 ## |
26 ## Before computing the Fourier transform, one of the following windows | |
3449 | 27 ## is applied: |
28 ## | |
29 ## @table @asis | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9072
diff
changeset
|
30 ## @item @nospell{hanning} |
3449 | 31 ## w_type = 1 |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
32 ## |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9072
diff
changeset
|
33 ## @item @nospell{hamming} |
3449 | 34 ## w_type = 2 |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
35 ## |
3449 | 36 ## @item rectangle |
37 ## w_type = 3 | |
38 ## @end table | |
39 ## | |
40 ## The window names can be passed as strings or by the @var{w_type} number. | |
3191 | 41 ## |
42 ## If not all arguments are specified, the following defaults are used: | |
3449 | 43 ## @var{win_size} = 80, @var{inc} = 24, @var{num_coef} = 64, and |
44 ## @var{w_type} = 1. | |
3191 | 45 ## |
3449 | 46 ## @code{@var{y} = stft (@var{x}, @dots{})} returns the absolute values |
47 ## of the Fourier coefficients according to the @var{num_coef} positive | |
48 ## frequencies. | |
49 ## | |
50 ## @code{[@var{y}, @var{c}] = stft (@code{x}, @dots{})} returns the | |
51 ## entire STFT-matrix @var{y} and a 3-element vector @var{c} containing | |
52 ## the window size, increment, and window type, which is needed by the | |
53 ## synthesis function. | |
54 ## @end deftypefn | |
3191 | 55 |
3457 | 56 ## 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
|
57 ## Description: Short-Time Fourier Transform |
3191 | 58 |
59 function [Y, c] = stft(X, win, inc, coef, w_type) | |
3426 | 60 |
8506 | 61 ## Default values of unspecified arguments. |
3191 | 62 if (nargin < 5) |
63 w_type = 1; | |
64 if (nargin < 4) | |
65 coef = 64; | |
66 if (nargin < 3) | |
3426 | 67 inc = 24; |
68 if (nargin < 2) | |
69 win = 80; | |
70 endif | |
3191 | 71 endif |
72 endif | |
3426 | 73 elseif (nargin == 5) |
5443 | 74 if (ischar (w_type)) |
3191 | 75 if (strcmp (w_type, "hanning")) |
3426 | 76 w_type = 1; |
3191 | 77 elseif (strcmp (w_type, "hamming")) |
3426 | 78 w_type = 2; |
3191 | 79 elseif (strcmp (w_type, "rectangle")) |
3426 | 80 w_type = 3; |
3191 | 81 else |
3457 | 82 error ("stft: unknown window type `%s'", w_type); |
3191 | 83 endif |
84 endif | |
85 else | |
6046 | 86 print_usage (); |
3191 | 87 endif |
88 | |
8506 | 89 ## Check whether X is a vector. |
3191 | 90 [nr, nc] = size (X); |
91 if (nc != 1) | |
92 if (nr == 1) | |
3426 | 93 X = X'; |
3191 | 94 nr = nc; |
95 else | |
3457 | 96 error ("stft: X must be a vector"); |
3191 | 97 endif |
98 endif | |
99 | |
100 num_coef = 2 * coef; | |
101 if (win > num_coef) | |
102 win = num_coef; | |
3457 | 103 printf ("stft: window size adjusted to %f\n", win); |
3191 | 104 endif |
105 num_win = fix ((nr - win) / inc); | |
106 | |
107 ## compute the window coefficients | |
8506 | 108 if (w_type == 3) |
109 ## Rectangular window. | |
3191 | 110 WIN_COEF = ones (win, 1); |
8506 | 111 elseif (w_type == 2) |
112 ## Hamming window. | |
3191 | 113 WIN_COEF = hamming (win); |
8506 | 114 else |
115 ## Hanning window. | |
3191 | 116 WIN_COEF = hanning (win); |
117 endif | |
3426 | 118 |
8506 | 119 ## Create a matrix Z whose columns contain the windowed time-slices. |
3191 | 120 Z = zeros (num_coef, num_win + 1); |
121 start = 1; | |
122 for i = 0:num_win | |
123 Z(1:win, i+1) = X(start:start+win-1) .* WIN_COEF; | |
124 start = start + inc; | |
125 endfor | |
126 | |
127 Y = fft (Z); | |
128 | |
129 if (nargout == 1) | |
130 Y = abs (Y(1:coef, :)); | |
131 else | |
132 c = [win, inc, w_type]; | |
133 endif | |
134 | |
135 endfunction |