DiscreteSignalSum#
- class DiscreteSignalSum(dt, samples, start_time=0.0, carrier_freq=None, phase=None, name=None)[source]#
Bases:
DiscreteSignal
,SignalSum
Represents a sum of piecewise constant signals, all with the same time parameters: dt, number of samples, and start time.
Directly initialize a
DiscreteSignalSum
. Samples of all terms in the sum are specified as a 2d array, with 0th axis indicating time, and 1st axis indicating a term in the sum.- Parameters:
dt (
float
) – The duration of each sample.samples (
Union
[ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
]) – The 2d array representing a list whose elements are all envelope values at a given time.start_time (
float
) – The time at which the signal starts.carrier_freq (
Union
[ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
]) – Array with the carrier frequencies of each term in the sum.phase (
Union
[ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
]) – Array with the phases of each term in the sum.name (
str
) – name of the signal.
Methods
- add_samples(start_sample, samples)#
Appends samples to the pulse starting at start_sample, filling any gap with zeros.
- Parameters:
start_sample (
int
) – Index of the sample at which the new samples should be appended.samples (
List
) – List of samples to append.
- Raises:
QiskitError – If start_sample is less than the current length of samples.
- complex_value(t)#
Return the sum of the complex values of each component.
- Return type:
Union
[ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
]
- conjugate()#
Return the conjugation of this collection.
- draw(t0, tf, n, function='signal', axis=None, title=None)#
Plot the signal over an interval.
The
function
arg specifies which function to plot:function == 'signal'
plots the full signal.function == 'envelope'
plots the complex envelope.function == 'complex_value'
plots thecomplex_value
.
- Parameters:
t0 (
float
) – Initial time.tf (
float
) – Final time.n (
int
) – Number of points to sample in interval.function (
Optional
[str
]) – Which function to plot.axis (
Optional
[axis
]) – The axis to use for plotting.title (
Optional
[str
]) – Title of plot.
- envelope(t)#
Vectorized evaluation of the envelope at time t.
- Return type:
Union
[ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
]
- flatten()#
Merge into a single
Signal
. The output frequency is given by the average.- Return type:
- classmethod from_Signal(signal, dt, n_samples, start_time=0.0, sample_carrier=False)#
Constructs a
DiscreteSignal
object by sampling aSignal
.The optional argument
sample_carrier
controls whether or not to include the carrier in the sampling. I.e.:- If
sample_carrier == False
, aDiscreteSignal
is constructed with: samples
obtained by samplingsignal.envelope
.carrier_freq = signal.carrier_freq
.phase = signal.phase
.
- If
- If
sample_carrier == True
, aDiscreteSignal
is constructed with: samples
obtained by samplingsignal
(as acallable
)carrier_freq = 0
.phase = signal.phase
.
- If
In either case, samples are obtained from the midpoint of each interval.
- Parameters:
signal (
Signal
) – Signal to sample.dt (
float
) – Time increment to use.n_samples (
int
) – Number of steps to resample with.start_time (
Optional
[float
]) – Start time from which to resample.sample_carrier (
Optional
[bool
]) – Whether or not to include the carrier in the sampling.
- Returns:
The discretized
Signal
.- Return type:
- classmethod from_SignalSum(signal_sum, dt, n_samples, start_time=0.0, sample_carrier=False)[source]#
Constructs a
DiscreteSignalSum
object by sampling aSignalSum
.The optional argument
sample_carrier
controls whether or not to include the carrier in the sampling. I.e.:- If
sample_carrier == False
, aDiscreteSignalSum
is constructed with: samples
obtained by samplingsignal_sum.envelope
.carrier_freq = signal_sum.carrier_freq
.phase = signal_sum.phase
.
- If
- If
sample_carrier == True
, aDiscreteSignal
is constructed with: samples
obtained by samplingsignal_sum
(as acallable
)carrier_freq = 0
.phase = signal_sum.phase
.
- If
In either case, samples are obtained from the midpoint of each interval.
- Parameters:
signal_sum (
SignalSum
) – SignalSum to sample.dt (
float
) – Time increment to use.n_samples (
int
) – Number of steps to resample with.start_time (
Optional
[float
]) – Start time from which to resample.sample_carrier (
Optional
[bool
]) – Whether or not to include the carrier in the sampling.
- Returns:
The discretized
SignalSum
.- Return type:
Attributes
- carrier_freq#
The carrier frequency of the signal.
- components#
The list of components.
- dt#
Returns: dt: the duration of each sample.
- duration#
Returns: duration: The duration of the signal in samples.
- is_constant#
Whether or not the signal is constant.
- name#
Return the name of the signal.
- phase#
The phase of the signal.
- samples#
Returns: samples: the samples of the piecewise constant signal.
- start_time#
Returns: start_time: The time at which the list of samples start.