Quanlse/QWaveform.py
def mix(xWave: Optional[QWaveform], yWave: Optional[QWaveform], t0: Union[int, float] = 0.):
    """
    Return the mix of two QWaveform instances.

    :param xWave: the first QWaveform instances
    :param yWave: the second QWaveform instances
    :param t0:
    :return: returned mixed QWaveform
    """

    def func(_t, args):
        """ The mix function """
        _xWave, _yWave = args
        _xVal = 0. if _xWave is None else _xWave(_t)
        _yVal = 0. if _yWave is None else _yWave(_t)
        # Calculate amplitude
        amp = math.sqrt(_xVal ** 2 + _yVal ** 2)
        # Calculate phase
        if abs(_xVal) > 1e-10 and abs(_yVal) > 1e-10:
            varPhase = atan(_yVal / _xVal)
        elif abs(_xVal) < 1e-10 < abs(_yVal):
            varPhase = sign(_yVal) * pi / 2
        else:
            varPhase = 0.
        return amp, varPhase

    xDuration = 0. if xWave is None else xWave.t0 + xWave.t
    yDuration = 0. if yWave is None else yWave.t0 + yWave.t
    tDuration = max(xDuration, yDuration)
    wave = QWaveform(f=func, t0=t0, t=tDuration, args=(xWave, yWave), flag=QWAVEFORM_FLAG_MIX_WAVE)
    xName = "" if xWave is None else xWave.name
    yName = "" if yWave is None else yWave.name
    wave.name = "mix-{}-{}".format(xName, yName)
    return wave

    Return the mix of two QWaveform instances.

    :param xWave: the first QWaveform instances
    :param yWave: the second QWaveform instances
    :param t0:
    :return: returned mixed QWaveform
    
Return the mix of two QWaveform instances.
Return the mix of two QWaveform instances .
def mix(xWave: Optional[QWaveform], yWave: Optional[QWaveform], t0: Union[int, float] = 0.):
    def func(_t, args):
        _xWave, _yWave = args
        _xVal = 0. if _xWave is None else _xWave(_t)
        _yVal = 0. if _yWave is None else _yWave(_t)
        amp = math.sqrt(_xVal ** 2 + _yVal ** 2)
        if abs(_xVal) > 1e-10 and abs(_yVal) > 1e-10:
            varPhase = atan(_yVal / _xVal)
        elif abs(_xVal) < 1e-10 < abs(_yVal):
            varPhase = sign(_yVal) * pi / 2
        else:
            varPhase = 0.
        return amp, varPhase
    xDuration = 0. if xWave is None else xWave.t0 + xWave.t
    yDuration = 0. if yWave is None else yWave.t0 + yWave.t
    tDuration = max(xDuration, yDuration)
    wave = QWaveform(f=func, t0=t0, t=tDuration, args=(xWave, yWave), flag=QWAVEFORM_FLAG_MIX_WAVE)
    xName = "" if xWave is None else xWave.name
    yName = "" if yWave is None else yWave.name
    wave.name = "mix-{}-{}".format(xName, yName)
    return wave
def mix ( xWave : Optional [ QWaveform ] , yWave : Optional [ QWaveform ] , t0 : Union [ int , float ] = 0. ) : def func ( _t , args ) : """ The mix function """ _xWave , _yWave = args _xVal = 0. if _xWave is None else _xWave ( _t ) _yVal = 0. if _yWave is None else _yWave ( _t ) amp = math . sqrt ( _xVal ** 2 + _yVal ** 2 ) if abs ( _xVal ) > 1e-10 and abs ( _yVal ) > 1e-10 : varPhase = atan ( _yVal / _xVal ) elif abs ( _xVal ) < 1e-10 < abs ( _yVal ) : varPhase = sign ( _yVal ) * pi / 2 else : varPhase = 0. return amp , varPhase xDuration = 0. if xWave is None else xWave . t0 + xWave . t yDuration = 0. if yWave is None else yWave . t0 + yWave . t tDuration = max ( xDuration , yDuration ) wave = QWaveform ( f = func , t0 = t0 , t = tDuration , args = ( xWave , yWave ) , flag = QWAVEFORM_FLAG_MIX_WAVE ) xName = "" if xWave is None else xWave . name yName = "" if yWave is None else yWave . name wave . name = "mix-{}-{}" . format ( xName , yName ) return wave
Return the mix of two QWaveform instances.
Return the mix of two QWaveform instances .
"""
    Return the mix of two QWaveform instances.

    :param xWave: the first QWaveform instances
    :param yWave: the second QWaveform instances
    :param t0:
    :return: returned mixed QWaveform
    """ """ The mix function """ # Calculate amplitude # Calculate phase
returned mixed QWaveform
returned mixed QWaveform
xWave
Optional[QWaveform]
the first QWaveform instances
the first QWaveform instances
yWave
Optional[QWaveform]
the second QWaveform instances
the second QWaveform instances
t0
Union[int, float]
None