1
$\begingroup$

From http://en.wikipedia.org/wiki/Trigonometric_interpolation trigonometric interpolation can be calculated as follows:

Trigonometric interpolation

Now assume we have 6 data points (0, 0.1), (1, 0.3), (2, 0.4), (5, 0.3), (6, 0.2), (7, 0). We want to interpolate the two missing points at 3 and 4.

Data points

How can we calculate the two missing points using trigonometric interpolation?

$\endgroup$
  • 1
    $\begingroup$ Hint: Use the given Lagrange type solution in the Wiki article to compute $p(3), p(4)$. $\endgroup$ – gammatester Sep 12 '13 at 11:15
  • $\begingroup$ I'm a bit confused what exactly N is. Is it the number of available samples (eg: 6 in the example) or your sample range (in the example: 7 - 0 + 1 = 8). If it's not too much effort, could you show how to calculate the 4th sample (at index 3)? $\endgroup$ – goocreations Sep 12 '13 at 12:07
  • $\begingroup$ The Wiki article indicates that in your case the polynomial is not unique. I suggest you drop the e.g. last data point, then you can apply the formula (and do the same for first, to see the difference between solutions). Another option is to keep the 6 points and add another helper point at say (6.5, 0.1). $\endgroup$ – gammatester Sep 12 '13 at 12:27
  • 1
    $\begingroup$ Nice to hear. I just coded a small Pascal program using the first five data points and get the values $p(3)=0.42$ and $p(4)=0.38$. $\endgroup$ – gammatester Sep 12 '13 at 13:49
  • 1
    $\begingroup$ With my example above I now get p(3) = 15.4021 and p(4) = 17.5876, so I'm doing something wrong somewhere. Your Pascal code could really help. $\endgroup$ – goocreations Sep 12 '13 at 14:10
1
$\begingroup$

Here is a simple answer with the Pascal code mentioned in the comment. Please note that only the missing points are computed not the explicit polynomial:

const
  x: array[0..5] of double = (0,   1,   2,   5,   6,   7);
  y: array[0..5] of double = (0.1, 0.3, 0.4, 0.3, 0.2, 0);

function interpol(u: double): double;
var
  k,m: integer;
  p,f,s: double;
begin
  p := 0.0;
  for k:=0 to 4 do begin
    f := 1.0;
    for m:=0 to 4 do begin
      if m<>k then begin
        s :=   sin(0.25*(u   -x[m])/Pi);
        s := s/sin(0.25*(x[k]-x[m])/Pi);
        f := s*f;
      end;
    end;
    p := p+f*y[k];
  end;
  interpol := p;
end;

var
  u: double;
begin
  u := 3.0;
  writeln('u p(u) = ', u:6:2, interpol(u):10:2);
  u := 4.0;
  writeln('u p(u) = ', u:6:2, interpol(u):10:2);
end.

The output is:

u p(u) =   3.00      0.42
u p(u) =   4.00      0.38
$\endgroup$
  • $\begingroup$ Ahh, finally got it working, I missed the divide by Pi the entire time. Can't believe my stupid mistake. Thanks gammatester for all your help, I appreciate it. $\endgroup$ – goocreations Sep 12 '13 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.