Repository navigation
Keep missing values missing in resample_sig - #615
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks for following up on this so quickly!
One issue when downsampling: the check only looks at the input samples on either side of each output position, so a gap that falls between two output samples disappears. For example, at 1000 Hz → 100 Hz, a single NaN at sample 500 gives one NaN output, but an 8-sample gap at 501–508 gives none.
Marking an output sample if any NaN lies within half an output spacing of it (and at least one input sample, so upsampling is unchanged) fixes this:
half = max(fs / fs_target / 2, 1)
n_nan = np.concatenate([[0], np.cumsum(nan_mask.reshape((-1,)))])
lo = np.clip(np.floor(resampled_t - half).astype(int) + 1, 0, len(t))
hi = np.clip(np.ceil(resampled_t + half).astype(int), 0, len(t))
resampled_x[n_nan[hi] - n_nan[lo] > 0] = np.nanWith this, your tests still pass and upsampling marks the same samples, while the 8-sample gap gives 2 NaN outputs. Could you add a downsampling test for that case too?
37d3d9d to
3aa9e27
Compare
|
Thanks, good catch! I've switched to your version, and added a downsampling test at 1000 Hz → 100 Hz: a NaN at sample 500 gives output 50, and the gap at 501–508 gives outputs 50 and 51. The gap case fails with the previous version. I also rebased onto |
3aa9e27 to
357400f
Compare
NaN values are filled before resampling, but the filled values were returned as if they were real data. Output samples at or next to a NaN input sample are now NaN.
Only the input samples on either side of each output position were checked, so a gap between two output samples was lost when downsampling. Mark an output sample if a NaN lies within half an output spacing of it (and at least one input sample).
357400f to
79ceedf
Compare
|
btw, sorry for incresing your load on halloween today, @tompollard 🤣 |
No problem at all, I've enjoyed working on this. Thanks for all the fixes! |
|
will work on some more things, tomorrow my time |
|
Thanks @TheNetherWatcher, I appreciate it. |
|
Also, side note, love the design here: https://www.bharatkaurav.com/ |
|
i really like cyberpunk themes, so i love the game cyberpunk 2077, blade runner 2049 and so on stuff |
|
same! i'm midway through the game, and the original bladerunner movie is one of my favorites. |
|
nice! the original is a classic, 2049 did a great job living up to it. how are you finding johnny silverhand so far? |
Follow-up to @tompollard's note on #604.
resample_sigfills NaN values before resampling, because the FFT would otherwise spread them over the whole signal. But the filled values were then returned as if they were real data, so the output had no trace of where the input was missing.Now output samples near a NaN input sample are set back to NaN. An output sample at position
t(in input samples) is NaN if any input sample within half an output spacing oftis NaN (and within at least one input sample, so neighbours count when upsampling). The filling and resampling are unchanged, so samples away from the gaps keep the same values.For example, record 100 at 360 Hz with its first 50 samples set to NaN, resampled to 250 Hz, gives NaN for the first 35 output samples (positions below 50) and finite values after. Signals without NaN give the same output as before.
This changes the output for signals with NaN, which is why it's a separate PR. The two tests from #604 now expect NaN at the filled positions.
Tests: new tests check which output samples are NaN when upsampling, and when downsampling with a single NaN and with a gap between two output samples; they fail without the change.
pytest -m "not network"passes (109 tests), and the docs build passes.