Created
September 13, 2012 17:30
-
-
Save huned/3716029 to your computer and use it in GitHub Desktop.
A naive downsampling implementation because I simply have too much 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
| # A naive downsample implementation. | |
| # | |
| # arguments: | |
| # | |
| # * `data`: the array of data you want to sample | |
| # * `sampleLength`: the number of samples you want | |
| # | |
| # returns a two element array, where the 1st | |
| # element, k, is the sampling period (ie, sample | |
| # every kth element) and the 2nd element is an | |
| # array of all samples. | |
| # | |
| downsample: (data, sampleLength) -> | |
| # compute k, where we want every kth value in the data array | |
| k = Math.floor(data.length / sampleLength) | |
| # just return the values if we want all of them | |
| return [1, data] if k <= 1 | |
| # return an array with every nth value | |
| [k, _.filter(data, (v, i) -> i % k == 0)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment