pathsim.blocks.sources module¶
- class pathsim.blocks.sources.Constant(value=1)[source]¶
Bases:
BlockProduces a constant output signal (SISO)
- Parameters:
value (float) – constant defining block output
- class pathsim.blocks.sources.Source(func=<function Source.<lambda>>)[source]¶
Bases:
BlockSource that produces an arbitrary time dependent output, defined by the func (callable).
\[y(t) = \mathrm{func}(t)\]Note
This block is purely algebraic and its internal function (func) will be called multiple times per timestep, each time when Simulation._update(t) is called in the global simulation loop.
Example
For example a ramp:
from pathsim.blocks import Source src = Source(lambda t : t)
or a simple sinusoid with some frequency:
import numpy as np from pathsim.blocks import Source #some parameter omega = 100 #the function that gets evaluated def f(t): return np.sin(omega * t) src = Source(f)
Because the Source block only has a single argument, it can be used to decorate a function and make it a PathSim block. This might be handy in some cases to keep definitions concise and localized in the code:
import numpy as np from pathsim.blocks import Source #does the same as the definition above @Source def src(t): omega = 100 return np.sin(omega * t) #'src' is now a PathSim block
- Parameters:
func (callable) – function defining time dependent block output
- class pathsim.blocks.sources.TriangleWaveSource(frequency=1, amplitude=1, phase=0)[source]¶
Bases:
BlockSource block that generates an analog triangle wave
- Parameters:
- update(t)[source]¶
The ‘update’ method is called iteratively for all blocks to evaluate the algebraic components of the global system ode from the DAG.
It is meant for instant time blocks (blocks that dont have a delay due to the timestep, such as Amplifier, etc.) and updates the ‘outputs’ of the block directly based on the ‘inputs’ and possibly internal states.
Note
The implementation of the ‘update’ method in the base ‘Block’ class is intended as a fallback and is not performance optimized. Special blocks might reimplement this method differently for higher performance, for example SISO or MISO blocks.
- Parameters:
t (float) – evaluation time
- class pathsim.blocks.sources.SinusoidalSource(frequency=1, amplitude=1, phase=0)[source]¶
Bases:
BlockSource block that generates a sinusoid wave
- Parameters:
- update(t)[source]¶
The ‘update’ method is called iteratively for all blocks to evaluate the algebraic components of the global system ode from the DAG.
It is meant for instant time blocks (blocks that dont have a delay due to the timestep, such as Amplifier, etc.) and updates the ‘outputs’ of the block directly based on the ‘inputs’ and possibly internal states.
Note
The implementation of the ‘update’ method in the base ‘Block’ class is intended as a fallback and is not performance optimized. Special blocks might reimplement this method differently for higher performance, for example SISO or MISO blocks.
- Parameters:
t (float) – evaluation time
- class pathsim.blocks.sources.GaussianPulseSource(amplitude=1, f_max=1000.0, tau=0.0)[source]¶
Bases:
BlockSource block that generates a gaussian pulse
- Parameters:
- update(t)[source]¶
The ‘update’ method is called iteratively for all blocks to evaluate the algebraic components of the global system ode from the DAG.
It is meant for instant time blocks (blocks that dont have a delay due to the timestep, such as Amplifier, etc.) and updates the ‘outputs’ of the block directly based on the ‘inputs’ and possibly internal states.
Note
The implementation of the ‘update’ method in the base ‘Block’ class is intended as a fallback and is not performance optimized. Special blocks might reimplement this method differently for higher performance, for example SISO or MISO blocks.
- Parameters:
t (float) – evaluation time
- class pathsim.blocks.sources.SinusoidalPhaseNoiseSource(frequency=1, amplitude=1, phase=0, sig_cum=0, sig_white=0, sampling_rate=10)[source]¶
Bases:
BlockSinusoidal source with cumulative and white phase noise
- Parameters:
frequency (float) – frequency of the sinusoid
amplitude (float) – amplitude of the sinusoid
phase (float) – phase of the sinusoid
sig_cum (float) – weight for cumulative phase noise contribution
sig_white (float) – weight for white phase noise contribution
sampling_rate (float) – number of samples per unit time for the internal RNG
- set_solver(Solver, parent, **solver_kwargs)[source]¶
Initialize the numerical integration engine with local truncation error tolerance if required.
If the block already has an integration engine, it is changed, if it does not require an integration engine, this method just passes.
- reset()[source]¶
Reset the blocks inputs and outputs and also its internal solver, if the block has a solver instance.
- update(t)[source]¶
update system equation for fixed point loop, here just setting the outputs
Note
no direct passthrough, so the ‘update’ method is optimized for this case
- Parameters:
t (float) – evaluation time
- solve(t, dt)[source]¶
The ‘solve’ method performs one iterative solution step that is required to solve the implicit update equation of the solver if an implicit solver (numerical integrator) is used.
It returns the relative difference between the new updated solution and the previous iteration of the solution to track convergence within an outer loop.
This only has to be implemented by blocks that have an internal integration engine with an implicit solver.
- step(t, dt)[source]¶
The ‘step’ method is used in transient simulations and performs an action (numeric integration timestep, recording data, etc.) based on the current inputs and the current internal state.
It performs one timestep for the internal states. For instant time blocks, the ‘step’ method does not has to be implemented specifically.
The method handles timestepping for dynamic blocks with internal states such as ‘Integrator’, ‘StateSpace’, etc.
- class pathsim.blocks.sources.ChirpPhaseNoiseSource(amplitude=1, f0=1, BW=1, T=1, phase=0, sig_cum=0, sig_white=0, sampling_rate=10)[source]¶
Bases:
BlockChirp source, sinusoid with frequency ramp up and ramp down.
This works by using a time dependent triangle wave for the frequency and integrating it with a numerical integration engine to get a continuous phase. This phase is then used to evaluate a sinusoid.
Additionally the chirp source can have white and cumulative phase noise. Mathematically it looks like this for the contributions to the phase from the triangular wave:
\[\varphi_t(t) = \int_0^t \mathrm{tri}_{f_0, B, T}(\tau) \, d\tau\]And from the white (w) and cumulative (c) noise:
\[\varphi_n(t) = \sigma_w \, \mathrm{RNG}_w(t) + \sigma_c \int_0^t \mathrm{RNG}_c(\tau) \, d\tau\]The phase contributions are then used to evaluate a sinusoid to get the final chirp signal:
\[y(t) = A \sin(\varphi_t(t) + \varphi_n(t) + \varphi_0)\]- Parameters:
amplitude (float) – amplitude of the chirp signal
f0 (float) – start frequency of the chirp signal
BW (float) – bandwidth of the frequency ramp of the chirp signal
T (float) – period of the frequency ramp of the chirp signal
phase (float) – phase of sinusoid (initial)
sig_cum (float) – weight for cumulative phase noise contribution
sig_white (float) – weight for white phase noise contribution
sampling_rate (float) – number of samples per unit time for the internal random number generators
- reset()[source]¶
Reset the blocks inputs and outputs and also its internal solver, if the block has a solver instance.
- set_solver(Solver, parent, **solver_kwargs)[source]¶
Initialize the numerical integration engine with local truncation error tolerance if required.
If the block already has an integration engine, it is changed, if it does not require an integration engine, this method just passes.
- sample(t)[source]¶
Sample from a normal distribution after successful timestep to update internal noise samples
- class pathsim.blocks.sources.ChirpSource(amplitude=1, f0=1, BW=1, T=1, phase=0, sig_cum=0, sig_white=0, sampling_rate=10)[source]¶
Bases:
ChirpPhaseNoiseSource
- class pathsim.blocks.sources.PulseSource(amplitude=1.0, T=1.0, t_rise=0.0, t_fall=0.0, tau=0.0, duty=0.5)[source]¶
Bases:
BlockGenerates a periodic pulse waveform with defined rise and fall times using a hybrid approach with scheduled events and continuous updates.
Scheduled events trigger phase changes (low, rising, high, falling), and the update method calculates the output value based on the current phase, performing linear interpolation during rise and fall.
- Parameters:
amplitude (float, optional) – Peak amplitude of the pulse. Default is 1.0.
T (float, optional) – Period of the pulse train. Must be positive. Default is 1.0.
t_rise (float, optional) – Duration of the rising edge. Default is 0.0.
t_fall (float, optional) – Duration of the falling edge. Default is 0.0.
tau (float, optional) – Initial delay before the first pulse cycle begins. Default is 0.0.
duty (float, optional) – Duty cycle, ratio of the pulse ON duration (plateau time only) to the total period T (must be between 0 and 1). Default is 0.5. The high plateau duration is T * duty.
- reset(t: float = None)[source]¶
Resets the block state.
Note
This block has a special implementation of reset where
tcan be provided to reset the block’s state to the specified time. This is done by changing the phase of the pulse + resetting all the internal events.- Parameters:
t (float, optional) – Time to reset the block state at. If None, resets to initial state.
- class pathsim.blocks.sources.Pulse(amplitude=1.0, T=1.0, t_rise=0.0, t_fall=0.0, tau=0.0, duty=0.5)[source]¶
Bases:
PulseSource
- class pathsim.blocks.sources.ClockSource(T=1, tau=0)[source]¶
Bases:
BlockDiscrete time clock source block.
Utilizes scheduled events to periodically set the block output to 0 or 1 at discrete times.
- class pathsim.blocks.sources.Clock(T=1, tau=0)[source]¶
Bases:
ClockSource
- class pathsim.blocks.sources.SquareWaveSource(amplitude=1, frequency=1, phase=0)[source]¶
Bases:
BlockDiscrete time square wave source.
Utilizes scheduled events to periodically set the block output at discrete times.
- Parameters:
- class pathsim.blocks.sources.StepSource(amplitude=1, tau=0.0)[source]¶
Bases:
BlockDiscrete time unit step source block.
Utilizes a scheduled event to set the block output to the specified output levels at the defined event times.
The arguments can be vectorial and in that case, the output is set to the amplitude that corresponds to the defined delay like a zero-order-hold stage. This functionality enables adding external or time series measurement data into the system.
Examples
This is how to use the source as a unit step source:
from pathsim.blocks import StepSource #default, starts at 0, jumps to 1 stp = StepSource()
And this is how to configure it with multiple consecutive steps:
from pathsim.blocks import StepSource #starts at 0, jumps to 1 at 1, jumps to -1 at 2 and jumps back to 0 at 3 stp = StepSource(amplitude=[1, -1, 0], tau=[1, 2, 3])
Similarly implementing measured time series data via zoh:
import numpy as np from pathsim.blocks import StepSource #some random time series arrays times, data = np.linspace(0, 100, 1000), np.random.rand(1000) #pass them to the block stp = StepSource(amplitude=data, tau=times)
- Parameters:
- Evt¶
internal scheduled event directly accessible
- Type:
- events¶
list of interna events
- Type:
- class pathsim.blocks.sources.Step(amplitude=1, tau=0.0)[source]¶
Bases:
StepSource