function [matrix]=fractional_diff(length,degree)

%    [matrix]=fractional_diff(length,degree)
%
%    Generate a differencing/integrating matrix of any order including
%    fractional.  These are the discrete-time versions of fractional
%    differentiation and integration.  For fractional degrees other than
%    powers of 1/2 this is an approximation which gets better as length
%    gets longer.
%
%    length    size of filter matrix (number of elements)
%    degree    differencing/integrating exponent:
%              differencing => degree > 0
%              integrating  => degree < 0
%
%    matrix    square filter matrix

% See Hosking, R. M., 1981, Biometrika, 68, pp. 165-176

% Hadley Johnson, hjohnson@ucsd.edu, 11-Aug-1998 version

column=cumprod([1;[0:1:length-2]'-degree]./[1;[1:1:length-1]']);

matrix=zeros(length,length);

for i=1:length,
  matrix(i:length,i)=column(1:length+1-i);
end
