def ktoi(data,axis=-1): if (axis == -1): ax = fth.arange(0,data.ndim) else: ax = axis return fth.fftshift(ft.ifftn(fth.ifftshift(data,axes=ax),axes=ax),axes=ax)
def ktoi(data, axis=-1): if (axis == -1): ax = fth.arange(0, data.ndim) else: ax = axis return fth.fftshift(ft.ifftn(fth.ifftshift(data, axes=ax), axes=ax), axes=ax)
def test_util_filterResponse(self): sr = self.stream[0].stats.sampling_rate # test filterResponse vs filter2 st = self.stream.copy() data = st[0].data.copy() N = len(data) nfft = nextpow2(len(data)) values = util.main.filterResp(1, 5, corners=2, sr=20, N=nfft, whole=True)[1] st.filter2(1, 5, corners=2) data2 = ifft(fft(data, nfft) * values, nfft) np.testing.assert_array_almost_equal(st[0].data, data2[:N]) # test stream interface st = self.stream.copy() st.fft() st.filter2(1, 5, corners=2) st.ifft() np.testing.assert_array_almost_equal(st[0].data, data2[:N]) # filtering with filterResponse and zerophase=Trueproduces a peak at # the end of data. With nfft=N there is no peak anymore, but still the values are not the same st = self.stream.copy() freqs, values = util.main.filterResp(1, 5, sr=20, N=nfft, corners=2, whole=True, zerophase=True) st.filter2(1, 5, corners=2, zerophase=True) data2 = ifft(fft(data, nfft) * values, nfft) np.testing.assert_array_almost_equal(st[0].data[:-10 * sr], data2[:N - 10 * sr]) return from numpy.fft.helper import ifftshift, fftfreq import matplotlib.pyplot as plt real_freqs = (ifftshift(freqs) - np.pi) * 0.5 * sr / np.pi freqs2 = fftfreq(nfft, 1 / 20.) print real_freqs print freqs2 plt.subplot(411) plt.plot(real_freqs, np.abs(values)) ax = plt.subplot(412) plt.plot(data, label='data') plt.legend() plt.subplot(413, sharex=ax) plt.plot(st[0].data, alpha=0.5, label='stream.filter2') plt.plot(data2[:N], alpha=0.5, label='filterResponse') plt.legend() plt.show()