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_subcarriersactive subcarriers centred on the carrier, out of a grid ofn_fft; the IFFT hasoversampling · n_fftpoints (4 by default, as the PAPR measurements need), and the samples have unit average power. Withdft_spread, the data are first spread by a unitary DFT (localised SC-FDMA).- Parameters:
- 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:
Kwithout a technique, fewer with tone reservation.- Return type:
- demodulate(samples)#
Demodulate whole blocks.
- Parameters:
samples (array_like) – a multiple of
block_lensamples.- Returns:
the data symbols, block after block (complex128).
- Return type:
- 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_lensamples.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:
- 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, asResourceGrid.mapgives it).- Returns:
the samples (complex128).
- Return type:
- 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:
- 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_lensamples.- Returns:
the PAPR of every block (dB).
- Return type:
- 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
rampsamples of every prefix rise as a half cosine, a cyclic postfix oframpsamples 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_lensamples.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:
- 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: