title: resampling, interpolating matrix
body: <p>I'm trying to interpolate some data for the purpose of plotting. For instance, given N data points, I'd like to be able to generate a "smooth" plot, made up of 10*N or so interpolated data points.</p>
  
  <p>My approach is to generate an N-by-10*N matrix and compute the inner product the original vector and the matrix I generated, yielding a 1-by-10*N vector.  I've already worked out the math I'd like to use for the interpolation, but my code is pretty slow.  I'm pretty new to Python, so I'm hopeful that some of the experts here can give me some ideas of ways I can try to speed up my code.</p>
  
  <p>I think part of the problem is that generating the matrix requires 10*N^2 calls to the following function:</p>
  
  <pre><code>def sinc(x):
      import math
      try:
          return math.sin(math.pi * x) / (math.pi * x)
      except ZeroDivisionError:
          return 1.0
  </code></pre>
  
  <p>(This <a href="http://en.wikipedia.org/wiki/Whittaker%E2%80%93Shannon_interpolation_formula" rel="noreferrer">comes from sampling theory</a>. Essentially, I'm attempting to recreate a signal from its samples, and upsample it to a higher frequency.)</p>
  
  <p>The matrix is generated by the following:</p>
  
  <pre><code>def resampleMatrix(Tso, Tsf, o, f):
      from numpy import array as npar
      retval = []
  
      for i in range(f):
          retval.append([sinc((Tsf*i - Tso*j)/Tso) for j in range(o)])
  
      return npar(retval)
  </code></pre>
  
  <p>I'm considering breaking up the task into smaller pieces because I don't like the idea of an N^2 matrix sitting in memory.  I could probably make 'resampleMatrix' into a generator function and do the inner product row-by-row, but I don't think that will speed up my code much until I start paging stuff in and out of memory.</p>
  
  <p>Thanks in advance for your suggestions!</p>