diff --git a/syncsweptsine.py b/syncsweptsine.py index 6728ba0..5ec2aa8 100644 --- a/syncsweptsine.py +++ b/syncsweptsine.py @@ -649,7 +649,7 @@ def _calculate_inverted_sweep_spectrum(self): sweepperiod = self._sweepperiod startfreq = self._startfreq freq = _np.linspace(0, samplerate/2, int(_np.round(self.fftlen/2+1))) - spectrum = _np.zeros_like(freq, dtype=_np.complex) + spectrum = _np.zeros_like(freq, dtype=_np.complex_) # eq. 43 definition of the inverse spectrum in frequency domain spectrum[1:] = ( 2*_np.sqrt(freq[1:]/sweepperiod) @@ -783,7 +783,7 @@ def hir_index(self, order, length, delay=0): Delay of system under test the hhir was derived from. """ - return _np.arange(length)+delay+self.hir_sample_position(order) + return _np.arange(length, dtype=int)+int(delay)+self.hir_sample_position(order) def max_hir_length(self, order): """Returns the maximum length of mpulse responses for given orders. @@ -856,7 +856,7 @@ def from_sweeps(cls, syncsweep, measuredsweep, fftlen=None, regularize=1e-6): Length of the calculated ffts. fftlen will be guessed from measuredsweep length if fftlen is None. """ - fftlen = fftlen or _np.int(2**_np.ceil(1+_np.log2(len(measuredsweep)))) + fftlen = fftlen or int(2**_np.ceil(1+_np.log2(len(measuredsweep)))) rspec = _np.fft.rfft(measuredsweep, fftlen) rinvspec = InvertedSyncSweepSpectrum.from_sweep(syncsweep, fftlen=fftlen).spectrum freq = _np.fft.rfftfreq(fftlen, 1/syncsweep.samplerate) diff --git a/test_syncsweptsine.py b/test_syncsweptsine.py index e160b9a..b2c8e2f 100644 --- a/test_syncsweptsine.py +++ b/test_syncsweptsine.py @@ -181,11 +181,11 @@ def test_higher_harmonic_impulse_response(): sweep = SyncSweep(10, 10000, 5, 20000) hhir = HigherHarmonicImpulseResponse.from_sweeps(sweep, sweep) assume(np.all(np.array(hhir) == hhir.hhir)) - hir = hhir.harmonic_impulse_response(order=1, length=1024, delay=0, window=True) + hir = hhir.harmonic_impulse_response(order=1, length=1024, delay=-512, window=True) assume(type(hir) == np.ndarray) assume(len(hir) == 1024) assume(np.argmax(hir)==512) - hir = hhir.harmonic_impulse_response(order=1, length=1024, delay=0, window=np.linspace(0, 1, 1024)) + hir = hhir.harmonic_impulse_response(order=1, length=1024, delay=-512, window=np.linspace(0, 1, 1024)) assume(type(hir) == np.ndarray) assume(len(hir) == 1024) assume(np.argmax(hir)==512) @@ -238,18 +238,19 @@ def nonlinear_system(sig): outsweep = nonlinear_system(np.array(sweep)) hhir = HigherHarmonicImpulseResponse.from_sweeps(sweep, outsweep, regularize=False) hm = HammersteinModel.from_higher_harmonic_impulse_response( - hhir, 2048, orders=(1, 2, 3), delay=0) + hhir, 2048, orders=(1, 2, 3), delay=-1024) # -delay since irs are acausal in this case. assume(hm.orders==(1, 2, 3)) x = np.array([1]+127*[0]) hm.filter(x) assume(hm.__repr__().startswith('HammersteinModel(')) expectedcoeffs = [1.0, 0.25, 0.125] for kernel, expc in zip(hm.kernels, expectedcoeffs): + print(abs(np.median(abs(kernel.frf[100:200]))), expc) assume(abs(np.median(abs(kernel.frf[100:200]))-expc) < 0.01) with pytest.raises(ValueError): hm = HammersteinModel.from_higher_harmonic_impulse_response( - hhir, 96e4, orders=(1, 2, 3), delay=0) + hhir, hhir.max_hir_length(1)+1, orders=(1, 2, 3), delay=-1024) lm = LinearModel.from_hammerstein_model(hm) @@ -266,7 +267,7 @@ def nonlinear_system(sig): y = lm.filter(x) with pytest.raises(ValueError): hm = LinearModel.from_higher_harmonic_impulse_response( - hhir, 96e4, delay=0) + hhir, hhir.max_hir_length(1)+1, delay=0) if __name__ == "__main__":