FrequencyDomainSignal

class modusa.signals.frequency_domain_signal.FrequencyDomainSignal(spectrum: ndarray, f: ndarray, t0: float | int = 0.0, title: str | None = None)[source]

Bases: ModusaSignal

Represents a 1D signal in the frequency domain.

Note

  • The class is not intended to be instantiated directly.

Parameters:
  • spectrum (np.ndarray) – The frequency-domain representation of the signal (real or complex-valued).

  • f (np.ndarray) – The frequency axis corresponding to the spectrum values. Must match the shape of spectrum.

  • t0 (float, optional) – The time (in seconds) corresponding to the origin of this spectral slice. Defaults to 0.0.

  • title (str, optional) – An optional title for display or plotting purposes.

property spectrum: ndarray

Complex valued spectrum data.

property f: ndarray

frequency array of the spectrum.

property t0: ndarray

Time origin (in seconds) of this spectral slice, e.g., from a spectrogram frame.

property ndim: int
property shape: tuple
print_info() None[source]

Prints info about the audio.

plot(ax: Axes | None = None, fmt: str = 'k-', title: str | None = None, label: str | None = None, ylabel: str | None = 'Strength', xlabel: str | None = 'Frequency (Hz)', 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 “Strength”.

  • xlabel (str | None) – Label for the x-axis. Defaults to “Frequency (Hz)”.

  • ylim (tuple[float, float] | None) – Limits for the y-axis.

  • xlim (tuple[float, float] | None)

  • highlight (list[tuple[float, float]] | None) – List of frequency 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

abs() Self[source]

Compute the element-wise abs of the signal data.

sin() Self[source]

Compute the element-wise sine of the signal data.

cos() Self[source]

Compute the element-wise cosine of the signal data.

exp() Self[source]

Compute the element-wise exponential of the signal data.

tanh() Self[source]

Compute the element-wise hyperbolic tangent of the signal data.

log() Self[source]

Compute the element-wise natural logarithm of the signal data.

log1p() Self[source]

Compute the element-wise natural logarithm of (1 + signal data).

log10() Self[source]

Compute the element-wise base-10 logarithm of the signal data.

log2() Self[source]

Compute the element-wise base-2 logarithm of the signal data.

mean() generic[source]

Compute the mean of the signal data.

std() generic[source]

Compute the standard deviation of the signal data.

min() generic[source]

Compute the minimum value in the signal data.

max() generic[source]

Compute the maximum value in the signal data.

sum() generic[source]

Compute the sum of the signal data.