magnelio.signals#
Signals — excitation waveforms and sampled time series.
A Waveform is the time function an Excitation
binds to a port or source (unit peak, known bandwidth and duration);
Signal1D is a sampled series on the result side, with its
spectrum.
- class magnelio.signals.Signal1D(t, values, dt, label='')#
Immutable time-domain signal.
- Parameters:
t (np.ndarray) – Time axis [s], shape (N,).
values (np.ndarray) – Signal values, shape (N,).
dt (float) – Time step [s].
label (str) – Optional label for identification.
- at_frequencies(f_target)#
Evaluate spectrum at arbitrary frequency points.
Two paths:
Direct DFT (default for small
Nf · N): evaluatesΣ_n x_n · e^{-2π j f t_n} · dtexactly at every requested frequency. Cost:O(Nf · N). Equivalent in scale tonp.fft.rfft(rfftreturnsΣ_n x_n · e^{-2π j k n / N}without adtfactor; the direct DFT here returns the same magnitude after dividing the Riemann-sum form bydt, i.e. cancels the explicitdtfactor).Zero-padded rFFT + linear interp (fallback for large
Nf · N): the historical path; pads so the FFT bin spacing is at mostdf_target / 2and linear-interpolatesreal/imag. Faster for very densef_target, but introduces a 1–3 % magnitude error when the inter-bin phase rotates significantly (~30° per bin) — manifests as a spurious|S|² < 1floor in the modal-port S-parameter pipeline. Switching to the direct DFT for smallNf · Neliminates that floor down to floating-point precision.
- Parameters:
f_target (np.ndarray) – Target frequencies [Hz].
- Returns:
Complex spectrum values at
f_target.- Return type:
np.ndarray
- class magnelio.signals.Waveform#
Excitation waveform: a unit-peak time function with a bandwidth.
Every waveform is callable —
w(t)for a float or an array of times [s] — and describes its own spectral occupancy and duration:f_maxUpper band edge [Hz]; sizes the time step and the run-length estimate.
f_minLower band edge [Hz];
0for baseband forms.f_centerCarrier frequency [Hz], or
Nonefor baseband forms. AnExcitationmay carry aphaseonly on a waveform with a carrier.t_endTime [s] after which the waveform is (effectively) zero;
inffor continuous-wave forms, which need an explicit run duration.
The amplitude, delay and phase of a drive live on the
Excitation, not here, so a single waveform can drive several ports and sources.See also
WaveformGaussian,WaveformGaussianModulated,WaveformSine,WaveformStep,WaveformTable,WaveformFunction- plot(ax=None, *, n=2000, t_max=None, **kwargs)#
Plot the waveform against time.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure otherwise.
n (int, default 2000) – Number of samples.
t_max (float, optional) – End of the time axis [s]. Default:
t_endfor finite forms, ten carrier periods (or ten rise times) for continuous-wave forms.**kwargs – Forwarded to
ax.plot.
- Return type:
- sample(dt, n, label='')#
Sample the waveform on
t = arange(n) · dt.- Parameters:
dt (float) – Time step [s].
n (int) – Number of samples.
label (str, optional) – Label of the returned signal.
- Returns:
The sampled waveform.
- Return type:
- spectrum(f)#
Continuous-time spectrum
∫ w(t) e^{-2πj f t} dtat frequencies f [Hz].The same sign convention as
Signal1D.at_frequencies(). Closed-form where the waveform has one; otherwise the waveform is sampled tot_endat twenty points per1/f_maxand integrated numerically. Continuous-wave forms (t_end = inf) have no finite-energy spectrum and raise.
- class magnelio.signals.WaveformFunction(fn, f_max, f_min=0.0, f_center=None, t_end=inf)#
Waveform from a user function
fn(t).The band edges cannot be read off a Python function, so
f_maxis required — it sizes the run-length estimate and the warning against exceeding the mesh’s design frequency. A function waveform cannot be stored in a project recipe, so a run driven by it cannot be resumed.- Parameters:
fn (callable) –
fn(t) -> valuefor a floatt[s]; may accept arrays.f_max (float) – Upper band edge [Hz].
f_min (float, default 0.0) – Lower band edge [Hz].
f_center (float, optional) – Carrier frequency [Hz], if the function is a modulated form.
t_end (float, default inf) – Time [s] after which
fnis effectively zero;infmarks a continuous-wave form.
- class magnelio.signals.WaveformGaussian(f_max)#
Baseband Gaussian pulse (DC-inclusive), unit peak at
t = 4 / f_max.The pulse for TEM and lumped ports and for any source that may carry DC. Its spectrum is a Gaussian of width
f_max(thee^{-4}point), sof_maxis the useful upper band edge.- Parameters:
f_max (float) – Upper band edge [Hz].
Examples
>>> from magnelio import signals >>> w = signals.WaveformGaussian(f_max=10e9) >>> w(4.0 / 10e9) 1.0
- spectrum(f)#
Continuous-time spectrum
∫ w(t) e^{-2πj f t} dtat frequencies f [Hz].The same sign convention as
Signal1D.at_frequencies(). Closed-form where the waveform has one; otherwise the waveform is sampled tot_endat twenty points per1/f_maxand integrated numerically. Continuous-wave forms (t_end = inf) have no finite-energy spectrum and raise.
- property t_end: float#
Twice the peak time — the pulse is below 1e-17 of its peak there.
- class magnelio.signals.WaveformGaussianModulated(f_min, f_max)#
Gaussian envelope on a carrier at the band centre, unit peak.
The band-limited pulse for TE/TM modes and any drive whose lower band edge matters: the envelope’s sigma follows the passband
f_max − f_min, so almost no energy leaks belowf_min. The carrier sits at(f_min + f_max) / 2, which makes this the waveform anExcitationmay phase-shift.- Parameters:
f_min (float) – Lower band edge [Hz].
f_max (float) – Upper band edge [Hz]; must exceed
f_min.
Examples
>>> from magnelio import signals >>> w = signals.WaveformGaussianModulated(f_min=8.2e9, f_max=12.4e9) >>> w.f_center 10300000000.0
- spectrum(f)#
Continuous-time spectrum
∫ w(t) e^{-2πj f t} dtat frequencies f [Hz].The same sign convention as
Signal1D.at_frequencies(). Closed-form where the waveform has one; otherwise the waveform is sampled tot_endat twenty points per1/f_maxand integrated numerically. Continuous-wave forms (t_end = inf) have no finite-energy spectrum and raise.
- property t_end: float#
Twice the peak time — the envelope is below 1e-17 of its peak there.
- class magnelio.signals.WaveformSine(f, phase=0.0, rise_time=None)#
Continuous-wave sinusoid
sin(2π f t + phase), unit amplitude.A single-frequency drive; zero for
t < 0. Its duration is infinite (t_end = inf), so a run driven by it needs an explicit duration and cannot stop on energy decay. Withrise_timethe amplitude ramps in with a raised-cosine envelope, which keeps the switch-on from exciting the whole band.- Parameters:
f (float) – Frequency [Hz].
phase (float, default 0.0) – Phase [degrees].
rise_time (float, optional) – Length of the raised-cosine switch-on [s].
None(default) switches on hard att = 0.
- class magnelio.signals.WaveformStep(rise_time, hold=None, fall_time=None)#
Raised-cosine step (or pulse), unit plateau.
Rises from 0 to 1 over
rise_time; withholdit stays at 1 for that long and falls back overfall_time— a smooth rectangular pulse for time-domain reflectometry. Withoutholdthe plateau lasts forever (t_end = inf), so the run needs an explicit duration. Zero fort < 0.- Parameters:
rise_time (float) – Length of the raised-cosine rise [s].
f_maxis1 / rise_time, the bandwidth the edge occupies.hold (float, optional) – Plateau duration [s].
None(default) never falls.fall_time (float, optional) – Length of the fall [s]; defaults to
rise_timewhenholdis given, ignored otherwise.
- class magnelio.signals.WaveformTable(t, values, f_max=None, f_min=0.0, f_center=None)#
Tabulated waveform, linearly interpolated between its samples.
Zero outside
[t[0], t[-1]]. The band edges default to what the table’s own spectrum shows:f_maxis the highest frequency at which the magnitude is still within 40 dB of its peak; give it explicitly when the table is short or noisy.- Parameters:
t (array_like) – Sample times [s], strictly increasing, starting at or after 0.
values (array_like) – Sample values, same length as
t.f_max (float, optional) – Upper band edge [Hz]; estimated from the samples by default.
f_min (float, default 0.0) – Lower band edge [Hz].
f_center (float, optional) – Carrier frequency [Hz] when the table holds a modulated pulse.