title: Linear Interpolation. How to implement this algorithm in C ? (Python version is given)
body: <p>There exists one very good linear interpolation method. It performs linear interpolation requiring <strong>at most one multiply per output sample</strong>. I found its description in a third edition of Understanding DSP by Lyons. This method involves a special hold buffer. Given a number of samples to be inserted between any two input samples, it produces output points using linear interpolation. Here, I have rewritten this algorithm using Python:</p>
  
  <pre><code>temp1, temp2 = 0, 0
  iL = 1.0 / L
  for i in x:
     hold = [i-temp1] * L
     temp1 = i
     for j in hold:
        temp2 += j
        y.append(temp2 *iL)
  </code></pre>
  
  <p>where x contains input samples, L is a number of points to be inserted, y will contain output samples.</p>
  
  <p>My question is <strong>how to implement such algorithm in ANSI C in a most effective way</strong>, e.g. is it possible to avoid the second loop?</p>
  
  <p>NOTE: presented Python code is just to understand how this algorithm works. </p>
  
  <p>UPDATE: here is an example how it works in Python:</p>
  
  <pre><code>x=[]
  y=[]
  hold=[]
  num_points=20
  points_inbetween = 2
  
  temp1,temp2=0,0
  
  for i in range(num_points):
     x.append( sin(i*2.0*pi * 0.1) )
  
  L = points_inbetween
  iL = 1.0/L
  for i in x:
     hold = [i-temp1] * L
     temp1 = i
     for j in hold:
        temp2 += j
        y.append(temp2 * iL)
  </code></pre>
  
  <p>Let's say x=[.... 10, 20, 30 ....]. Then, if L=1, it will produce [... 10, 15, 20, 25, 30 ...]</p>