torchsig.signals.builders.ofdm.OFDMSignalGenerator

class torchsig.signals.builders.ofdm.OFDMSignalGenerator(**kwargs: dict[str, str | float | int])[source]

Bases: BaseSignalGenerator

OFDM Signal Generator.

Implements OFDM waveforms with configurable parameters.

Methods

add_parent

Add parent Seedable object and set up RNGs accordingly.

copy

Creates a deep copy of the SignalGenerator with copied transforms.

generate

Generates an OFDM signal based on the configured parameters.

get_distribution

Create distribution function with proper seeding.

get_full_metadata

Function for modifying and returning a new metadata with all the fields in parent or child, with child overriding parent in conflicts.

get_second_seed

Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds.

key_lookup

Lookup a metadata key with enhanced error reporting.

keys

Get all metadata keys.

seed

Seed number generators with given seed.

set_default_class_name

Sets the class_name to name if there wasn't already a class name set.

setup_rngs

Initialize torch and numpy number generators, and update its children.

update_from_parent

Update numpy and torch number generators with parent seed.

validate_metadata_fields

Validates that all required metadata fields are present.

__init__(**kwargs: dict[str, str | float | int]) None[source]

Initializes OFDM Signal Generator.

Parameters:

**kwargs – Metadata parameters including: - sample_rate: Sampling rate (Hz) - bandwidth_min: Minimum bandwidth (Hz) - bandwidth_max: Maximum bandwidth (Hz) - num_subcarriers: Number of subcarriers - signal_duration_in_samples_min: Minimum signal duration (samples) - signal_duration_in_samples_max: Maximum signal duration (samples)

Raises:

ValueError – If required metadata fields are missing or invalid.

generate() Signal[source]

Generates an OFDM signal based on the configured parameters.

Returns:

Generated OFDM signal with metadata.

Return type:

Signal

Raises:

ValueError – If required metadata fields are missing or invalid.

__call__() Signal

Generates a new signal and applies all transforms.

Returns:

The generated signal after applying all transforms.

__repr__() str

Returns a string representation of the SignalGenerator.

Returns:

A string representation showing the class name, metadata, and transforms.

add_parent(parent: Seedable, register: bool = True) None

Add parent Seedable object and set up RNGs accordingly.

Parameters:
  • parent – Parent Seedable object to add.

  • register – If True (default), add self to parent.children so that future seed propagation reaches this object. Pass False for transient objects (e.g. per-sample Signal instances) that only need the parent link for metadata/RNG access during their lifetime but must not accumulate in the parent’s child list, which would otherwise cause unbounded memory growth.

copy() BaseSignalGenerator

Creates a deep copy of the SignalGenerator with copied transforms.

Returns:

A new instance of the SignalGenerator with copied metadata and transforms.

get_distribution(params: list | tuple | float, scaling: str = 'linear') Distribution

Create distribution function with proper seeding.

Parameters:
  • params – Parameters for distribution.

  • scaling – Scaling param for distribution. Defaults to ‘linear’.

Returns:

Distribution function, seeded.

Return type:

Distribution

get_full_metadata() dict[str, Any]

Function for modifying and returning a new metadata with all the fields in parent or child, with child overriding parent in conflicts.

Returns:

Dictionary containing all metadata from parent and child, with child values overriding parent values in case of conflicts.

Example

>>> parent = HierarchicalMetadataObject(metadata={"field_1": 4, "field_2": 5})
>>> child = HierarchicalMetadataObject(parent=parent, metadata={"field_2": 6})
>>> child.get_full_metadata()
{'field_1': 4, 'field_2': 6}
get_second_seed(seed: int) int

Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds.

Parameters:

seed – Seed to use.

Returns:

New seed.

key_lookup(key: str) Any

Lookup a metadata key with enhanced error reporting.

Parameters:

key – The metadata key to lookup.

Returns:

The value associated with the key.

Raises:

MetadataAttributeError – If the key is not found in the metadata or parent metadata.

Example

>>> obj = HierarchicalMetadataObject(metadata={"key": "value"})
>>> obj.key_lookup("key")
'value'
keys() list[str]

Get all metadata keys.

Returns:

List of all metadata keys.

Example

>>> obj = HierarchicalMetadataObject(metadata={"key1": 1, "key2": 2})
>>> list(obj.keys())
['key1', 'key2']
seed(seed: int) None

Seed number generators with given seed.

Parameters:

seed – Seed to use.

set_default_class_name(name: str) None

Sets the class_name to name if there wasn’t already a class name set.

Parameters:

name – The class name to set if no class name exists.

setup_rngs() None

Initialize torch and numpy number generators, and update its children.

update_from_parent() None

Update numpy and torch number generators with parent seed.

validate_metadata_fields() None

Validates that all required metadata fields are present.

Throws an exception if required_metadata_fields are not filled. Does nothing if required_metadata_fields is not set.

Raises:
  • TypeError – If any required metadata field names are not strings.

  • ValueError – If any required metadata fields are missing.