def test_fftfilt_nd(): np.random.seed(123) x = np.random.randn(2**16) + 1j * np.random.randn(2**16) b = np.random.randn(128) oned = fftfilt.fftfilt(b, x) nd = fftfilt.fftfilt_nd(b, x[:, None]).squeeze() assert np.allclose(oned, nd) x = x.reshape((2**12, 2**4)) oned = np.zeros_like(x) for k in range(16): oned[:, k] = fftfilt.fftfilt(b, x[:, k]) nd = fftfilt.fftfilt_nd(b, x) assert np.allclose(oned, nd)
def test_fftfilt_nd(): np.random.seed(123) x = np.random.randn(2 ** 16) + 1j * np.random.randn(2 ** 16) b = np.random.randn(128) oned = fftfilt.fftfilt(b, x) nd = fftfilt.fftfilt_nd(b, x[:, None]).squeeze() assert np.allclose(oned, nd) x = x.reshape((2 ** 12, 2 ** 4)) oned = np.zeros_like(x) for k in range(16): oned[:, k] = fftfilt.fftfilt(b, x[:, k]) nd = fftfilt.fftfilt_nd(b, x) assert np.allclose(oned, nd)
def test_decimating_fir(): np.random.seed(123) x = np.random.randn(2**16) + 1j * np.random.randn(2**16) dfir = decimating_fir.DecimatingFIR(downsample_factor=16, num_taps=1024) gold = fftfilt.fftfilt(dfir.coefficients.ravel(), x)[15::16] result = dfir.process(x) assert np.allclose(gold, result)
def test_decimating_fir(): np.random.seed(123) x = np.random.randn(2**16) + 1j*np.random.randn(2**16) dfir = decimating_fir.DecimatingFIR(downsample_factor=16,num_taps=1024) gold = fftfilt.fftfilt(dfir.coefficients.ravel(),x)[15::16] result = dfir.process(x) assert np.allclose(gold,result)
def mean(self): if self._mean is None: if self._lpf_data is None: self._lpf_data = fftfilt.fftfilt( lpf, self.data)[len(lpf):] * self.wavenorm self._mean = self._lpf_data.mean(0, dtype='complex') return self._mean
def low_pass_fir(data, num_taps=256, cutoff=1 / 256., nyquist_freq=1.0, decimate_by=1): taps = scipy.signal.firwin(num_taps, cutoff / nyquist_freq) result = fftfilt(taps, data)[num_taps:] result = result[::decimate_by].copy( ) # add .copy to ensure we separate this from the full sized original data return result
def mean_error(self): if self._std is None: if self._lpf_data is None: self._lpf_data = fftfilt.fftfilt(lpf,self.data)[len(lpf):]*self.wavenorm # the standard deviation is scaled by the number of independent samples # to compute the error on the mean. real_error = self._lpf_data.real.std(0)/np.sqrt(self._lpf_data.shape[0]/len(lpf)) imag_error = self._lpf_data.imag.std(0)/np.sqrt(self._lpf_data.shape[0]/len(lpf)) self._std = real_error + 1j*imag_error return self._std
def deglitch_block(ts,thresh=5): tsl = np.roll(np.abs(fftfilt(scipy.signal.firwin(16,1/16.),ts)),-8) mask = medmadmask(tsl,thresh=thresh) mask[:-50] = mask[:-50] | mask[50:] mask[50:] = mask[50:] | mask[:-50] nmask = mask.sum() # print "rejecting",nmask/float(ts.shape[0]) out = ts.copy() try: out[mask] = np.array(random.sample(ts[~mask],nmask)) except ValueError: print "more masked values than samples to draw from!" return out
def mean_error(self): if self._std is None: if self._lpf_data is None: self._lpf_data = fftfilt.fftfilt( lpf, self.data)[len(lpf):] * self.wavenorm # the standard deviation is scaled by the number of independent samples # to compute the error on the mean. real_error = self._lpf_data.real.std(0) / np.sqrt( self._lpf_data.shape[0] / len(lpf)) imag_error = self._lpf_data.imag.std(0) / np.sqrt( self._lpf_data.shape[0] / len(lpf)) self._std = real_error + 1j * imag_error return self._std
def deglitch_block(ts, thresh=5): tsl = np.roll(np.abs(fftfilt(scipy.signal.firwin(16, 1 / 16.), ts)), -8) mask = medmadmask(tsl, thresh=thresh) mask[:-50] = mask[:-50] | mask[50:] mask[50:] = mask[50:] | mask[:-50] nmask = mask.sum() # print "rejecting",nmask/float(ts.shape[0]) out = ts.copy() try: out[mask] = np.array(random.sample(ts[~mask], nmask)) except ValueError: print "more masked values than samples to draw from!" return out
def low_pass_fir(data, num_taps=256, cutoff=1/256.,nyquist_freq=1.0,decimate_by=1): taps = scipy.signal.firwin(num_taps,cutoff/nyquist_freq) result = fftfilt(taps,data)[num_taps:] result = result[::decimate_by].copy() # add .copy to ensure we separate this from the full sized original data return result
def lpf256(ts): return fftfilt(scipy.signal.firwin(256,1/256.),ts)
def lpf256(ts): return fftfilt(scipy.signal.firwin(256, 1 / 256.), ts)
def mean(self): if self._mean is None: if self._lpf_data is None: self._lpf_data = fftfilt.fftfilt(lpf,self.data)[len(lpf):]*self.wavenorm self._mean = self._lpf_data.mean(0,dtype='complex') return self._mean