diff --git a/madarrays/tests/test_waveform.py b/madarrays/tests/test_waveform.py index fb3d7ab0279554abc7ee28d2b07a7818aa5a95a5..4c24ab6c847ec10dbb439ec0ae16d916dc617211 100644 --- a/madarrays/tests/test_waveform.py +++ b/madarrays/tests/test_waveform.py @@ -243,34 +243,32 @@ class TestWaveform: w.resample(fs=fs) assert w.fs == fs - assert w.length == int(np.floor(fs * self.length / self.fs)) + assert w.length == int(np.floor(fs / self.fs * self.length)) assert not w.is_stereo() print(self.length, self.fs) assert w.duration == pytest.approx(self.length / self.fs, 1e-4) np.testing.assert_equal( w.time_axis, - np.arange(np.floor(fs * self.length / self.fs)) / fs) + np.arange(np.floor(fs / self.fs * self.length)) / fs) # Stereo w = Waveform(self.x_stereo, fs=self.fs) w.resample(fs=fs) assert w.fs == fs - assert w.length == int(np.floor(fs * self.length / self.fs)) + assert w.length == int(np.floor(fs / self.fs * self.length)) assert w.is_stereo() assert w.duration == pytest.approx(self.length / self.fs, 1e-4) np.testing.assert_equal( w.time_axis, - np.arange(np.floor(fs * self.length / self.fs)) / fs) + np.arange(np.floor(fs / self.fs * self.length)) / fs) # Floating values with ratios that are exact rationals for (old_fs, new_fs) in [(1, 1.5), (0.5, 3), (100.1, 200.2)]: - print('Testing resampling {}/{}, signal length = {}' - .format(new_fs, old_fs, w.shape[0])) w = Waveform(self.x_mono, fs=old_fs) w.resample(fs=new_fs) assert w.fs == new_fs - assert w.length == int(new_fs * self.length / old_fs) + assert w.length == int(new_fs / old_fs * self.length) # Floating values with ratios that are not well approximated # by rationals diff --git a/madarrays/waveform.py b/madarrays/waveform.py index 0c20cbc4cf203b9ed94d91ece82855990fabc788..6f839b59a3b6a43950b465c4fac808415579dc19 100644 --- a/madarrays/waveform.py +++ b/madarrays/waveform.py @@ -310,15 +310,15 @@ class Waveform(MadArray): UserWarning """ - assert np.issubdtype(type(fs), np.integer) or np.issubdtype(type(fs), - np.float) + assert np.issubdtype(type(fs), np.integer) \ + or np.issubdtype(type(fs), np.floating) if fs <= 0: errmsg = '`fs` should be a positive number (given: {})' raise ValueError(errmsg.format(fs)) - if np.issubdtype(type(fs), np.float) or np.issubdtype(type(self.fs), - np.float): + if np.issubdtype(type(fs), np.floating) \ + or np.issubdtype(type(self.fs), np.floating): # Find a good rational number to approximate the ratio between # sampling frequencies fs_ratio = Fraction(fs/self.fs)