Signal#
- class Signal(envelope, carrier_freq=0.0, phase=0.0, name=None)[source]#
Bases:
object
General signal class.
Represents a function of the form:
\[Re[f(t)e^{i (2 \pi \nu t + \phi)}] = Re[f(t)]\cos(2 \pi \nu t + \phi) - Im[f(t)]\sin(2 \pi \nu t + \phi),\]where
\(f(t)\) is the envelope function.
\(\nu\) is the carrier frequency.
\(\phi\) is the phase.
The envelope function can be specified either as a constant numeric value (indicating a constant function), or as a complex-valued callable, and the frequency and phase must be real.
Note
Signal
assumes the envelopef
is array vectorized in the sense thatf
can operate on arrays of arbitrary shape and satisfyf(x)[idx] == f(x[idx])
for a multidimensional indexidx
. This can be ensured either by writingf
to be vectorized, or by using thevectorize
function innumpy
orjax.numpy
.For example, for an unvectorized envelope function
f
:import numpy as np vectorized_f = np.vectorize(f) signal = Signal(envelope=vectorized_f, carrier_freq=2.)
Initializes a signal given by an envelope and a carrier.
- Parameters:
envelope (
Union
[Callable
,ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
]) – Envelope function of the signal, must be vectorized.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 (
Optional
[str
]) – Name of the signal.
Methods
- complex_value(t)[source]#
Vectorized evaluation of the complex value at time t.
- Return type:
Union
[ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
]
- draw(t0, tf, n, function='signal', axis=None, title=None)[source]#
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)[source]#
Vectorized evaluation of the envelope at time t.
- Return type:
Union
[ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
]
Attributes
- carrier_freq#
The carrier frequency of the signal.
- is_constant#
Whether or not the signal is constant.
- name#
Return the name of the signal.
- phase#
The phase of the signal.