示例#1
0
def apply_DAC_filter(sig, fs, cutoff=18e9, fn=None, ch=1):
    """
    Apply the frequency response filter of the DAC. This function
    uses either a 2nd order Bessel filter or a measured frequency response
    loaded from a file.

    Parameters
    ----------
    sig : array_like
        signal to be filtered. Can be real or complex
    fs : float
        sampling rate of the signal
    cutoff : float, optional
        Cutoff frequency used by only by Bessel filter
    fn : string, optional
        filename of a experimentally measured response, if None use a Bessel
        filter approximation
    ch : int, optional
        channel number of the measured response to use
    Returns
    -------
    filter_sig : array_like
        filtered signal
    """
    # filtering was split into real and imaginary before but that should not be necessary
    if fn is None:
        filter_sig = filter_signal(sig, fs, cutoff, ftype="bessel", order=2)
    else:
        H_dac = load_dac_response(fn, fs, sig.shape[-1], ch=ch).astype(sig) # should check if response is real
        sigf = fft.fft(sig)
        filter_sig = fft.ifft(sigf * H_dac)
    return filter_sig
示例#2
0
 def test_filter_signal_1d(self):
     x = np.random.randn(2**15) + 0.j
     y = cfilter.filter_signal(x, 2, 0.01)
     assert x.shape == y.shape
示例#3
0
 def test_filter_signal(self):
     s2 = cfilter.filter_signal(self.s, self.s.fs, 0.001)
     assert type(self.s) is type(s2)
示例#4
0
 def test_filter_signal_attr(self, attr):
     s2 = cfilter.filter_signal(self.s, self.s.fs, 0.01)
     assert getattr(self.s, attr) is getattr(s2, attr)
示例#5
0
 def test_filter_signal(self, ndim):
     x = np.random.randn(ndim, 2**15) + 0.j
     y = cfilter.filter_signal(x, 2, 0.01)
     assert x.shape == y.shape
示例#6
0
 def test_filter_signal_analog(self, dtype):
     s = self.s.astype(dtype)
     s2 = cfilter.filter_signal(s, s.fs, 0.001, analog=True)
     assert s2.dtype is np.dtype(dtype)
示例#7
0
 def test_filter_signal(self, dtype):
     s = self.s.astype(dtype)
     s2 = cfilter.filter_signal(s, s.fs, 0.001)
     assert s2.dtype == np.dtype(dtype)
示例#8
0
 def test_filter_signal_1d(self, ftype, analog):
     x = np.random.randn(2**15) + 0.j
     y = cfilter.filter_signal(x, 2, 0.01, ftype=ftype, analog=analog)
     assert x.shape == y.shape
示例#9
0
 def test_filter_signal_type(self, ndim, ftype, analog, dtype):
     x = np.random.randn(ndim, 2**15) + 0.j
     x = x.astype(dtype)
     y = cfilter.filter_signal(x, 2, 0.01, ftype=ftype, analog=analog)
     assert x.shape == y.shape
     assert x.dtype == y.dtype
示例#10
0
 def test_filter_signal_analog_attr(self, attr):
     s = self.s
     s2 = cfilter.filter_signal(s, s.fs, 0.01, analog=True)
     assert getattr(s, attr) is getattr(s2, attr)