3191
|
1 ## Copyright (C) 1995, 1996, 1997 Friedrich Leisch |
3426
|
2 ## |
3191
|
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. |
3426
|
7 ## |
3191
|
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 |
3426
|
11 ## General Public License for more details. |
|
12 ## |
3191
|
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 |
3449
|
17 ## -*- texinfo -*- |
|
18 ## @deftypefn {Function File} {} sinetone (@var{freq}, @var{rate}, @var{sec}, @var{ampl}) |
|
19 ## Return a sinetone of frequency @var{freq} with length of @var{sec} |
|
20 ## seconds at sampling rate @var{rate} and with amplitude @var{ampl}. |
|
21 ## The arguments @var{freq} and @var{ampl} may be vectors of common size. |
3191
|
22 ## |
3449
|
23 ## Defaults are @var{rate} = 8000, @var{sec} = 1 and @var{ampl} = 64. |
|
24 ## @end deftypefn |
3426
|
25 |
3191
|
26 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
27 ## Description: Compute a sine tone |
3426
|
28 |
3191
|
29 function retval = sinetone (f, r, s, a) |
3426
|
30 |
3191
|
31 if (nargin == 1) |
|
32 r = 8000; |
|
33 s = 1; |
|
34 a = 64; |
|
35 elseif (nargin == 2) |
|
36 s = 1; |
|
37 a = 64; |
|
38 elseif (nargin == 3) |
|
39 a = 64; |
|
40 elseif ((nargin < 1) || (nargin > 4)) |
3449
|
41 usage ("sinetone (freq, rate, sec, ampl)"); |
3191
|
42 endif |
3426
|
43 |
3191
|
44 [err, f, a] = common_size (f, a); |
|
45 if (err || ! is_vector (f)) |
|
46 error ("sinetone: freq and ampl must be vectors of common size"); |
|
47 endif |
3426
|
48 |
3191
|
49 if !(is_scalar (r) && is_scalar (s)) |
|
50 error ("sinetone: rate and sec must be scalars"); |
|
51 endif |
|
52 |
|
53 n = length (f); |
|
54 |
|
55 retval = zeros (r * s, n); |
|
56 for k = 1:n |
|
57 retval (:, k) = a(k) * sin (2 * pi * (1:r*s) / r * f(k))'; |
|
58 endfor |
3426
|
59 |
3191
|
60 endfunction |
|
61 |