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
评论列表
文章目录