Skip to content

Instantly share code, notes, and snippets.

@ndvbd
Created February 28, 2017 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndvbd/dd2351d0869894c43ee20541c29aaae1 to your computer and use it in GitHub Desktop.
Save ndvbd/dd2351d0869894c43ee20541c29aaae1 to your computer and use it in GitHub Desktop.
def sinc_interp(x, s, u):
"""
Interpolates x, sampled at "s" instants
Output y is sampled at "u" instants ("u" for "upsampled")
"""
if len(x) != len(s):
raise Exception, 'x and s must be the same length'
# Find the period
T = s[1] - s[0]
transposed = np.transpose(np.tile(np.arange(len(s)), (len(u),1))) * T
sincM = np.tile(u, (len(s), 1)) - transposed
y = np.dot(x, np.sinc(sincM / T))
return y
@ndvbd
Copy link
Author

ndvbd commented Feb 28, 2017

That's a quick python implementation for the Whittaker–Shannon interpolation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment