Plot Utilities
Customized functions for plotting and vizualization (optic.plot
)
|
Plot signal constellations. |
|
Generate histogram-based constellation plot. |
|
Colored constellation scatter plot. |
|
Plot decision boundaries for a given constellation symbols. |
|
Plot the eye diagram of a modulated signal waveform. |
|
Plot the power spectrum density (PSD) of a signal. |
|
Generate a random colormap with the specified number of colors and random RGB values. |
- animateConstGIF(x, figName, xlabel='In-Phase (I)', ylabel='Quadrature (Q)', title=[], color='b', centralAxes=False, squareAxes=True, fram=200, inter=20, radius=2)
Create and save a constellation plot animation as GIF
- Parameters:
x (numpy.ndarray) – x-axis values.
figName (str) – Figure file name with folder path.
xlabel (str, optional) – X-axis label. Default is ‘In-Phase (I)’.
ylabel (str, optional) – Y-axis label. Default is ‘Quadrature (Q)’.
title (str, optional) – Title of the plot.
color (str, optional) – Color of the points in the plot. Default is ‘b’ (blue).
centralAxes (bool, optional) – Whether to place the axes at the center. Default is False.
squareAxes (bool, optional) – Whether to keep the axes square. Default is True.
fram (int, optional) – Number of frames. Default is 200.
inter (int, optional) – Time interval between frames in milliseconds. Default is 20.
radius (int, optional) – Radius for setting plot limits. Default is 2.
- constHist(symb, ax, cmap='turbo', whiteb=True)
Generate histogram-based constellation plot.
- Parameters:
symb (np.array) – Complex-valued constellation symbols.
ax (axis object handle) – axis of the plot.
- Returns:
ax – axis of the plot.
- Return type:
axis object handle
- eyediagram(sigIn, Nsamples, SpS, n=3, ptype='fast', plotlabel=None)
Plot the eye diagram of a modulated signal waveform.
- Parameters:
sigIn (array-like) – Input signal waveform.
Nsamples (int) – Number of samples to be plotted.
SpS (int) – Samples per symbol.
n (int, optional) – Number of symbol periods. Defaults to 3.
ptype (str, optional) – Type of eye diagram. Can be ‘fast’ or ‘fancy’. Defaults to ‘fast’.
plotlabel (str, optional) – Label for the plot legend. Defaults to None.
- Return type:
None
- pconst(x, lim=True, R=1.25, pType='fancy', cmap='turbo', whiteb=True)
Plot signal constellations.
- Parameters:
x (complex signals or list of complex signals) – Input signals.
lim (bool, optional) – Flag indicating whether to limit the axes to the radius of the signal. Defaults to True.
R (float, optional) – Scaling factor for the radius of the signal. Defaults to 1.25.
pType (str, optional) – Type of plot. “fancy” for scatter_density plot, “fast” for fast plot. Defaults to “fancy”.
cmap (str, optional) – Color map for scatter_density plot. Defaults to “turbo”.
whiteb (bool, optional) – Flag indicating whether to use white background for scatter_density plot. Defaults to True.
- Returns:
fig (Figure) – Figure object.
ax (Axes or array of Axes) – Axes object(s).
- plotColoredConst(symb, constSymb, px=None, SNR=20, rule='MAP', cmap=<matplotlib.colors.ListedColormap object>, fig=None, ax=None)
Colored constellation scatter plot.
- Parameters:
symb (np.array) – Complex-valued constellation symbols.
constSymb (np.array) – Complex-valued constellation symbols used for detection.
px (array_like, optional) – Prior probabilities of symbols.
SNR (float, optional) – Signal-to-Noise Ratio (SNR) in decibels (dB). Default is 20 dB.
rule (str, optional) – Detection rule, either “MAP” for Maximum A Posteriori or “ML” for Maximum Likelihood. Default is “MAP”.
cmap (matplotlib.colors.Colormap, optional) – Colormap for coloring the constellation symbols. Default is matplotlib.cm.turbo.
fig (matplotlib.figure.Figure, optional) – Figure object for the plot. If None, a new figure is created. Default is None.
ax (matplotlib.axes.Axes, optional) – Axes object for the plot. If None, a new axes is created. Default is None.
- Returns:
fig (matplotlib.figure.Figure) – Figure object for the plot.
ax (matplotlib.axes.Axes) – Axes object for the plot.
Notes
This function generates a scatter plot of complex-valued constellation symbols with colors representing the corresponding decided constellation symbols based on detection results.
The detected symbols are determined using a detector based on the provided input symbols, noise variance, detection rule, and prior probabilities (if available).
- plotDecisionBoundaries(constSymb, px=None, SNR=20, rule='MAP', gridStep=0.001, d=0.5, cmap=<matplotlib.colors.ListedColormap object>, fig=None, ax=None)
Plot decision boundaries for a given constellation symbols.
- Parameters:
constSymb (array_like) – An array of complex constellation symbols.
px (array_like, optional) – Prior probabilities for each symbol in constSymb. If None, equal probabilities are assumed.
SNR (float, optional) – Signal-to-noise ratio in decibels (dB). Default is 20.
rule (str, optional) – The detection rule to use. Either ‘MAP’ (default) or ‘ML’.
gridStep (float, optional) – Step size for creating the decision boundary grid. Default is 0.001.
d (float, optional) – Margin added to the maximum and minimum values of real and imaginary parts of constSymb. Default is 0.5.
cmap (str or Colormap, optional) – Colormap to be used for the contour plot. Default is ‘turbo’.
fig (matplotlib.figure.Figure, optional) – Figure object for the plot. If None, a new figure is created. Default is None.
ax (matplotlib.axes.Axes, optional) – Axes object for the plot. If None, a new axes is created. Default is None.
- Returns:
fig (matplotlib.figure.Figure) – The created matplotlib figure.
ax (matplotlib.axes.Axes) – The created matplotlib axes.
Notes
This function plots decision boundaries for a given set of constellation symbols in the complex plane. It uses the specified signal-to-noise ratio (SNR), detection rule, and prior probabilities (if available) to determine the decision boundaries.
The decision boundaries are plotted using a contour plot with colors representing the different decision regions.
- plotPSD(sig, Fs=1, Fc=0, NFFT=4096, fig=None, label=None)
Plot the power spectrum density (PSD) of a signal.
- Parameters:
sig (np.array) – input signal.
Fs (scalar, optional) – signal’s sampling frequency. The default is 1.
Fc (scalar, optional) – signal’s central frequency. The default is 0.
NFFT (scalar int, optional) – FFT size. The default is 4096.
fig (figure object, optional) – matplotlib figure handle. The default is [].
label (string, optional) – PSD plot label. The default is [].
- Returns:
fig (matplotlib figure object) – matplotlib figure object where the plot is generated.
matplotlib axes object – matplotlib axes object where the plot is displayed.
- randomCmap(nColors=100, low=0.1, high=0.99)
Generate a random colormap with the specified number of colors and random RGB values.
- Parameters:
nColors (int, optional) – Number of colors in the colormap. Defaults to 100.
low (float, optional) – Lower bound for random RGB values. Defaults to 0.1.
high (float, optional) – Upper bound for random RGB values. Defaults to 0.99.
- Returns:
Random colormap with the specified number of colors and random RGB values.
- Return type:
matplotlib.colors.ListedColormap