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