home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / signal / sinetone.m < prev    next >
Text File  |  1997-02-26  |  2KB  |  61 lines

  1. ## Copyright (C) 1995, 1996, 1997  Friedrich Leisch
  2. ## 
  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.
  7. ## 
  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
  11. ## General Public License for more details. 
  12. ## 
  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.
  24.     
  25. ## Author:  FL <Friedrich.Leisch@ci.tuwien.ac.at>
  26. ## Description:  Compute a sine tone
  27.   
  28. function retval = sinetone (f, r, s, a)
  29.   
  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
  42.   
  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
  47.   
  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
  58.   
  59. endfunction
  60.  
  61.