예제 #1
0
    def test_amgauss(self):
        """Test if the gaussian amplitude modulator works correctly."""
        time_center = 63
        n_points = 128
        spread = 10
        signal = am.amgauss(n_points, time_center, spread)
        # parameters of the underlying gaussian function of the form
        # f(x) = a * exp( (-(x - b) **2) / (2 * (c ** 2)))
        a, b, c = 1, time_center, spread / np.sqrt(2 * pi)
        # Integral of a Gaussian is a * c * sqrt( 2 * pi)
        integral = a * c * np.sqrt(2 * pi)
        self.assertAlmostEqual(integral, signal.sum())

        # Other miscellaneous properties of a Gaussian
        maximum = argrelmax(signal)
        self.assertEqual(len(maximum), 1)
        self.assertEqual(maximum[0][0], time_center - 1)
        self.assertAlmostEqual(signal[time_center - 1], 1.0)

        self.assert_is_monotonic_increasing(signal[:(time_center - 1)])
        self.assert_is_monotonic_decreasing(signal[(time_center - 1):])

        infpl1 = np.floor(b - c).astype(int) - 1
        infpl2 = np.floor(b + c).astype(int)
        self.assert_is_convex(signal[:infpl1])
        self.assert_is_concave(signal[infpl1:infpl2])
        self.assert_is_convex(signal[infpl2:])
예제 #2
0
 def test_group_delay(self):
     """Test Group delay calculation."""
     n_points = 128
     signal = am.amgauss(n_points, 64, 30) * fm.fmlin(n_points, 0.1, 0.4)[0]
     fnorm = np.arange(0.1, 0.38, step=0.04)
     grp_dlay = fproc.group_delay(signal, fnorm)
     self.assert_is_linear(grp_dlay, 0)
예제 #3
0
    def test_amgauss(self):
        """Test if the gaussian amplitude modulator works correctly."""
        time_center = 63
        n_points = 128
        spread = 10
        signal = am.amgauss(n_points, time_center, spread)
        # parameters of the underlying gaussian function of the form
        # f(x) = a * exp( (-(x - b) **2) / (2 * (c ** 2)))
        a, b, c = 1, time_center, spread / np.sqrt(2 * pi)
        # Integral of a Gaussian is a * c * sqrt( 2 * pi)
        integral = a * c * np.sqrt(2 * pi)
        self.assertAlmostEqual(integral, signal.sum())

        # Other miscellaneous properties of a Gaussian
        maximum = argrelmax(signal)
        self.assertEqual(len(maximum), 1)
        self.assertEqual(maximum[0][0], time_center - 1)
        self.assertAlmostEqual(signal[time_center - 1], 1.0)

        self.assert_is_monotonic_increasing(signal[:(time_center - 1)])
        self.assert_is_monotonic_decreasing(signal[(time_center - 1):])

        infpl1 = np.floor(b - c).astype(int) - 1
        infpl2 = np.floor(b + c).astype(int)
        self.assert_is_convex(signal[:infpl1])
        self.assert_is_concave(signal[infpl1:infpl2])
        self.assert_is_convex(signal[infpl2:])
예제 #4
0
파일: misc.py 프로젝트: souravsingh/pytftb
def atoms(n_points, coordinates):
    """Compute linear combination of elementary Gaussian atoms.

    :param n_points: Number of points in a signal
    :param coordinates: matrix of time-frequency centers
    :type n_points: int
    :type coordinates: array-like
    :return: signal
    :rtype: array-like
    :Examples:
    >>> coordinates = np.array([[32.0, 0.3, 32.0, 1.0],
                                [0.15, 0.15, 48.0, 1.22]])
    >>> sig = atoms(128, coordinates)
    >>> plot(real(sig))

    .. plot:: docstring_plots/generators/misc/atoms.py
    """
    if coordinates.ndim == 1:
        coordinates = coordinates.reshape((coordinates.shape[0], 1))
    signal = np.zeros((n_points,), dtype=complex)
    n_atoms = coordinates.shape[0]
    for k in range(n_atoms):
        t0 = np.round(np.max((np.min((coordinates[k, 0], n_points)), 1)))
        f0 = np.max((np.min((coordinates[k, 1], 0.5)), 0.0))
        T = coordinates[k, 2]
        A = coordinates[k, 3]
        signal += A * amgauss(n_points, t0, T) * fmconst(n_points, f0, t0)[0]
    return signal
예제 #5
0
파일: misc.py 프로젝트: jaidevd/pytftb
def atoms(n_points, coordinates):
    """Compute linear combination of elementary Gaussian atoms.

    :param n_points: Number of points in a signal
    :param coordinates: matrix of time-frequency centers
    :type n_points: int
    :type coordinates: array-like
    :return: signal
    :rtype: array-like
    :Examples:
    >>> import numpy as np
    >>> coordinates = np.array([[32.0, 0.3, 32.0, 1.0], [0.15, 0.15, 48.0, 1.22]])
    >>> sig = atoms(128, coordinates)
    >>> plot(real(sig)) #doctest: +SKIP

    .. plot:: docstring_plots/generators/misc/atoms.py
    """
    if coordinates.ndim == 1:
        coordinates = coordinates.reshape((coordinates.shape[0], 1))
    signal = np.zeros((n_points, ), dtype=complex)
    n_atoms = coordinates.shape[0]
    for k in range(n_atoms):
        t0 = round(np.max((np.min((coordinates[k, 0], n_points)), 1)))
        f0 = np.max((np.min((coordinates[k, 1], 0.5)), 0.0))
        T = coordinates[k, 2]
        A = coordinates[k, 3]
        signal += A * amgauss(n_points, t0, T) * fmconst(n_points, f0, t0)[0]
    return signal
예제 #6
0
def atoms(n_points, coordinates):
    """Compute linear combination of elementary Gaussian atoms.

    :param n_points: Number of points in a signal
    :param coordinates: matrix of time-frequency centers
    :type n_points: int
    :type coordinates: array-like
    :return: signal
    :rtype: array-like
    :Examples:
    >>> coordinates = np.array([[32.0, 0.3, 32.0, 1.0],
                                [0.15, 0.15, 48.0, 1.22]])
    >>> sig = atoms(128, coordinates)
    >>> plot(real(sig))

    .. plot:: docstring_plots/generators/misc/atoms.py
    """
    # FIXME: This function produces incorrect output when coordinates are
    # one-dimensional.
    signal = np.zeros((n_points,), dtype=complex)
    n_atoms = coordinates.shape[0]
    for k in xrange(n_atoms):
        t0 = np.round(np.max((np.min((coordinates[k, 0], n_points)), 1)))
        f0 = np.max((np.min((coordinates[k, 1], 0.5)), 0.0))
        T = coordinates[k, 2]
        A = coordinates[k, 3]
        signal += A * amgauss(n_points, t0, T) * fmconst(n_points, f0, t0)[0]
    return signal
예제 #7
0
 def test_group_delay(self):
     """Test Group delay calculation."""
     n_points = 128
     signal = am.amgauss(n_points, 64, 30) * fm.fmlin(n_points, 0.1, 0.4)[0]
     fnorm = np.arange(0.1, 0.38, step=0.04)
     grp_dlay = fproc.group_delay(signal, fnorm)
     self.assert_is_linear(grp_dlay, 0)
예제 #8
0
 def test_loctime(self):
     signal = am.amgauss(160, 80, 50)
     tm, T = tmd.loctime(signal)
     self.assertAlmostEqual(tm, 79, places=6)
     self.assertAlmostEqual(T, 50, places=4)
예제 #9
0
 def test_loctime(self):
     """Test computation of localized time characteristics."""
     signal = am.amgauss(160, 80, 50)
     tm, T = tmd.loctime(signal)
     self.assertAlmostEqual(tm, 79, places=6)
     self.assertAlmostEqual(T, 50, places=4)
예제 #10
0
 def test_loctime(self):
     """Test computation of localized time characteristics."""
     signal = am.amgauss(160, 80, 50)
     tm, T = tmd.loctime(signal)
     self.assertAlmostEqual(tm, 79, places=6)
     self.assertAlmostEqual(T, 50, places=4)