Ejemplo n.º 1
0
def rrcos_resample(signal, fold, fnew, Ts=None, beta=None, taps=4001, renormalise=False, fftconv=True):
    """
    Resample a signal using a root raised cosine filter. This performs pulse shaping and resampling a the same time.
    The resampling is done by scipy.signal.resample_poly. This function can be quite slow.

    Parameters
    ----------
    signal   : array_like
        input time domain signal
    fold     : float
        sampling frequency of the input signal
    fnew     : float
        desired sampling frequency
    Ts       : float, optional
        time width of the RRCOS filter (default:None makes this 1/fold)
    beta     : float, optional
        filter roll off factor between (0,1] (default:None will use the default filter in poly_resample)
    taps : int, optional
        taps of the interpolation filter if taps is None we filter by zeroinsertion upsampling and multipling
        with the full length rrcos frequency response in the spectral domain
    fftconv : bool, optional
        filter using zero insertion upsampling/decimation and filtering using fftconvolve. I often faster for
        long filters and power of two signal lengths.

    Returns
    -------
    sig_out  : array_like
        resampled output signal

    """
    if beta is None:
        return resample_poly(signal, fold, fnew)
    assert 0 < beta <= 1, "beta needs to be in interval (0,1]"
    if Ts is None:
        Ts = 1/fold
    up, down = _resamplingfactors(fold, fnew)
    fup = up*fold
    # for very large tap lengths it is better to filter with fftconvolve
    # it could be better to use default values here, but this seems to depend on pc
    if fftconv or taps is None:
        sig_new = np.zeros((up*signal.size,), dtype=signal.dtype)
        sig_new[::up] = signal
        sig_new = rrcos_pulseshaping(sig_new, fup, Ts, beta, taps)
        sig_new = sig_new[::down]
    else:
        t = np.linspace(0, taps, taps, endpoint=False)
        t -= t[(t.size-1)//2]
        t /= fup
        nqf = rrcos_time(t, beta, Ts)
        nqf /= nqf.max()
        sig_new = scisig.resample_poly(signal, up, down, window=nqf)
    if renormalise:
        p = np.mean(abs(signal)**2)
        sig_new = normalise_and_center(sig_new)*np.sqrt(p)
    return sig_new
Ejemplo n.º 2
0
 def test_rrcos_pulseshaping(self):
     x = np.random.randn(2**15) + 0.j
     y = cfilter.rrcos_pulseshaping(x, 2, 1, 0.2)
     assert x.shape == y.shape
Ejemplo n.º 3
0
 def test_rrcos_pulseshaping_attr(self, attr):
     s2 = cfilter.rrcos_pulseshaping(self.s, self.s.fs, 1 / self.s.fb, 0.1)
     assert getattr(self.s, attr) is getattr(s2, attr)
Ejemplo n.º 4
0
 def test_rrcos_pulseshaping(self):
     s2 = cfilter.rrcos_pulseshaping(self.s, self.s.fs, 1 / self.s.fb, 0.1)
     assert type(self.s) is type(s2)
Ejemplo n.º 5
0
 def test_rrcos_pulseshaping(self, dtype):
     s = self.s.astype(dtype)
     s2 = cfilter.rrcos_pulseshaping(s, s.fs, 1 / s.fb, 0.1)
     assert s2.dtype is np.dtype(dtype)