Mercurial > hg > octave-nkf
annotate scripts/signal/synthesis.m @ 11469:c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 09 Jan 2011 12:41:21 -0800 |
parents | a1dbe9d80eee |
children | 1740012184f9 |
rev | line source |
---|---|
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 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
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 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
47 w_size = c(1); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
48 inc = c(2); |
3191 | 49 w_type = c(3); |
3426 | 50 |
3191 | 51 if (w_type == 1) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
52 w_coeff = hanning (w_size); |
3191 | 53 elseif (w_type == 2) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
54 w_coeff = hamming (w_size); |
3191 | 55 elseif (w_type == 3) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
56 w_coeff = ones (w_size, 1); |
3191 | 57 else |
3457 | 58 error ("synthesis: window_type must be 1, 2, or 3"); |
3191 | 59 endif |
3426 | 60 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
61 z = real (ifft (y)); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
62 st = fix ((w_size-inc) / 2); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
63 z = z(st:st+inc-1, :); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
64 w_coeff = w_coeff(st:st+inc-1); |
3191 | 65 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
66 nc = columns(z); |
3191 | 67 for i = 1:nc |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
68 z(:, i) = z(:, i) ./ w_coeff; |
3191 | 69 endfor |
3426 | 70 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
71 x = reshape(z, inc * nc, 1); |
3426 | 72 |
3191 | 73 endfunction |