def test_centrfreq(): # db1 is Haar function, frequency=1 w = pywt.Wavelet('db1') expected = 1 result = pywt.centfrq(w, precision=12) assert_almost_equal(result, expected, decimal=3) # db2, frequency=2/3 w = pywt.Wavelet('db2') expected = 2/3. result = pywt.centfrq(w, precision=12) assert_almost_equal(result, expected)
def get_tf_info(self, Fs): """ returns energy centroids and spread in the time frequency plane """ # This is some pretty ugly hack and is only intended to allow basic # plotting features C = np.cumsum(self.waveform**2) center = np.min(np.nonzero(C>np.max(C)/2)) start = np.min(np.nonzero(C>0.00001*np.max(C))) end = np.min(np.nonzero(C>(0.99999*np.max(C)))) scale = 2**(np.round(np.log2(end-start))) L = scale K = L / 4 freq = centfrq(self.nature, precision=self.level) f = float(freq) * float(Fs) / float(L) bw = (float(Fs) / scale) # / 2 p = center / float(Fs) l = float(L + K) / float(Fs) return f, bw, p, l