peng/wave_functions.py
def fft(wave, npoints=None, indep_min=None, indep_max=None):
    r"""
    Return the Fast Fourier Transform of a waveform.

    :param wave: Waveform
    :type  wave: :py:class:`peng.eng.Waveform`

    :param npoints: Number of points to use in the transform. If **npoints**
                    is less than the size of the independent variable vector
                    the waveform is truncated; if **npoints** is greater than
                    the size of the independent variable vector, the waveform
                    is zero-padded
    :type  npoints: positive integer

    :param indep_min: Independent vector start point of computation
    :type  indep_min: integer or float

    :param indep_max: Independent vector stop point of computation
    :type  indep_max: integer or float

    :rtype: :py:class:`peng.eng.Waveform`

    .. [[[cog cog.out(exobj_eng.get_sphinx_autodoc(raised=True)) ]]]
    .. Auto-generated exceptions documentation for peng.wave_functions.fft

    :raises:
     * RuntimeError (Argument \`indep_max\` is not valid)

     * RuntimeError (Argument \`indep_min\` is not valid)

     * RuntimeError (Argument \`npoints\` is not valid)

     * RuntimeError (Argument \`wave\` is not valid)

     * RuntimeError (Incongruent \`indep_min\` and \`indep_max\`
       arguments)

     * RuntimeError (Non-uniform sampling)

    .. [[[end]]]
    """
    ret = copy.copy(wave)
    _bound_waveform(ret, indep_min, indep_max)
    npoints = npoints or ret._indep_vector.size
    fs = (npoints - 1) / float(ret._indep_vector[-1])
    spoints = min(ret._indep_vector.size, npoints)
    sdiff = np.diff(ret._indep_vector[:spoints])
    cond = not np.all(
        np.isclose(sdiff, sdiff[0] * np.ones(spoints - 1), FP_RTOL, FP_ATOL)
    )
    pexdoc.addex(RuntimeError, "Non-uniform sampling", cond)
    finc = fs / float(npoints - 1)
    indep_vector = _barange(-fs / 2.0, +fs / 2.0, finc)
    dep_vector = np.fft.fft(ret._dep_vector, npoints)
    return Waveform(
        indep_vector=indep_vector,
        dep_vector=dep_vector,
        dep_name="fft({0})".format(ret.dep_name),
        indep_scale="LINEAR",
        dep_scale="LINEAR",
        indep_units="Hz",
        dep_units="",
    )
def fft(wave, npoints=None, indep_min=None, indep_max=None):
    r"""
    Return the Fast Fourier Transform of a waveform.

    :param wave: Waveform
    :type  wave: :py:class:`peng.eng.Waveform`

    :param npoints: Number of points to use in the transform. If **npoints**
                    is less than the size of the independent variable vector
                    the waveform is truncated; if **npoints** is greater than
                    the size of the independent variable vector, the waveform
                    is zero-padded
    :type  npoints: positive integer

    :param indep_min: Independent vector start point of computation
    :type  indep_min: integer or float

    :param indep_max: Independent vector stop point of computation
    :type  indep_max: integer or float

    :rtype: :py:class:`peng.eng.Waveform`

    .. [[[cog cog.out(exobj_eng.get_sphinx_autodoc(raised=True)) ]]]
    .. Auto-generated exceptions documentation for peng.wave_functions.fft

    :raises:
     * RuntimeError (Argument \`indep_max\` is not valid)

     * RuntimeError (Argument \`indep_min\` is not valid)

     * RuntimeError (Argument \`npoints\` is not valid)

     * RuntimeError (Argument \`wave\` is not valid)

     * RuntimeError (Incongruent \`indep_min\` and \`indep_max\`
       arguments)

     * RuntimeError (Non-uniform sampling)

    .. [[[end]]]
    """
    ret = copy.copy(wave)
    _bound_waveform(ret, indep_min, indep_max)
    npoints = npoints or ret._indep_vector.size
    fs = (npoints - 1) / float(ret._indep_vector[-1])
    spoints = min(ret._indep_vector.size, npoints)
    sdiff = np.diff(ret._indep_vector[:spoints])
    cond = not np.all(
        np.isclose(sdiff, sdiff[0] * np.ones(spoints - 1), FP_RTOL, FP_ATOL)
    )
    pexdoc.addex(RuntimeError, "Non-uniform sampling", cond)
    finc = fs / float(npoints - 1)
    indep_vector = _barange(-fs / 2.0, +fs / 2.0, finc)
    dep_vector = np.fft.fft(ret._dep_vector, npoints)
    return Waveform(
        indep_vector=indep_vector,
        dep_vector=dep_vector,
        dep_name="fft({0})".format(ret.dep_name),
        indep_scale="LINEAR",
        dep_scale="LINEAR",
        indep_units="Hz",
        dep_units="",
    )
r"""
    Return the Fast Fourier Transform of a waveform.

    :param wave: Waveform
    :type  wave: :py:class:`peng.eng.Waveform`

    :param npoints: Number of points to use in the transform. If **npoints**
                    is less than the size of the independent variable vector
                    the waveform is truncated; if **npoints** is greater than
                    the size of the independent variable vector, the waveform
                    is zero-padded
    :type  npoints: positive integer

    :param indep_min: Independent vector start point of computation
    :type  indep_min: integer or float

    :param indep_max: Independent vector stop point of computation
    :type  indep_max: integer or float

    :rtype: :py:class:`peng.eng.Waveform`

    .. [[[cog cog.out(exobj_eng.get_sphinx_autodoc(raised=True)) ]]]
    .. Auto-generated exceptions documentation for peng.wave_functions.fft

    :raises:
     * RuntimeError (Argument \`indep_max\` is not valid)

     * RuntimeError (Argument \`indep_min\` is not valid)

     * RuntimeError (Argument \`npoints\` is not valid)

     * RuntimeError (Argument \`wave\` is not valid)

     * RuntimeError (Incongruent \`indep_min\` and \`indep_max\`
       arguments)

     * RuntimeError (Non-uniform sampling)

    .. [[[end]]]