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
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
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
def test_fmconst(self): """Test constant frequency modulation.""" n_points, fnorm, center = 129, 0.5, 64 signal, iflaw = fm.fmconst(n_points, fnorm, center) real = np.real(signal) np.testing.assert_allclose(iflaw.ravel(), fnorm * np.ones((n_points,))) omega = np.arccos(real)[1:] / (2 * np.pi) / np.arange(n_points)[1:] self.assertEqual(omega.max(), fnorm) self.assert_is_analytic(signal)
def test_fmodany(self): """Test arbitrary modulation.""" iflaw = np.pad(np.ones((32,)), pad_width=(48, 48), mode='constant', constant_values=0) signal = fm.fmodany(iflaw / 2.0) self.assert_is_analytic(signal) np.testing.assert_allclose(np.real(signal)[:48], np.ones((48,))) np.testing.assert_allclose(np.real(signal)[-48:], np.ones((48,))) x = fm.fmconst(32, 0.5, 1)[0] np.testing.assert_allclose(np.real(x), np.real(signal)[48:48 + 32])