]> Creatis software - CreaPhase.git/blob - octave_packages/signal-1.1.3/cheb.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / signal-1.1.3 / cheb.m
1 ## Copyright (C) 2002 AndrĂ© Carezia <acarezia@uol.com.br>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## Usage:  cheb (n, x)
17 ##
18 ## Returns the value of the nth-order Chebyshev polynomial calculated at
19 ## the point x. The Chebyshev polynomials are defined by the equations:
20 ##
21 ##           / cos(n acos(x),    |x| <= 1
22 ##   Tn(x) = |
23 ##           \ cosh(n acosh(x),  |x| > 1
24 ##
25 ## If x is a vector, the output is a vector of the same size, where each
26 ## element is calculated as y(i) = Tn(x(i)).
27
28 function T = cheb (n, x)
29   if (nargin != 2)
30     print_usage;
31   elseif !(isscalar (n) && (n == round(n)) && (n >= 0))
32     error ("cheb: n has to be a positive integer");
33   endif
34
35   if (max(size(x)) == 0)
36     T = [];
37   endif
38         # avoid resizing latencies
39   T = zeros(size(x));
40   ind = abs (x) <= 1;
41   if (max(size(ind)))
42     T(ind) = cos(n*acos(x(ind)));
43   endif
44
45   ind = abs (x) > 1;
46   if (max(size(ind)))
47     T(ind) = cosh(n*acosh(x(ind)));
48   endif
49
50   T = real(T);
51 endfunction