Mercurial > hg > octave-lyh
annotate scripts/signal/stft.m @ 10791:3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
interpreter/doccheck: New directory for spelling/grammar scripts.
interpreter/doccheck/README: Instructions for using scripts.
interpreter/doccheck/spellcheck: Script to spellcheck a Texinfo file.
interpreter/doccheck/aspell.conf: GNU Aspell configuration file for
Octave documentation.
interpreter/doccheck/aspell-octave.en.pws: Private Aspell dictionary.
interpreter/doccheck/add_to_aspell_dict: Script to add new
Octave-specific words to
private Aspell dictionary.
interpreter/octave.texi: New @nospell macro which forces Aspell
to ignore the word marked by the macro.
interpreter/mk_doc_cache.m: Skip new @nospell macro when building
doc_cache.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 17 Jul 2010 19:53:01 -0700 |
parents | bd8e388043c4 |
children | 693e22af08ae |
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 |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9072
diff
changeset
|
32 ## @item @nospell{hamming} |
3449 | 33 ## w_type = 2 |
34 ## @item rectangle | |
35 ## w_type = 3 | |
36 ## @end table | |
37 ## | |
38 ## The window names can be passed as strings or by the @var{w_type} number. | |
3191 | 39 ## |
40 ## If not all arguments are specified, the following defaults are used: | |
3449 | 41 ## @var{win_size} = 80, @var{inc} = 24, @var{num_coef} = 64, and |
42 ## @var{w_type} = 1. | |
3191 | 43 ## |
3449 | 44 ## @code{@var{y} = stft (@var{x}, @dots{})} returns the absolute values |
45 ## of the Fourier coefficients according to the @var{num_coef} positive | |
46 ## frequencies. | |
47 ## | |
48 ## @code{[@var{y}, @var{c}] = stft (@code{x}, @dots{})} returns the | |
49 ## entire STFT-matrix @var{y} and a 3-element vector @var{c} containing | |
50 ## the window size, increment, and window type, which is needed by the | |
51 ## synthesis function. | |
52 ## @end deftypefn | |
3191 | 53 |
3457 | 54 ## 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
|
55 ## Description: Short-Time Fourier Transform |
3191 | 56 |
57 function [Y, c] = stft(X, win, inc, coef, w_type) | |
3426 | 58 |
8506 | 59 ## Default values of unspecified arguments. |
3191 | 60 if (nargin < 5) |
61 w_type = 1; | |
62 if (nargin < 4) | |
63 coef = 64; | |
64 if (nargin < 3) | |
3426 | 65 inc = 24; |
66 if (nargin < 2) | |
67 win = 80; | |
68 endif | |
3191 | 69 endif |
70 endif | |
3426 | 71 elseif (nargin == 5) |
5443 | 72 if (ischar (w_type)) |
3191 | 73 if (strcmp (w_type, "hanning")) |
3426 | 74 w_type = 1; |
3191 | 75 elseif (strcmp (w_type, "hamming")) |
3426 | 76 w_type = 2; |
3191 | 77 elseif (strcmp (w_type, "rectangle")) |
3426 | 78 w_type = 3; |
3191 | 79 else |
3457 | 80 error ("stft: unknown window type `%s'", w_type); |
3191 | 81 endif |
82 endif | |
83 else | |
6046 | 84 print_usage (); |
3191 | 85 endif |
86 | |
8506 | 87 ## Check whether X is a vector. |
3191 | 88 [nr, nc] = size (X); |
89 if (nc != 1) | |
90 if (nr == 1) | |
3426 | 91 X = X'; |
3191 | 92 nr = nc; |
93 else | |
3457 | 94 error ("stft: X must be a vector"); |
3191 | 95 endif |
96 endif | |
97 | |
98 num_coef = 2 * coef; | |
99 if (win > num_coef) | |
100 win = num_coef; | |
3457 | 101 printf ("stft: window size adjusted to %f\n", win); |
3191 | 102 endif |
103 num_win = fix ((nr - win) / inc); | |
104 | |
105 ## compute the window coefficients | |
8506 | 106 if (w_type == 3) |
107 ## Rectangular window. | |
3191 | 108 WIN_COEF = ones (win, 1); |
8506 | 109 elseif (w_type == 2) |
110 ## Hamming window. | |
3191 | 111 WIN_COEF = hamming (win); |
8506 | 112 else |
113 ## Hanning window. | |
3191 | 114 WIN_COEF = hanning (win); |
115 endif | |
3426 | 116 |
8506 | 117 ## Create a matrix Z whose columns contain the windowed time-slices. |
3191 | 118 Z = zeros (num_coef, num_win + 1); |
119 start = 1; | |
120 for i = 0:num_win | |
121 Z(1:win, i+1) = X(start:start+win-1) .* WIN_COEF; | |
122 start = start + inc; | |
123 endfor | |
124 | |
125 Y = fft (Z); | |
126 | |
127 if (nargout == 1) | |
128 Y = abs (Y(1:coef, :)); | |
129 else | |
130 c = [win, inc, w_type]; | |
131 endif | |
132 | |
133 endfunction |