Utilities#

get_standard_carrier_allocation(config_name: str, os: int = 1, custom: Sequence[Any] | None = None, shift: bool = False) → ndarray[source]#

Allocate subcarriers based on a specified OFDM configuration.

Deprecated since version 1.0: Use comnumpy.ofdm.allocation.get_allocation(), which returns a CarrierAllocation object carrying its metadata and self-checked against the standard’s tables.

This function generates a subcarrier allocation array based on the given configuration name or custom parameters. It supports various OFDM configurations and allows for oversampling, Hermitian symmetry, and optional shifting.

Parameters:
  • config_name (str) – The name of the OFDM configuration to use. If “Custom”, the custom parameter must be provided.

  • os (int, optional) – Oversampling factor. Default is 1 (no oversampling).

  • custom (list, optional) – Custom configuration parameters in the form [N, N_nulled_DC, N_nulled_left, N_nulled_right, pilot_index]. Required if config_name is “Custom”.

  • shift (bool, optional) – If False, apply FFT shift to the subcarrier allocation. Default is False.

Returns:

np.ndarray – An array representing the subcarrier allocation, where: - 0 indicates a nulled subcarrier, - 1 indicates a data subcarrier, - 2 indicates a pilot subcarrier, - -1 indicates Hermitian symmetry (if applicable).

Notes

  • The function supports predefined configurations for various OFDM standards.

  • Hermitian symmetry, when applied, affects the allocation of data subcarriers.

  • Oversampling adds nulled subcarriers to the array.

plot_carrier_allocation(carrier_type: np.ndarray, ax: 'Axes' | None = None, color_list: List[str] | None = None, label_list: List[str] | None = None, shift: bool = False, title: str = 'Carrier allocation') → Axes[source]#

Plot the allocation of subcarriers based on their types.

This function visualizes the allocation of subcarriers in a carrier type array. It uses different colors and markers to represent different subcarrier types, such as Hermitian, null, data, and pilots. The plot can be shifted and customized with various parameters.

Parameters:
  • carrier_type (np.ndarray) – An array representing the type of each subcarrier. The values in the array correspond to different subcarrier types: - 0: Null subcarrier - 1: Data subcarrier - 2: Pilot subcarrier

  • ax (matplotlib.axes.Axes or None, optional) – Axis to draw on. If None, a new figure and axis are created.

  • color_list (list of str, optional) – Colors indexed by subcarrier type value. Defaults to the frozen CARRIER_STYLE palette of decision D27 (Okabe-Ito, safe for colour-vision deficiency), the same one the ASCII spectral map and CarrierAllocation.plot() use.

  • label_list (list of str, optional) – Legend labels indexed by subcarrier type value. Defaults to the CARRIER_STYLE labels.

  • shift (bool, optional) – If True, shift the x-axis by half the length of the carrier_type array. Default is False.

  • title (str, optional) – The title of the plot. Default is “Carrier allocation”.

Returns:

matplotlib.axes.Axes – The axis containing the plot (decision D25).

Notes

  • The function uses matplotlib.pyplot to create the plot.

  • The stem plot is used to visualize the subcarrier types with vertical lines and markers.

  • Ensure that color_list and label_list have the correct length and order corresponding to the subcarrier types.

Examples

>>> import matplotlib
>>> matplotlib.use("Agg")
>>> carrier_type = np.array([1, 1, 0, 2, 1, 0, 0])
>>> ax = plot_carrier_allocation(carrier_type)
>>> ax.get_xlabel()
'subcarrier index'