Skip to content

Instantly share code, notes, and snippets.

@ptweir
Created June 28, 2012 00:05
Show Gist options
  • Select an option

  • Save ptweir/3007746 to your computer and use it in GitHub Desktop.

Select an option

Save ptweir/3007746 to your computer and use it in GitHub Desktop.
Find closest dense samples to sparsely sampled data
def findClosestSampleTimes(denseSamples,sparseSamples,debug=False):
"""inds, samples = findClosestSampleTimes(denseSamples,sparseSamples)
NOTE: SHOULD CLEAN ADC SIGNAL BEFORE DOWNSAMPLING"""
inds = np.empty(sparseSamples.shape)
for sparseInd, sparseSample in enumerate(sparseSamples):
inds[sparseInd] = np.argmin(abs(denseSamples - sparseSample))
if debug:
f = pylab.figure()
ax = f.add_subplot(111)
ax.plot(denseSamples,denseSamples*0,'.b')
ax.plot(sparseSamples,sparseSamples*0+1,'.g')
ax.plot(denseSamples[inds.astype(int)], denseSamples[inds.astype(int)]*0,'.r')
ax.set_ylim((-100, 100))
return inds.astype(int), denseSamples[inds.astype(int)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment