Sources¶
- class pathsim.blocks.sources.Constant(value=1)[source]¶
Bases:
BlockProduces a constant output signal (SISO).
\[y(t) = const.\]- Parameters:
value (float) – constant defining block output
- input_port_labels = {}¶
- output_port_labels = {'out': 0}¶
- class pathsim.blocks.sources.Source(func=<function Source.<lambda>>)[source]¶
Bases:
BlockSource that produces an arbitrary time dependent output defined by 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
- input_port_labels = {}¶
- output_port_labels = {'out': 0}¶
- class pathsim.blocks.sources.TriangleWaveSource(frequency=1, amplitude=1, phase=0)[source]¶
Bases:
SourceSource block that generates an analog triangle wave
- Parameters:
- property amplitude¶
- property frequency¶
- property phase¶
- class pathsim.blocks.sources.SinusoidalSource(frequency=1, amplitude=1, phase=0)[source]¶
Bases:
SourceSource block that generates a sinusoid wave
- Parameters:
- property amplitude¶
- property frequency¶
- property phase¶
- class pathsim.blocks.sources.GaussianPulseSource(amplitude=1, f_max=1000.0, tau=0.0)[source]¶
Bases:
SourceSource block that generates a gaussian pulse
- class pathsim.blocks.sources.SinusoidalPhaseNoiseSource(frequency=1, amplitude=1, phase=0, sig_cum=0, sig_white=0, sampling_period=0.1)[source]¶
Bases:
BlockSinusoidal source with cumulative and white phase noise.
Generates a sinusoid with additive phase noise from two components:
White phase noise: sampled from a normal distribution at each sample
Cumulative phase noise: integrated random walk process
The output is given by:
\[y(t) = A \sin\left(\omega t + \varphi_0 + \sigma_w n_w(t) + \sigma_c \int_0^t n_c(\tau) d\tau\right)\]where \(A\) is amplitude, \(\omega = 2\pi f\) is angular frequency, \(\varphi_0\) is initial phase, \(\sigma_w\) and \(\sigma_c\) are the white and cumulative noise weights, and \(n_w(t)\) and \(n_c(t)\) are independent standard normal random processes sampled at the specified sampling period.
- Parameters:
frequency (float) – frequency of the sinusoid
amplitude (float) – amplitude of the sinusoid
phase (float) – initial phase of the sinusoid (radians)
sig_cum (float) – weight for cumulative phase noise contribution
sig_white (float) – weight for white phase noise contribution
sampling_period (float, None) – time between phase noise samples. If None, noise is sampled every timestep (default is 0.1)
- input_port_labels = {}¶
- output_port_labels = {'out': 0}¶
- property amplitude¶
- property frequency¶
- property phase¶
- property sampling_period¶
- property sig_cum¶
- property sig_white¶
- update(t)[source]¶
Update system equation for fixed point loop, evaluating the sinusoid with phase noise.
- Parameters:
t (float) – evaluation time
- sample(t, dt)[source]¶
Sample from a normal distribution after successful timestep.
Only used when sampling_period is None (continuous sampling).
- solve(t, dt)[source]¶
Advance solution of implicit update equation for cumulative noise integration.
- class pathsim.blocks.sources.ChirpPhaseNoiseSource(amplitude=1, f0=1, BW=1, T=1, phase=0, sig_cum=0, sig_white=0, sampling_period=0.1)[source]¶
Bases:
BlockChirp source, sinusoid with frequency ramp up and ramp down, plus phase noise.
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 \, n_w(t) + \sigma_c \int_0^t n_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, radians)
sig_cum (float) – weight for cumulative phase noise contribution
sig_white (float) – weight for white phase noise contribution
sampling_period (float, None) – time between phase noise samples. If None, noise is sampled every timestep (default is 0.1)
- input_port_labels = {}¶
- output_port_labels = {'out': 0}¶
- sample(t, dt)[source]¶
Sample from a normal distribution after successful timestep to update internal noise samples.
Only used when sampling_period is None (continuous sampling).
- update(t)[source]¶
Update the block output, assemble phase and evaluate the sinusoid.
- Parameters:
t (float) – evaluation time
- class pathsim.blocks.sources.ChirpSource(amplitude=1, f0=1, BW=1, T=1, phase=0, sig_cum=0, sig_white=0, sampling_period=0.1)[source]¶
Bases:
ChirpPhaseNoiseSourceAlias for ChirpPhaseNoiseSource.
Deprecated since version 1.0.0: Use
ChirpPhaseNoiseSource()instead.
- 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.
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.
- input_port_labels = {}¶
- output_port_labels = {'out': 0}¶
- property amplitude¶
- property T¶
- property t_rise¶
- property t_fall¶
- property tau¶
- property 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:
PulseSourceAlias for PulseSource.
Deprecated since version 1.0.0: Use
PulseSource()instead.
- 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.
- input_port_labels = {}¶
- output_port_labels = {'out': 0}¶
- property T¶
- property tau¶
- class pathsim.blocks.sources.Clock(T=1, tau=0)[source]¶
Bases:
ClockSourceAlias for ClockSource.
Deprecated since version 1.0.0: Use
ClockSource()instead.
- 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:
- input_port_labels = {}¶
- output_port_labels = {'out': 0}¶
- property amplitude¶
- property frequency¶
- property phase¶
- class pathsim.blocks.sources.StepSource(amplitude=1, tau=0.0)[source]¶
Bases:
BlockDiscrete time unit step (or multi 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:
- input_port_labels = {}¶
- output_port_labels = {'out': 0}¶
- class pathsim.blocks.sources.Step(amplitude=1, tau=0.0)[source]¶
Bases:
StepSourceAlias for StepSource.
Deprecated since version 1.0.0: Use
StepSource()instead.