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} {} fractdiff (@var{x}, @var{d}) |
3499
|
19 ## Compute the fractional differences @math{(1-L)^d x} where @math{L} |
|
20 ## denotes the lag-operator and @math{d} is greater than -1. |
3449
|
21 ## @end deftypefn |
3426
|
22 |
3457
|
23 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
|
24 ## Description: Compute fractional differences |
3426
|
25 |
3191
|
26 function retval = fractdiff (x, d) |
3426
|
27 |
3191
|
28 N = 100; |
3426
|
29 |
3457
|
30 if (! is_vector (x)) |
|
31 error ("fractdiff: x must be a vector") |
3191
|
32 endif |
3426
|
33 |
3457
|
34 if (! is_scalar (d)) |
|
35 error ("fractdiff: d must be a scalar") |
3191
|
36 endif |
3426
|
37 |
|
38 |
3191
|
39 if (d >= 1) |
|
40 for k = 1 : d |
|
41 x = x(2 : length (x)) - x(1 : length (x) - 1); |
|
42 endfor |
|
43 endif |
3426
|
44 |
3191
|
45 if (d > -1) |
3426
|
46 |
3191
|
47 d = rem (d, 1); |
3426
|
48 |
3191
|
49 if (d != 0) |
|
50 n = (0 : N)'; |
|
51 w = real (gamma (-d+n) ./ gamma (-d) ./ gamma (n+1)); |
|
52 retval = fftfilt (w, x); |
|
53 retval = retval(1 : length (x)); |
|
54 else |
|
55 retval = x; |
|
56 endif |
3426
|
57 |
3191
|
58 else |
3457
|
59 error ("fractdiff: d must be > -1"); |
3426
|
60 |
3191
|
61 endif |
3426
|
62 |
3191
|
63 endfunction |