comnum.Ofdm#

class comnum.Ofdm(n_fft, n_subcarriers, *, oversampling=4, n_cp=0, dc_null=False, dft_spread=False)#

An OFDM (or DFT-spread OFDM) modulator and demodulator.

n_subcarriers active subcarriers centred on the carrier, out of a grid of n_fft; the IFFT has oversampling · n_fft points (4 by default, as the PAPR measurements need), and the samples have unit average power. With dft_spread, the data are first spread by a unitary DFT (localised SC-FDMA).

Parameters:
  • n_fft (int) – grid size N.

  • n_subcarriers (int) – active subcarriers K ≤ N (the name of the ofdm_tx block).

  • oversampling (int) – L.

  • n_cp (int) – cyclic prefix, in Nyquist-rate samples.

  • dc_null (bool) – leave the DC subcarrier empty.

  • dft_spread (bool) – DFT-spread OFDM.

Raises:

ValueError – for an invalid parameter (the message names it).

Examples

>>> import comnum, numpy as np
>>> ofdm = comnum.Ofdm(64, 48, n_cp=8)
>>> ofdm.n_subcarriers, ofdm.bins.shape
(48, (48,))
>>> d = np.exp(2j * np.pi * np.arange(96) / 7)
>>> np.allclose(ofdm.demodulate(ofdm.modulate(d)), d)
True
data_len(reduction=None)#

Data symbols per block with a reduction technique.

Parameters:

reduction (PaprReduction, optional) – the technique.

Returns:

K without a technique, fewer with tone reservation.

Return type:

int

demodulate(samples)#

Demodulate whole blocks.

Parameters:

samples (array_like) – a multiple of block_len samples.

Returns:

the data symbols, block after block (complex128).

Return type:

numpy.ndarray

Raises:

ValueError – for an invalid parameter or input (the message names it).

demodulate_with(samples, reduction=None, *, side=None)#

Demodulate whole blocks sent with a PAPR reduction technique.

Parameters:
  • samples (array_like) – a multiple of block_len samples.

  • reduction (PaprReduction, optional) – the technique of the transmitter (the expansion of companding is applied).

  • side (array_like, optional) – the side information of SLM and PTS.

Returns:

the data symbols, block after block (complex128).

Return type:

numpy.ndarray

Raises:

ValueError – for an invalid parameter or input (the message names it).

modulate(data)#

Modulate data symbols (whole blocks).

Parameters:

data (array_like) – a multiple of data_len() data symbols, block after block, or a grid (data_len(), n_blocks) (a column per block, as ResourceGrid.map gives it).

Returns:

the samples (complex128).

Return type:

numpy.ndarray

Raises:

ValueError – for an invalid parameter or input (the message names it).

modulate_with(data, reduction)#

Modulate data symbols (whole blocks) with a PAPR reduction technique.

Parameters:
  • data (array_like) – a multiple of data_len(reduction) data symbols, or a grid (data_len(reduction), n_blocks).

  • reduction (PaprReduction) – the technique.

Returns:

the samples (complex128) and the side information of every block (the SLM or PTS candidate, int64).

Return type:

tuple[numpy.ndarray, numpy.ndarray]

Raises:

ValueError – for an invalid parameter or input (the message names it).

papr_db(samples)#

The PAPR of every block (the prefix is excluded).

Parameters:

samples (array_like) – a multiple of block_len samples.

Returns:

the PAPR of every block (dB).

Return type:

numpy.ndarray

Raises:

ValueError – for an input that is not an array of numbers of the expected shape.

windowed(samples, ramp)#

The raised-cosine window of whole blocks (prefix included): the first ramp samples of every prefix rise as a half cosine, a cyclic postfix of ramp samples falls and overlaps the ramp of the next block (the last wraps onto the first), so the output has the length of the input and the FFT part of every block is untouched: the raised-cosine impulse shape of windowed OFDM (Saul, VTC2004-Fall, eq. (1)).

Parameters:
  • samples (array_like) – whole blocks of block_len samples.

  • ramp (int) – the length of the ramps, at most the prefix oversampling * n_cp.

Returns:

the windowed samples (complex128), as many as samples.

Return type:

numpy.ndarray

Raises:

ValueError – for a ramp longer than the prefix or a partial block.

bins#

FFT bins of the active subcarriers (int64), for the channel frequency responses (ChannelTaps.frequency_response).

Type:

numpy.ndarray

block_len#

Samples per block, prefix included.

Type:

int

fft_len#

Samples of the useful part of a block, L N.

Type:

int

n_cp#

Cyclic prefix (Nyquist-rate samples).

Type:

int

n_fft#

Grid size N.

Type:

int

n_subcarriers#

Active subcarriers K.

Type:

int

oversampling#

Oversampling factor L.

Type:

int