tl;dr I'm looking for something like Scipy's decimate
function, but one that takes in a generator, rather than a Numpy array.
I am turning on and off a light using a pseudo-random sequence of 0s and 1s, something like:
instructions = [0, 1, 1, 0, 1, 0, 1, 1, 1…]
Each 0 or 1 corresponds to ideally 50 milliseconds. The instruction reaching the light is subject to jitter (as much as +- 5ms). However, I have a sensor running at 20 kHz which records when the light receives the next instruction. I assume that the light turns on pretty instantaneously when it receives the instruction.
What I have recorded and saved to disk is a sequence like:
instructions_arrive = [0, 998, 1950, 2999, 3080, 4000, 4900, ...]
Which is the light change event as sampled by the 20 kHz sensor.
I now want to downsample this 20 kHz signal to about 1 kHz. I am aware that I can use something like Scipy's decimate
; however, this would require me to decompress the signal to a Numpy array where each element is one of the samples at 20 kHz. Instead, I would like to pass something like a generator, where I calculate the sample values by looking at the instructions_arrive
array. This will save me a lot of memory.
My backup option is to use Numpy's memmap
feature.
SciPy
. $\endgroup$