Authored by David Mayerich
1 parent 2ce6954b

### implemented finite differences and SG filters in stim::envi

Showing 7 changed files with 521 additions and 0 deletions
matlab/fd_coefficients.m 0 → 100644

 1 +function c = fd_coefficients(z,x,m) 2 +% Calculates FD weights. The parameters are: 3 +% z location where approximations are to be accurate, 4 +% x vector with x-coordinates for grid points, 5 +% m highest derivative that we want to find weights for 6 +% c array size m+1,lentgh(x) containing (as output) in 7 +% successive rows the weights for derivatives 0,1,...,m. 8 + 9 +n=length(x); c=zeros(m+1,n); c1=1; c4=x(1)-z; c(1,1)=1; 10 +for i=2:n 11 + mn=min(i,m+1); c2=1; c5=c4; c4=x(i)-z; 12 + for j=1:i-1 13 + c3=x(i)-x(j); c2=c2*c3; 14 + if j==i-1 15 + c(2:mn,i)=c1*((1:mn-1)'.*c(1:mn-1,i-1)-c5*c(2:mn,i-1))/c2; 16 + c(1,i)=-c1*c5*c(1,i-1)/c2; 17 + end 18 + c(2:mn,j)=(c4*c(2:mn,j)-(1:mn-1)'.*c(1:mn-1,j))/c3; 19 + c(1,j)=c4*c(1,j)/c3; 20 + end 21 + c1=c2; 22 +end 0 23 \ No newline at end of file ... ...
matlab/sg_coefficients.m 0 → 100644

 1 +function C = sg_coefficients(n, order) 2 + 3 +if(mod(n, 2) == 0) 4 + disp('The number of coefficients must be odd'); 5 + return; 6 +end 7 + 8 +%assemble the column vector based on positions 9 +r = floor(n/2); %maximum extent around zero (0) 10 +x = -r:1:r; 11 + 12 +%calculate J 13 +J = zeros(n, order + 1); 14 + 15 +%columns values are 1, x_i, x_i^2, ... 16 +for i = 1:order+1 17 + J(:, i) = (x').^(i-1); 18 +end 19 +C = (J' * J)^(-1) * J'; 0 20 \ No newline at end of file ... ...
stim/envi/bil.h