transient_sources.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:SpicePy 作者: giaccone 项目源码 文件源码
def sin(Vo, Va, Freq=None, Td=0, Df=0, Phase=0, t=None):
    """
    SIN provides a damped sinusoidal waveform in the form
    Vo + Va * np.sin(2 * np.pi * Freq * t + Phase * (np.pi / 180))

    The waveforms is:
        * t < Td ==> Vo + Va * np.sin(Phase * (np.pi / 180))
        * t > Td ==> Vo + Va * np.sin(2 * np.pi * Freq * (t - Td) + Phase * (np.pi / 180)) * np.exp(-(t - Td) * Df)

    :param Vo: offset
    :param Va: amplitude (peak) of the waveform
    :param Freq: frequency (Hz)
    :param Td: delay time (s)
    :param Df: damping factor (1/s)
    :param Phase: voltage phase (deg)
    :param t: array with times where the function has to be evaluated
    :return: the function values at times defined in t
    """

    # check presence of time array
    if t is None:
        raise TypeError('Missing time array')

    # check if t is scalar
    if isinstance(t, (int, float)):
        t = np.array([t])

    # check presence of Freq
    if Freq is None:
        Freq = 1 / t[-1]

    out = np.zeros_like(t)
    out[t <= Td] = Vo + Va * np.sin(Phase * (np.pi / 180))
    out[t > Td] = Vo + Va * np.sin(2 * np.pi * Freq * (t[t > Td] - Td) + Phase * (np.pi / 180)) * np.exp(-(t[t > Td] - Td) * Df)

    # if input is scalar convert out to scalar too
    if out.size == 1:
        out = np.asscalar(out)

    return out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号