Mercurial > hg > ishara
annotate general/numerical/frint.m @ 16:db7f4afd27c5
Rearranging numerical toolbox.
author | samer |
---|---|
date | Thu, 17 Jan 2013 13:20:44 +0000 |
parents | e44f49929e56 |
children |
rev | line source |
---|---|
samer@4 | 1 function y=frint(r,x,dc) |
samer@4 | 2 % frint - Fractional integration |
samer@4 | 3 % |
samer@4 | 4 % y=frint(r,x[,dc]) |
samer@4 | 5 % Returns the rth order integral of x, where r can be fractional |
samer@4 | 6 % if dc=0 (default is 1) dc term is not added back in |
samer@4 | 7 |
samer@4 | 8 x=x(:); |
samer@4 | 9 n=length(x); |
samer@4 | 10 z=fft(x); z0=z(1); z(1)=0; |
samer@4 | 11 K=(0:n-1)'; |
samer@4 | 12 D=exp(2*pi*i*K/n)-1; |
samer@4 | 13 D(1)=1; % to avoid divide by zero |
samer@4 | 14 z2=z./D.^r; |
samer@4 | 15 y=real(ifft(z2)); % integral minus DC term |
samer@4 | 16 |
samer@4 | 17 % put DC term back as a ramp |
samer@4 | 18 if nargin<3 || dc==1, |
samer@4 | 19 y=y+sign(z0)*(K*abs(z0)/n).^r; |
samer@4 | 20 end |
samer@4 | 21 |
samer@4 | 22 |