Signal

class Signal[source]

Bases: ABC, HDFSerializable

Abstract base class for all signal models in HermesPy.

static Create(samples, sampling_rate=1.0, carrier_frequency=0.0, noise_power=0.0, delay=0.0, offsets=None)[source]

Creates a signal model instance given signal samples. Subclasses of Signal should reroute the given arguments to init and return the result.

Parameters:
  • samples (np.ndarray | Sequence[np.ndarray]) –

    Single or a sequence of 2D matricies with shapes MxT_i, where

    M - number of streams, T_i - number of samples in the matrix i.

    Note that M for each entry of the sequence must be the same. SignalBlock and Sequence[SignalBlock] can also be passed here.

  • sampling_rate (float) – Sampling rate of the signal in Hz.

  • offsets (List[int]) – Integer offsets of the samples if given in a sequence. Ignored if samples is not a Sequence of np.ndarray. len(offsets) must be equal to len(samples). Offset number i must be greater then offset i-1 + samples[i-1].shape[1].

Return type:

Signal

Returns
signal (Signal):

SparseSignal if samples argument is a list of np.ndarrays. DenseSignal otherwise.

static Empty(sampling_rate, num_streams=0, num_samples=0, **kwargs)[source]

Creates an empty signal model instance. Initializes it with the given arguments. If both num_streams and num_samples are not 0, then initilizes samples with np.empty.

Return type:

Signal

append_samples(signal)[source]

Append samples in time-domain to the signal model.

Parameters:

signal (Signal) – The signal to be appended.

Raises:

ValueError – If the number of streams don’t align.

Return type:

None

append_streams(signal)[source]

Append streams to the signal model.

Parameters:

signal (Signal) – The signal to be appended.

Raises:

ValueError – If the number of samples don’t align.

Return type:

None

copy()[source]

Copy this signal model to a new object.

Returns:

A copy of this signal model.

Return type:

Signal

classmethod from_interleaved(interleaved_samples, scale=True, **kwargs)[source]

Initialize a signal model from interleaved samples.

Parameters:
  • interleaved_samples (np.ndarray) – Numpy array of interleaved samples.

  • scale (bool, optional) – Scale the samples after interleaving

  • **kwargs – Additional class initialization arguments.

Return type:

Signal

from_ndarray(samples)[source]

Create a new signal using parameters from this signal. Equivalent to create(samples, **self.kwargs).

resample(sampling_rate, aliasing_filter=True)[source]

Resample the modeled signal to a different sampling rate.

Parameters:
  • sampling_rate (float) – Sampling rate of the new signal model in Hz.

  • aliasing_filter (bool, optional) – Apply an anti-aliasing filter during downsampling. Enabled by default.

Returns:

The resampled signal model.

Return type:

Signal

Raises:

ValueError – If sampling_rate is smaller or equal to zero.

set_samples(samples, offsets=None)[source]

Sets given samples into this dense signal model. Validates given samples and optional offsets, writes them into _blocks attribute and resambles, if needed.

Return type:

None

superimpose(added_signal, resample=True, aliasing_filter=True, stream_indices=None)[source]

Superimpose an additive signal model to this model.

Internally re-samples added_signal to this model’s sampling rate, if required. Mixes added_signal according to the carrier-frequency distance.

Parameters:
  • added_signal (Signal) – The signal to be superimposed onto this one.

  • resample (bool) – Allow for dynamic resampling during superposition.

  • aliasing_filter (bool, optional) – Apply an anti-aliasing filter during mixing.

  • stream_indices (Sequence[int], optional) – Indices of the streams to be mixed.

Raises:
  • ValueError – If added_signal contains a different number of streams than this signal model.

  • RuntimeError – If resampling is required but not allowd.

  • NotImplementedError – If the delays if this signal and added_signal differ.

Return type:

None

to_dense()[source]

Concatenate all the blocks in the signal into one block. Accounts for offsets. Warning - if offset values are to big, memory overflow is possible.

Returns:

Dense form for this signal

Return type:

signal (DenseSignal)

to_interleaved(data_type=<class 'numpy.int16'>, scale=True)[source]

Convert the complex-valued floating-point model samples to interleaved integers.

Parameters:
  • data_type (optional) – Numpy resulting data type.

  • scale (bool, optional) – Scale the floating point values to stretch over the whole range of integers.

Returns:

Numpy array of interleaved samples. Will contain double the samples in time-domain.

Return type:

samples (np.ndarray)

property carrier_frequency: float

The center frequency of the modeled signal in the radio-frequency transmit band.

Returns:

The carrier frequency in Hz.

Return type:

float

delay: float
property duration: float

Signal model duration in time-domain.

Returns:

Duration in seconds.

Return type:

float

property energy: ndarray

Compute the energy of the modeled signal.

Returns: The energy of each modeled stream within a numpy vector.

property eye: _EyeVisualization

Visualize the eye diagram of the signal model.

filter_order: int = 10
property frequencies: ndarray

The signal model’s discrete sample points in frequcy domain.

Returns: Numpy vector of frequency bins.

property kwargs: dict

Returns: {“sampling_rate”: self.sampling_rate, “carrier_frequency”: self.carrier_frequency, “delay”: self.delay, “noise_power”: self.noise_power}

property noise_power: float

Noise power of the superimposed noise signal.

Returns:

Noise power.

Raises:

ValueError – If the noise power is smaller than zero.

property num_samples: int

The number of samples within this signal model.

Returns:

The number of samples.

Return type:

int

property num_streams: int

The number of streams within this signal model.

Returns:

The number of streams.

Return type:

int

property plot: _SamplesVisualization

Visualize the samples of the signal model.

property power: ndarray

Compute the power of the modeled signal.

Returns: The power of each modeled stream within a numpy vector.

property sampling_rate: float

The rate at which the modeled signal was sampled.

Returns:

The sampling rate in Hz.

Return type:

float

property shape: tuple

(num_streams, num_samples)

Type:

Returns

property timestamps: ndarray

The sample-points of the signal block.

Returns:

Vector of length T containing sample-timestamps in seconds.

Return type:

np.ndarray

property title: str