Created
June 28, 2012 00:05
-
-
Save ptweir/3007746 to your computer and use it in GitHub Desktop.
Find closest dense samples to sparsely sampled data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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