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