Exemplo n.º 1
0
def anaask(n_points, n_comp=None, f0=0.25):
    """Generate an amplitude shift (ASK) keying signal.

    :param n_points: number of points.
    :param n_comp: number of points of each component.
    :param f0: normalized frequency.
    :type n_points: int
    :type n_comp: int
    :type f0: float
    :return: Tuple containing the modulated signal and the amplitude modulation.
    :rtype: tuple(numpy.ndarray)
    :Examples:
    >>> x, am = anaask(512, 64, 0.05)
    >>> subplot(211), plot(real(x))
    >>> subplot(212), plot(am)

    .. plot:: docstring_plots/generators/analytic_signals/anaask.py
    """
    if n_comp is None:
        n_comp = np.round(n_points / 2)
    if (f0 < 0) or (f0 > 0.5):
        raise TypeError("f0 must be between 0 and 0.5")
    m = np.ceil(n_points / n_comp)
    jumps = np.random.rand(m)
    am = np.kron(jumps, np.ones((n_comp,)))[:n_points]
    fm, iflaw = fmconst(n_points, f0, 1)
    y = am * fm
    return y, am
Exemplo n.º 2
0
def anabpsk(n_points, n_comp=None, f0=0.25):
    """Binary phase shift keying (BPSK) signal.

    :param n_points: number of points.
    :param n_comp: number of points in each component.
    :param f0: normalized frequency.
    :type n_points: int
    :type n_comp: int
    :type f0: float
    :return: BPSK signal
    :rtype: numpy.ndarray
    :Examples:
    >>> x, am = anabpsk(300, 30, 0.1)
    >>> subplot(211), plot(real(x))
    >>> subplot(212), plot(am)

    .. plot:: docstring_plots/generators/analytic_signals/anabpsk.py
    """
    if n_comp is None:
        n_comp = np.round(n_points / 5)
    if (f0 < 0) or (f0 > 0.5):
        raise TypeError("f0 must be between 0 and 0.5")
    m = np.ceil(n_points / n_comp)
    jumps = 2.0 * np.round(np.random.rand(m)) - 1
    am = np.kron(jumps, np.ones((n_comp,)))[:n_points]
    y = am * fmconst(n_points, f0, 1)[0]
    return y, am