7017
|
1 ## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2005, 2006, |
|
2 ## 2007 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 -*- |
3500
|
21 ## @deftypefn {Function File} {} synthesis (@var{y}, @var{c}) |
3449
|
22 ## Compute a signal from its short-time Fourier transform @var{y} and a |
|
23 ## 3-element vector @var{c} specifying window size, increment, and |
|
24 ## window type. |
3191
|
25 ## |
3449
|
26 ## The values @var{y} and @var{c} can be derived by |
3191
|
27 ## |
3449
|
28 ## @example |
|
29 ## [@var{y}, @var{c}] = stft (@var{x} , @dots{}) |
|
30 ## @end example |
|
31 ## @end deftypefn |
3426
|
32 |
3457
|
33 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
|
34 ## Description: Recover a signal from its short-term Fourier transform |
3191
|
35 |
|
36 function X = synthesis (Y, c) |
3426
|
37 |
3191
|
38 if (nargin != 2) |
6046
|
39 print_usage (); |
3191
|
40 endif |
3426
|
41 |
3238
|
42 [nr, nc] = size (c); |
3191
|
43 if (nr * nc != 3) |
3457
|
44 error ("synthesis: c must contain exactly 3 elements"); |
3191
|
45 endif |
3426
|
46 |
3191
|
47 ## not necessary, enables better reading |
3426
|
48 win = c(1); |
3191
|
49 inc = c(2); |
|
50 w_type = c(3); |
3426
|
51 |
3191
|
52 if (w_type == 1) |
|
53 H = hanning (win); |
|
54 elseif (w_type == 2) |
|
55 H = hamming (win); |
|
56 elseif (w_type == 3) |
|
57 H = ones (win, 1); |
|
58 else |
3457
|
59 error ("synthesis: window_type must be 1, 2, or 3"); |
3191
|
60 endif |
3426
|
61 |
3191
|
62 Z = real (ifft (Y)); |
|
63 st = fix ((win-inc) / 2); |
|
64 Z = Z(st:st+inc-1, :); |
|
65 H = H(st:st+inc-1); |
|
66 |
|
67 nc = columns(Z); |
|
68 for i = 1:nc |
|
69 Z(:, i) = Z(:, i) ./ H; |
|
70 endfor |
3426
|
71 |
3191
|
72 X = reshape(Z, inc * nc, 1); |
3426
|
73 |
3191
|
74 endfunction |