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