3191
|
1 ## Copyright (C) 1995, 1996, 1997 Andreas Weingessel |
|
2 ## |
|
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. |
|
7 ## |
|
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 |
|
11 ## General Public License for more details. |
|
12 ## |
|
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 |
|
17 ## usage: X = synthesis (Y, c) |
|
18 ## |
|
19 ## recovers a signal X from its short-time Fourier transform Y. c = |
|
20 ## [win_size, increment, window_type]. |
|
21 ## |
|
22 ## Y and c can be derived by [Y, c] = stft (X [, ...]). |
|
23 |
|
24 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
|
25 ## Description: Recover a signal from its short-term Fourier transform |
|
26 |
|
27 function X = synthesis (Y, c) |
|
28 |
|
29 if (nargin != 2) |
|
30 usage ("X = synthesis (Y, c)"); |
|
31 endif |
|
32 |
3238
|
33 [nr, nc] = size (c); |
3191
|
34 if (nr * nc != 3) |
|
35 error ("synthesis: c must contain exactly 3 elements"); |
|
36 endif |
|
37 |
|
38 ## not necessary, enables better reading |
|
39 win = c(1); |
|
40 inc = c(2); |
|
41 w_type = c(3); |
|
42 |
|
43 if (w_type == 1) |
|
44 H = hanning (win); |
|
45 elseif (w_type == 2) |
|
46 H = hamming (win); |
|
47 elseif (w_type == 3) |
|
48 H = ones (win, 1); |
|
49 else |
|
50 error ("synthesis: window_type must be 1, 2, or 3"); |
|
51 endif |
|
52 |
|
53 Z = real (ifft (Y)); |
|
54 st = fix ((win-inc) / 2); |
|
55 Z = Z(st:st+inc-1, :); |
|
56 H = H(st:st+inc-1); |
|
57 |
|
58 nc = columns(Z); |
|
59 for i = 1:nc |
|
60 Z(:, i) = Z(:, i) ./ H; |
|
61 endfor |
|
62 |
|
63 X = reshape(Z, inc * nc, 1); |
|
64 |
|
65 endfunction |