]> Creatis software - CreaPhase.git/blob - octave_packages/m/signal/fractdiff.m
update packages
[CreaPhase.git] / octave_packages / m / signal / fractdiff.m
1 ## Copyright (C) 1995-2012 Friedrich Leisch
2 ##
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} fractdiff (@var{x}, @var{d})
21 ## Compute the fractional differences @math{(1-L)^d x} where @math{L}
22 ## denotes the lag-operator and @math{d} is greater than -1.
23 ## @end deftypefn
24
25 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at>
26 ## Description: Compute fractional differences
27
28 function retval = fractdiff (x, d)
29
30   if (nargin != 2)
31     print_usage ();
32   endif
33
34   N = 100;
35
36   if (! isvector (x))
37     error ("fractdiff: X must be a vector");
38   endif
39
40   if (! isscalar (d))
41     error ("fractdiff: D must be a scalar");
42   endif
43
44
45   if (d >= 1)
46     for k = 1 : d
47       x = x(2 : length (x)) - x(1 : length (x) - 1);
48     endfor
49   endif
50
51   if (d > -1)
52
53     d = rem (d, 1);
54
55     if (d != 0)
56       n = (0 : N)';
57       w = real (gamma (-d+n) ./ gamma (-d) ./ gamma (n+1));
58       retval = fftfilt (w, x);
59       retval = retval(1 : length (x));
60     else
61       retval = x;
62     endif
63
64   else
65     error ("fractdiff: D must be > -1");
66
67   endif
68
69 endfunction