TimeViewers / signalworks

MIT License
3 stars 2 forks source link

Wave.resample changes the dtype! #31

Open j9ac9k opened 4 years ago

j9ac9k commented 4 years ago

Description

When calling tracking.wave.resample(some_freq), I get a new track back, but the dtype of the new_track was floating point (when the original track dtype was int16). This of course causes all sorts of havok with wave.min and wave.max, and thus plotting

Here is the code for resampling:

https://github.com/TimeViewers/signalworks/blob/master/signalworks/tracking/wave.py#L189-L202

In the end, it calls the Wave constructor, with the new values from resample_poly.

The thing to do here would be to convert the returned values into the dtype of the original array, something along the lines of

return type(self)(resample_poly(self._value, 1, int(self._fs / fs).astype(self._value.dtype), fs)
lxkain commented 4 years ago

The assumption is that folks are ok with loosing the additional precision that would be necessary to capture the details of the resampling. I'm ok with making this assumption. Maybe we should have explicit bit-depth converters between 16 (int16), 32 (float32), and 64 (float64) bits.