title: How to smooth interpolation of a float array into a bigger array?
body: <p>I'm stuck with interpolation in Swift. Can anyone help me with that?</p>
  <p>I want to interpolate the float array (say <code>[0, 0, 100, 25, 0, 0, 0, 25, 0, 0, 0]</code>) into another array with some given size (for example <strong>128</strong>). I found an article (<a href="https://developer.apple.com/documentation/accelerate/use_linear_interpolation_to_construct_new_data_points" rel="noreferrer">Use Linear Interpolation to Construct New Data Points</a>) that shows, how to achieve this stuff.</p>
  <p>There are two ways (you can see the results below, how they perform):</p>
  <ul>
  <li>Linear Interpolation using <code>vDSP_vgenp</code> and</li>
  <li>Smoother (but not for my purposes) Interpolation using <code>vDSP_vlint</code></li>
  </ul>
  <p>The problem is both techniques don't realize my expectations, which illustrated in <a href="https://i.stack.imgur.com/DVxFP.png" rel="noreferrer">Screenshot 3</a>. How can I make my <em>interpolated</em> distribution smoother? I want to see a <strong>cube-like curve</strong>.</p>
  <p><strong>Initial Plot:</strong></p>
  <p><img src="https://i.stack.imgur.com/P67en.png" alt="Screenshot 1" /></p>
  <p><strong>Linear Interpolation:</strong></p>
  <pre class="lang-swift prettyprint-override"><code>import Accelerate
  
  let n = vDSP_Length(128)
  let stride = vDSP_Stride(1)
  
  let values: [Float] = [0, 0, 100, 25, 0, 0, 0, 25, 0, 0, 0]
  let indices: [Float] = [0, 11, 23, 34, 46, 58, 69, 81, 93, 104, 116]
  
  var result = [Float](repeating: 0, count: Int(n))
  
  vDSP_vgenp(values, stride, indices, stride, &amp;result, stride, n, vDSP_Length(values.count))
  </code></pre>
  <p><img src="https://i.stack.imgur.com/tWyFx.png" alt="Screenshot 2" /></p>
  <p><strong>Smooth Interpolation:</strong></p>
  <pre class="lang-swift prettyprint-override"><code>import Accelerate
  import AVFoundation
  
  let n = vDSP_Length(1024)
  let stride = vDSP_Stride(1)
  
  let values: [Float] = [0, 0, 100, 25, 0, 0, 0, 25, 0, 0, 0]
  let denominator = Float(n) / Float(values.count - 1)
  
  let control: [Float] = (0 ... n).map {
      let x = Float($0) / denominator
      return floor(x) + simd_smoothstep(0, 1, simd_fract(x))
  }
  
  var result = [Float](repeating: 0, count: Int(n))
  
  vDSP_vlint(values, control, stride, &amp;result, stride, n, vDSP_Length(values.count))
  </code></pre>
  <p><img src="https://i.stack.imgur.com/DVxFP.png" alt="Screenshot 3" /></p>