def test_anapulse(self):
     """Test analytic unit impulse."""
     signal = ana.anapulse(512, 301)
     recons = np.zeros((512,))
     recons[301] = 1
     np.testing.assert_allclose(recons, np.real(signal), rtol=1e-5,
                                atol=1e-5)
Example #2
0
def gdpower(n_points, degree=0.0, rate=1.0):
    """Generate a signal with a power law group delay.

    :param n_points: Number of points in time.
    :param degree: degree of the power law.
    :param rate: rate-coefficient of the power law GD.
    :type n_points: int
    :type degree: int		# yoder: i'm pretty sure this is supposed to be a float. at least in test_misc.py, the test for this funct. passes degree=0.5
    :type rate: float
    :return: Tuple of time row containing modulated samples, group delay, \
            frequency bins.
    :rtype: tuple
    """
    n_points = int(n_points)
    degree = float(degree)
    rate = float(rate)
    t0 = 0
    lnu = int(np.ceil(n_points / 2.0))
    nu = np.linspace(0, 0.5, lnu + 1)
    nu = nu[1:]
    am = nu ** ((degree - 2.0) / 6.0)

    if rate == 0.:
        raise TypeError("rate must be non-zero")

    tfx = np.zeros((n_points,), dtype=complex)

    if (degree < 1.) and (degree != 0):
        d = float(n_points) ** (degree * rate)
        t0 = n_points / 10.0
        tfx[:lnu] = np.exp(-1.0j * 2. * pi * (t0 * nu + d * nu ** degree / degree)) * am
        x = np.fft.ifft(tfx)
    elif degree == 0:
        d = rate
        t0 = n_points / 10.0
        tfx[:lnu] = np.exp(-1j * 2 * np.pi * (t0 * nu + d * np.log(nu))) * am
        x = np.fft.ifft(tfx)
    elif degree == 1.:
        from tftb.generators.analytic_signals import anapulse
        t0 = n_points
        x = anapulse(n_points, t0)
    elif degree > 1.:
        d = n_points * 2. ** (degree - 1.) * rate
        tfx[:lnu] = np.exp(-1.0j * 2.0 * pi * (t0 * nu + d * nu ** degree / degree)) * am
        x = np.fft.ifft(tfx)
    else:
        t0 = n_points / 10
        d = n_points * 2.0 ** (degree - 1.0) * rate
        tfx[:lnu] = np.exp(-1j * 2 * pi * (t0 * nu + d * np.log(nu))) * am
        x = np.fft.ifft(tfx)

    if degree != 1.0:
        gpd = t0 + np.abs(np.sign(rate) - 1.0) / 2.0 * (n_points + 1.0) + d * nu ** (degree - 1.0)
    else:
        gpd = t0 * np.ones((n_points / 2.0,))

    x = x - x.mean()
    x = x / np.linalg.norm(x)

    return x, gpd, nu
Example #3
0
def gdpower(n_points, degree=0.0, rate=1.0):
    """Generate a signal with a power law group delay.

    :param n_points: Number of points in time.
    :param degree: degree of the power law.
    :param rate: rate-coefficient of the power law GD.
    :type n_points: int
    :type degree: int		# yoder: i'm pretty sure this is supposed to be a float. at least in test_misc.py, the test for this funct. passes degree=0.5
    :type rate: float
    :return: Tuple of time row containing modulated samples, group delay, \
            frequency bins.
    :rtype: tuple
    """
    n_points = int(n_points)
    degree = float(degree)
    rate = float(rate)
    t0 = 0
    lnu = int(np.ceil(n_points / 2))
    nu = np.linspace(0, 0.5, lnu + 1)
    nu = nu[1:]
    am = nu ** ((degree - 2.0) / 6.0)

    if rate == 0.:
        raise TypeError("rate must be non-zero")

    tfx = np.zeros((n_points,), dtype=complex)

    if (degree < 1.) and (degree != 0):
        d = float(n_points) ** (degree * rate)
        t0 = n_points / 10.0
        tfx[:lnu] = np.exp(-1.0j * 2. * pi * (t0 * nu + d * nu ** degree / degree)) * am
        x = np.fft.ifft(tfx)
    elif degree == 0:
        d = rate
        t0 = n_points / 10.0
        tfx[:lnu] = np.exp(-1j * 2 * np.pi * (t0 * nu + d * np.log(nu))) * am
        x = np.fft.ifft(tfx)
    elif degree == 1.:
        from tftb.generators.analytic_signals import anapulse
        t0 = n_points
        x = anapulse(n_points, t0)
    elif degree > 1.:
        d = n_points * 2. ** (degree - 1.) * rate
        tfx[:lnu] = np.exp(-1.0j * 2.0 * pi * (t0 * nu + d * nu ** degree / degree)) * am
        x = np.fft.ifft(tfx)
    else:
        t0 = n_points / 10
        d = n_points * 2.0 ** (degree - 1.0) * rate
        tfx[:lnu] = np.exp(-1j * 2 * pi * (t0 * nu + d * np.log(nu))) * am
        x = np.fft.ifft(tfx)

    if degree != 1.0:
        gpd = t0 + np.abs(np.sign(rate) - 1.0) / 2.0 * (n_points + 1.0) + d * nu ** (degree - 1.0)
    else:
        gpd = t0 * np.ones((n_points / 2.0,))

    x = x - x.mean()
    x = x / np.linalg.norm(x)

    return x, gpd, nu
Example #4
0
 def test_anapulse(self):
     """Test analytic unit impulse."""
     signal = ana.anapulse(512, 301)
     recons = np.zeros((512, ))
     recons[301] = 1
     np.testing.assert_allclose(recons,
                                np.real(signal),
                                rtol=1e-5,
                                atol=1e-5)