3191
|
1 ## Copyright (C) 1995, 1996, 1997 Friedrich Leisch |
3426
|
2 ## |
3922
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
3426
|
9 ## |
3922
|
10 ## Octave is distributed in the hope that it will be useful, but |
3191
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
13 ## General Public License for more details. |
|
14 ## |
3191
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3191
|
18 |
3449
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} sinetone (@var{freq}, @var{rate}, @var{sec}, @var{ampl}) |
|
21 ## Return a sinetone of frequency @var{freq} with length of @var{sec} |
|
22 ## seconds at sampling rate @var{rate} and with amplitude @var{ampl}. |
|
23 ## The arguments @var{freq} and @var{ampl} may be vectors of common size. |
3191
|
24 ## |
3449
|
25 ## Defaults are @var{rate} = 8000, @var{sec} = 1 and @var{ampl} = 64. |
|
26 ## @end deftypefn |
3426
|
27 |
3457
|
28 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
29 ## Description: Compute a sine tone |
3426
|
30 |
3191
|
31 function retval = sinetone (f, r, s, a) |
3426
|
32 |
3191
|
33 if (nargin == 1) |
|
34 r = 8000; |
|
35 s = 1; |
|
36 a = 64; |
|
37 elseif (nargin == 2) |
|
38 s = 1; |
|
39 a = 64; |
|
40 elseif (nargin == 3) |
|
41 a = 64; |
|
42 elseif ((nargin < 1) || (nargin > 4)) |
6046
|
43 print_usage (); |
3191
|
44 endif |
3426
|
45 |
3191
|
46 [err, f, a] = common_size (f, a); |
4030
|
47 if (err || ! isvector (f)) |
3457
|
48 error ("sinetone: freq and ampl must be vectors of common size"); |
3191
|
49 endif |
3426
|
50 |
4030
|
51 if (! (isscalar (r) && isscalar (s))) |
3457
|
52 error ("sinetone: rate and sec must be scalars"); |
3191
|
53 endif |
|
54 |
|
55 n = length (f); |
|
56 |
|
57 retval = zeros (r * s, n); |
|
58 for k = 1:n |
|
59 retval (:, k) = a(k) * sin (2 * pi * (1:r*s) / r * f(k))'; |
|
60 endfor |
3426
|
61 |
3191
|
62 endfunction |
|
63 |