Blame view

matlab/sg_coefficients.m 394 Bytes
9b2a5d71   David Mayerich   implemented finit...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  function C = sg_coefficients(n, order)
  
  if(mod(n, 2) == 0)
      disp('The number of coefficients must be odd');
      return;
  end
  
  %assemble the column vector based on positions
  r = floor(n/2);         %maximum extent around zero (0)
  x = -r:1:r;
  
  %calculate J
  J = zeros(n, order + 1);
  
  %columns values are 1, x_i, x_i^2, ...
  for i = 1:order+1
      J(:, i) = (x').^(i-1);
  end
  C = (J' * J)^(-1) * J';