DiscreteSignal#

class DiscreteSignal(dt, samples, start_time=0.0, carrier_freq=0.0, phase=0.0, name=None)[source]#

Bases: Signal

Piecewise constant signal implemented as an array of samples.

The envelope is specified by an array of samples s = [s_0, ..., s_k], sample width dt, and a start time t_0, with the envelope being evaluated as \(f(t) =\) s[floor((t - t0)/dt)] if t is in the interval with endpoints start_time and start_time + dt * len(samples), and 0.0 otherwise. By default a DiscreteSignal is defined to start at \(t=0\) but a custom start time can be set via the start_time kwarg.

Initialize a piecewise constant signal.

Parameters:
  • dt (float) – The duration of each sample.

  • samples (Union[ndarray, number, int, float, complex, Tracer, Array, Array, spmatrix, BCOO, list]) – The array of samples.

  • start_time (float) – The time at which the signal starts.

  • carrier_freq (Union[ndarray, number, int, float, complex, Tracer, Array, Array, spmatrix, BCOO, list]) – Frequency of the carrier. Subclasses such as SignalSums represent the carriers of each signal in an array.

  • phase (Union[ndarray, number, int, float, complex, Tracer, Array, Array, spmatrix, BCOO, list]) – The phase of the carrier. Subclasses such as SignalSums represent the phase of each signal in an array.

  • name (str) – Name of the signal.

Methods

add_samples(start_sample, samples)[source]#

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)#

Vectorized evaluation of the complex value at time t.

Return type:

Union[ndarray, number, int, float, complex, Tracer, Array, Array, spmatrix, BCOO, list]

conjugate()[source]#

Return a new signal whose complex value is the complex conjugate of this one.

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 the complex_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]

classmethod from_Signal(signal, dt, n_samples, start_time=0.0, sample_carrier=False)[source]#

Constructs a DiscreteSignal object by sampling a Signal.

The optional argument sample_carrier controls whether or not to include the carrier in the sampling. I.e.:

  • If sample_carrier == False, a DiscreteSignal is constructed with:
    • samples obtained by sampling signal.envelope.

    • carrier_freq = signal.carrier_freq.

    • phase = signal.phase.

  • If sample_carrier == True, a DiscreteSignal is constructed with:
    • samples obtained by sampling signal (as a callable)

    • carrier_freq = 0.

    • phase = signal.phase.

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:

DiscreteSignal

Attributes

carrier_freq#

The carrier frequency of the signal.

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.