3191
|
1 ## Copyright (C) 1995, 1996, 1997 Andreas Weingessel |
3426
|
2 ## |
3191
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
3426
|
7 ## |
3191
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
11 ## General Public License for more details. |
|
12 ## |
3191
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this file. If not, write to the Free Software Foundation, |
|
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
16 |
3449
|
17 ## -*- texinfo -*- |
|
18 ## @deftypefn {Function File} {@var{x} =} synthesis (@var{y}, @var{c}) |
|
19 ## Compute a signal from its short-time Fourier transform @var{y} and a |
|
20 ## 3-element vector @var{c} specifying window size, increment, and |
|
21 ## window type. |
3191
|
22 ## |
3449
|
23 ## The values @var{y} and @var{c} can be derived by |
3191
|
24 ## |
3449
|
25 ## @example |
|
26 ## [@var{y}, @var{c}] = stft (@var{x} , @dots{}) |
|
27 ## @end example |
|
28 ## @end deftypefn |
3426
|
29 |
3457
|
30 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
|
31 ## Description: Recover a signal from its short-term Fourier transform |
3191
|
32 |
|
33 function X = synthesis (Y, c) |
3426
|
34 |
3191
|
35 if (nargin != 2) |
|
36 usage ("X = synthesis (Y, c)"); |
|
37 endif |
3426
|
38 |
3238
|
39 [nr, nc] = size (c); |
3191
|
40 if (nr * nc != 3) |
3457
|
41 error ("synthesis: c must contain exactly 3 elements"); |
3191
|
42 endif |
3426
|
43 |
3191
|
44 ## not necessary, enables better reading |
3426
|
45 win = c(1); |
3191
|
46 inc = c(2); |
|
47 w_type = c(3); |
3426
|
48 |
3191
|
49 if (w_type == 1) |
|
50 H = hanning (win); |
|
51 elseif (w_type == 2) |
|
52 H = hamming (win); |
|
53 elseif (w_type == 3) |
|
54 H = ones (win, 1); |
|
55 else |
3457
|
56 error ("synthesis: window_type must be 1, 2, or 3"); |
3191
|
57 endif |
3426
|
58 |
3191
|
59 Z = real (ifft (Y)); |
|
60 st = fix ((win-inc) / 2); |
|
61 Z = Z(st:st+inc-1, :); |
|
62 H = H(st:st+inc-1); |
|
63 |
|
64 nc = columns(Z); |
|
65 for i = 1:nc |
|
66 Z(:, i) = Z(:, i) ./ H; |
|
67 endfor |
3426
|
68 |
3191
|
69 X = reshape(Z, inc * nc, 1); |
3426
|
70 |
3191
|
71 endfunction |