TimeDomainSignal¶
- class modusa.signals.time_domain_signal.TimeDomainSignal(y: ndarray, sr: float, t0: float = 0.0, title: str | None = None)[source]¶
Bases:
ModusaSignal
Initialize a uniformly sampled 1D time-domain signal.
Not to be instantiated directly.
This class is specifically designed to hold 1D signals that result
from slicing a 2D representation like a spectrogram. - For example, if you have a spectrogram S and you perform S[10, :], the result is a 1D signal over time, this class provides a clean and consistent way to handle such slices.
- Parameters:
y (np.ndarray) – The 1D signal values sampled uniformly over time.
sr (float) – The sampling rate in Hz (samples per second).
t0 (float, optional) – The starting time of the signal in seconds (default is 0.0).
title (str, optional) – An optional title used for labeling or plotting purposes.
- property y: ndarray¶
- property sr: ndarray¶
- property t0: ndarray¶
- property t: ndarray¶
Timestamp array of the audio.
- property Ts: float¶
Sampling Period of the audio.
- property duration: float¶
Duration of the audio.
- property shape: tuple¶
Shape of the audio signal.
- property ndim: int¶
Dimension of the audio.
- plot(ax: Axes | None = None, fmt: str = 'k-', title: str | None = None, label: str | None = None, ylabel: str | None = 'Amplitude', xlabel: str | None = 'Time (sec)', ylim: tuple[float, float] | None = None, xlim: tuple[float, float] | None = None, highlight: list[tuple[float, float]] | None = None, vlines: list[float] | None = None, hlines: list[float] | None = None, show_grid: bool = False, stem: bool | None = False, legend_loc: str | None = None) Figure | None [source]¶
Plot the audio waveform using matplotlib.
from modusa.generators import AudioSignalGenerator audio_example = AudioSignalGenerator.generate_example() audio_example.plot(color="orange", title="Example Audio")
- Parameters:
ax (matplotlib.axes.Axes | None) – Pre-existing axes to plot into. If None, a new figure and axes are created.
fmt (str | None) – Format of the plot as per matplotlib standards (Eg. “k-” or “blue–o)
title (str | None) – Plot title. Defaults to the signal’s title.
label (str | None) – Label for the plot, shown as legend.
ylabel (str | None) – Label for the y-axis. Defaults to “Amplitude”.
xlabel (str | None) – Label for the x-axis. Defaults to “Time (sec)”.
ylim (tuple[float, float] | None) – Limits for the y-axis.
xlim (tuple[float, float] | None)
highlight (list[tuple[float, float]] | None) – List of time intervals to highlight on the plot, each as (start, end).
vlines (list[float]) – List of x values to draw vertical lines. (Eg. [10, 13.5])
hlines (list[float]) – List of y values to draw horizontal lines. (Eg. [10, 13.5])
show_grid (bool) – If true, shows grid.
stem (bool) – If True, use a stem plot instead of a continuous line. Autorejects if signal is too large.
legend_loc (str | None) – If provided, adds a legend at the specified location (e.g., “upper right” or “best”). Limits for the x-axis.
- Returns:
The figure object containing the plot or None in case an axis is provided.
- Return type:
matplotlib.figure.Figure | None