Skip to content

Modem Algorithms

Common digital modulation algorithms.

DSSS

Bases: Modem

Direct-sequence spread spectrum modulation and demodulation.

Currently implemented using the third-party commpy library. Note that DSSS does not contain any trainable parameters. DSSS provides compatible tx and rx methods. When defining transmitters and receivers, ensure the corresponding method is passed.

Example
>>> chip_sequence = torch.randint(0, 2, (4,))  # binary sequence of length 4
>>> modem = DSSS(chip_sequence)
>>> env = NullEnvironment()
>>> env.place({"tx": modem.tx}, {"rx": modem.rx})

__init__(chip_sequence, mode='psk', n_symbols=2, demod_type='hard')

Create a new DSSS radio using either phase-shift keying (PSK) or quadrature amplitude modulation (QAM).

Parameters:

Name Type Description Default
chip_sequence Tensor

A binary sequence to spread the input bits with.

required
mode str

Modulation mode. Must be either "psk" or "qam".

'psk'
n_symbols int

Number of symbols to use for modulation. If mode == "psk",n_symbolsmust be a power of 2. Ifmode == "qam",n_symbols` must be a power of 2 and square.

2
demod_type str

"hard" or "soft" decision boundary for bit demodulation.

'hard'

Raises:

Type Description
ValueError

If mode not in ["psk", "qam"].

ValueError

If n_symbols is not a power of 2 or square (square only required for mode == "qam").

ValueError

If demod_type not in ["hard", "soft"].

NotImplementedError

If demod_type == "soft".

rx(signal)

Demodulates and despreads an input signal.

Parameters:

Name Type Description Default
signal Tensor

A 2D complex valued input tensor.

required

Returns:

Type Description
Reception

A Reception dictionary that records the decoded bits using the key "bits".

tx(n_timesteps, batch_size=1)

Encode randomly generated bits with a chip sequence before modulating using commpy.Modem.

Parameters:

Name Type Description Default
n_timesteps int

How many timesteps to transmit for.

required
batch_size int

How many transmissions to create in parallel.

1

Returns:

Type Description
Transmission

A Transmission with a complex-valued signal tensor with shape [n_timesteps, batch_size] and a metadata dictionary that records the transmitted bits using the key "bits".

Modem

Torchradio compatible wrapper for commpy.PSKModem and commpy.QAMModem.

Currently implemented using the third-party commpy library. Note that Modem does not contain any trainable parameters. A Modem provides compatible tx and rx methods. When defining transmitters and receivers, ensure the corresponding method is passed.

Example
>>> modem = Modem("psk", 8)
>>> env = NullEnvironment()
>>> env.place({"tx": modem.tx}, {"rx": modem.rx})

n_input_bits: int property

Get number of bits per symbol.

Returns Number of bits per symbol.

__init__(mode, n_symbols, demod_type='hard')

Create a new Modem using either phase-shift keying (PSK) or quadrature amplitude modulation (QAM).

Parameters:

Name Type Description Default
mode str

Modulation mode. Must be either "psk" or "qam".

required
n_symbols int

Number of symbols to use for modulation. If mode == "psk",n_symbolsmust be a power of 2. Ifmode == "qam",n_symbols` must be a power of 2 and square.

required
demod_type str

"hard" or "soft" decision boundary for bit demodulation.

'hard'

Raises:

Type Description
ValueError

If mode not in ["psk", "qam"].

ValueError

If n_symbols is not a power of 2 or square (square only required for mode == "qam").

ValueError

If demod_type not in ["hard", "soft"].

NotImplementedError

If demod_type == "soft".

rx(signal)

Demodulates an input signal using a prespecified digital demodulation technique.

Parameters:

Name Type Description Default
signal Tensor

A 2D complex valued input tensor.

required

Returns:

Type Description
Reception

A Reception dictionary that records the decoded bits using the key "bits".

tx(n_timesteps, batch_size=1)

Apply digital modulation to randomly generated bits.

Parameters:

Name Type Description Default
n_timesteps int

How many timesteps to transmit for.

required
batch_size int

How many transmissions to create in parallel.

1

Returns:

Type Description
Transmission

A Transmission with a complex-valued signal tensor with shape [n_timesteps, batch_size] and a metadata dictionary that records the transmitted bits using the key "bits".