Generators

FunctionGenerator

FunctionGenerator is the generic function generator. The output waveform is shaped by its output function. A FunctionGenerator can be constructed by specifying its output function outputfunc.

Basic Operation AbstractSource

An AbstractSource is a subtype of AbstractComponent. (See Components for more information.) An AbstractComponent has input and output for data flow. The AbstractComponent reads data from the input and writes data to output. Since the input-output relation of AbstractSource depends on just the current time t, Sources does not have inputs since they do not read input values. They just need time t to compute its output. During their evolution, the AbstractComponent read time t from their trigger links, computes their output according to their output function and writes its computed output to their output busses. An AbstractComponent also writes true to their handshake links to signal that the evolution is succeeded. To further clarify the operation of AbstractSource, let us do some examples.

julia> using Jusdl # hide

julia> outputfunc(t) = t * exp(t) + sin(t)
outputfunc (generic function with 1 method)

julia> gen = FunctionGenerator(outputfunc)
FunctionGenerator(outputfunc:outputfunc, nout:1)

We constructed a FunctionGenerator which is an AbstractSource.

julia> gen isa AbstractSource
true

To drive gen, that is to make gen evolve, we need to launch gen.

julia> t = launch(gen)
(Task (runnable) @0x00007f70256a8280, Task (runnable) @0x00007f70256a3a90)

At this moment, gen is ready to be triggered from its trigger link. Note that the trigger link gen.trigger and the output gen.output of gen are writable.

julia> gen.trigger
Link(state:open, eltype:Float64, hasmaster:false, numslaves:0, isreadable:false, iswritable:true)

julia> gen.output
1-element Bus{Link{Float64}}:
 Link(state:open, eltype:Float64, hasmaster:false, numslaves:0, isreadable:false, iswritable:true)

gen is triggered by writing time t to its trigger link gen.trigger.

julia> put!(gen.trigger, 1.)
1.0

When triggered gen writes true to its handshake link gen.handshake. Note that gen.handshake is readable.

julia> gen.handshake
Link(state:open, eltype:Bool, hasmaster:false, numslaves:0, isreadable:true, iswritable:false)

and to drive gen for another time gen.handshake must be read.

julia> take!(gen.handshake)
true

Now continue driving gen.

julia> for t in 2. : 10.
           put!(gen.trigger, t)
           take!(gen.handshake)
       end

When triggered, the output of gen is written to its output gen.output.

julia> println(gen.output[1].buffer.data)
[3.5597528132669414, 15.687409624686982, 60.39773077762287, 217.635797637269, 741.1068712382199, 2420.2933454582117, 7677.0890955979285, 23848.65325458045, 72928.1674666637, 220264.11392695628, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

In addition to generic FunctionGenerator, Jusdl provides some other function generators which are documented in the following section.

Full API

Jusdl.Components.Sources.SinewaveGeneratorType
SinewaveGenerator(;amplitude=1., frequency=1., phase=0., delay=0., offset=0.)

Constructs a SinewaveGenerator with output of the form

\[ x(t) = A sin(2 \pi f (t - \tau) + \phi) + B\]

where $A$ is amplitude, $f$ is frequency, $\tau$ is delay and $\phi$ is phase and $B$ is offset.

source
Jusdl.Components.Sources.DampedSinewaveGeneratorType
DampedSinewaveGenerator(;amplitude=1., decay=-0.5, frequency=1., phase=0., delay=0., offset=0.)

Constructs a DampedSinewaveGenerator which generates outputs of the form

\[ x(t) = A e^{\alpha t} sin(2 \pi f (t - \tau) + \phi) + B\]

where $A$ is amplitude, $\alpha$ is decay, $f$ is frequency, $\phi$ is phase, $\tau$ is delay and $B$ is offset.

source
Jusdl.Components.Sources.SquarewaveGeneratorType
SquarewaveGenerator(;level1=1., level2=0., period=1., duty=0.5, delay=0.)

Constructs a SquarewaveGenerator with output of the form

\[ x(t) = \left\{\begin{array}{lr} A_1 + B, & kT + \tau \leq t \leq (k + \alpha) T + \tau \\ A_2 + B, & (k + \alpha) T + \tau \leq t \leq (k + 1) T + \tau \end{array} \right. \quad k \in Z\]

where $A_1$, $A_2$ is level1 and level2, $T$ is period, $\tau$ is delay $\alpha$ is duty.

source
Jusdl.Components.Sources.TriangularwaveGeneratorType
TriangularwaveGenerator(;amplitude=1, period=1, duty=0.5, delay=0, offset=0)

Constructs a TriangularwaveGenerator with output of the form

\[ x(t) = \left\{\begin{array}{lr} \dfrac{A t}{\alpha T} + B, & kT + \tau \leq t \leq (k + \alpha) T + \tau \\[0.25cm] \dfrac{A (T - t)}{T (1 - \alpha)} + B, & (k + \alpha) T + \tau \leq t \leq (k + 1) T + \tau \end{array} \right. \quad k \in Z\]

where $A$ is amplitude, $T$ is period, $\tau$ is delay $\alpha$ is duty.

source
Jusdl.Components.Sources.StepGeneratorType
StepGenerator(;amplitude=1, delay=0, offset=0)

Constructs a StepGenerator with output of the form

\[ x(t) = \left\{\begin{array}{lr} B, & t \leq \tau \\ A + B, & t > \tau \end{array} \right.\]

where $A$ is amplitude, $B$ is the offset and `\tau is the delay.

source
Jusdl.Components.Sources.ExponentialGeneratorType
ExponentialGenerator(;scale=1, decay=-1, delay=0.)

Constructs an ExponentialGenerator with output of the form

\[ x(t) = A e^{\alpha (t - \tau)}\]

where $A$ is scale, $\alpha$ is decay and $tau$ is delay.

source
Jusdl.Components.Sources.DampedExponentialGeneratorType
DampedExponentialGenerator(;scale=1, decay=-1, delay=0.)

Constructs an DampedExponentialGenerator with outpsuts of the form

\[ x(t) = A (t - \tau) e^{\alpha (t - \tau)}\]

where $A$ is scale, $\alpha$ is decay, $tau$ is delay.

source