Plotter
BasePlot
Base class for plotting graphs, implementing common functionality for all plots.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax
|
Axes
|
Matplotlib |
required |
title
|
str
|
Plot title. |
''
|
labels
|
Optional[List[str]]
|
List of axis labels. |
None
|
xlim
|
Optional[Tuple[float, float]]
|
Limits of the x-axis |
None
|
ylim
|
Optional[Tuple[float, float]]
|
Limits of the y-axis |
None
|
colors
|
Optional[Union[str, List[str]]]
|
Plot colors. |
None
|
style
|
Optional[Dict[str, Any]]
|
Plot style. |
None
|
TimePlot
Bases: BasePlot
Class for plotting signals in the time domain, receiving a time vector \(t\), and a list of signals \(s(t)\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure object |
required |
grid
|
GridSpec
|
GridSpec object |
required |
pos
|
int
|
Plot position |
required |
t
|
ndarray
|
Time vector |
required |
signals
|
Union[ndarray, List[ndarray]]
|
Signal or list of signals \(s(t)\). |
required |
time_unit
|
str
|
Time unit for plotting ("ms" by default, can be "s"). |
'ms'
|
amp_norm
|
bool
|
Signal normalization for maximum amplitude |
False
|
Examples:
- Modulator Time Domain Example:
- AWGN addition Time Domain Example:
FrequencyPlot
Bases: BasePlot
Class for plotting signals in the frequency domain, receiving a sampling frequency \(f_s\) and a signal \(s(t)\) and performing the Fourier transform of the signal, according to the expression below.
Where
- \(S(f)\): Signal in the frequency domain.
- \(s(t)\): Signal in the time domain.
- \(\mathcal{F}\): Fourier transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure object |
required |
grid
|
GridSpec
|
GridSpec object |
required |
pos
|
int
|
Plot position |
required |
fs
|
float
|
Sampling frequency |
required |
signal
|
ndarray
|
Signal to be plotted |
required |
fc
|
float
|
Central frequency |
0.0
|
Examples:
- Modulator Frequency Domain Example:
- AWGN addition Frequency Domain Example:
ConstellationPlot
Bases: BasePlot
Class for plotting signals in the constellation domain, receiving the signals \(d_I\) and \(d_Q\), performing the plot in phase \(I\) and quadrature \(Q\), according to the expression below.
Where
- \(s(t)\): Complex signal.
- \(d_I(t)\): In-phase signal.
- \(d_Q(t)\): Quadrature signal.
The constellation plot can be normalized by a normalization factor given by:
Where
- \(\text{A}\): Desired amplitude, defined as
1
. - \(\varphi\): Normalization factor.
- \(N\): Number of samples.
- \(I(n)\) and \(Q(n)\): In-phase and quadrature signals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure object |
required |
grid
|
GridSpec
|
GridSpec object |
required |
pos
|
int
|
Plot position |
required |
dI
|
ndarray
|
In-phase signal |
required |
dQ
|
ndarray
|
Quadrature signal |
required |
Examples:
- Modulator Constellation/Phase Example:
BitsPlot
Bases: BasePlot
Class for plotting bits, receiving a list of bits \(b_t\) and performing the plot in function of time \(t\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure object |
required |
grid
|
GridSpec
|
GridSpec object |
required |
pos
|
int
|
Plot position |
required |
bits_list
|
List[ndarray]
|
List of bits |
required |
sections
|
Optional[List[Tuple[str, int]]]
|
Plot sections |
None
|
colors
|
Optional[List[str]]
|
Plot colors |
None
|
show_bit_values
|
bool
|
If |
True
|
xlabel
|
Optional[str]
|
X-axis label. |
None
|
ylabel
|
Optional[str]
|
Y-axis label. |
None
|
label
|
Optional[str]
|
Label of the plot. |
None
|
xlim
|
Optional[Tuple[float, float]]
|
X-axis limits. |
None
|
Examples:
- Datagram Bitstream Example:
- Convolutional Bitstream Example:
- Scrambler Bitstream Example:
SymbolsPlot
Bases: BasePlot
Class for plotting symbols encoded with line coding, receiving a vector of symbols \(s[i]\) and performing the plot in function of the symbol index \(i\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int
|
Position of the plot |
required |
symbols_list
|
List[ndarray]
|
List of symbols |
required |
samples_per_symbol
|
int
|
Number of samples per symbol |
1
|
sections
|
Optional[List[Tuple[str, int]]]
|
Plot sections |
None
|
colors
|
Optional[List[str]]
|
Plot colors |
None
|
show_symbol_values
|
bool
|
If |
True
|
xlabel
|
Optional[str]
|
X-axis label. |
None
|
ylabel
|
Optional[str]
|
Y-axis label. |
None
|
label
|
Optional[str]
|
Plot label. |
None
|
xlim
|
Optional[Tuple[float, float]]
|
X-axis limits. |
None
|
Examples:
- Symbols Plot Example:
ImpulseResponsePlot
Bases: BasePlot
Class for plotting the impulse response of a filter, receiving a vector of time \(t_{imp}\) and performing the plot in function of time \(t\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int
|
Position of the plot in the GridSpec |
required |
t_imp
|
ndarray
|
Vector of time \(t_{imp}\) |
required |
impulse_response
|
ndarray
|
Impulse response |
required |
t_unit
|
str
|
Unit of time on the x-axis ("ms" or "s"). Default is "ms" |
'ms'
|
label
|
Optional[Union[str, List[str]]]
|
Plot label |
None
|
xlabel
|
Optional[str]
|
x-axis label |
None
|
ylabel
|
Optional[str]
|
y-axis label |
None
|
xlim
|
Optional[Tuple[float, float]]
|
x-axis limits |
None
|
amp_norm
|
Optional[bool]
|
Normalizes the impulse response to have unitary amplitude. |
False
|
Examples:
- Impulse Response RRC:
- Impulse Response Manchester:
- Impulse Response LPF:
SampledSignalPlot
Bases: BasePlot
Class to plot a sampled signal \(s(t)\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int ou tuple
|
Position in the GridSpec |
required |
t_signal
|
ndarray
|
Vector of time \(t_{signal}\) |
required |
signal
|
ndarray
|
Filtered signal |
required |
t_samples
|
ndarray
|
Vector of time \(t_{samples}\) |
required |
samples
|
ndarray
|
Samples |
required |
time_unit
|
str
|
Time unit. |
'ms'
|
label_signal
|
str
|
Label of the filtered signal. |
None
|
label_samples
|
str
|
Label of the samples. |
None
|
xlabel
|
str
|
Label of the x-axis. |
None
|
ylabel
|
str
|
Label of the y-axis. |
'Amplitude'
|
title
|
str
|
Title of the plot. |
None
|
xlim
|
tuple
|
Limits of the x-axis. |
None
|
Examples:
- Time Domain Plot Example:
PhasePlot
Bases: BasePlot
Class to plot the phase of the signals \(d_I(t)\) and \(d_Q(t)\) in the time domain.
Where
- \(s(t)\): Phase vector \(s(t)\).
- \(d_I(t)\): In-phase signal component \(d_I(t)\).
- \(d_Q(t)\): Quadrature signal component \(d_Q(t)\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int
|
Position of the plot |
required |
t
|
ndarray
|
Vector of time |
required |
signals
|
Union[ndarray, List[ndarray]]
|
IQ signals (I and Q) |
required |
time_unit
|
str
|
Time unit for plot ("ms" by default, can be "s"). |
'ms'
|
Examples:
- Modulator Constellation/Phase Example:
GaussianNoisePlot
Bases: BasePlot
Class to plot the probability density \(p(x)\) of a given variance \(\sigma^2\), following the expression below.
Where
- \(p(x)\): Probability density of the noise.
- \(\sigma^2\): Variance of the noise.
- \(x\): Amplitude of the noise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int
|
Position of the plot in the GridSpec |
required |
variance
|
float
|
Variance of the noise |
required |
num_points
|
int
|
Number of points for the gaussian curve |
5000
|
legend
|
str
|
Legend of the plot |
'$p(x)$'
|
xlabel
|
str
|
Label of the x-axis |
'Amplitude ($x$)'
|
ylabel
|
str
|
Label of the y-axis |
'Probability Density $p(x)$'
|
xlim
|
Optional[Tuple[float, float]]
|
Limit of the x-axis |
required |
span
|
int
|
Span of the plot |
100
|
Examples:
- Noise Density Plot Example:
PoleZeroPlot
Bases: BasePlot
Plot the diagram of poles and zeros of a discrete transfer function in the z-plane.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int
|
Position in the GridSpec |
required |
b
|
ndarray
|
Coefficients of the numerator of the transfer function |
required |
a
|
ndarray
|
Coefficients of the denominator of the transfer function |
required |
Examples:
- Pole-Zero Diagram Example:
FrequencyResponsePlot
Bases: BasePlot
Plot the frequency response of a filter from its coefficients (b, a).
Calculates the Discrete Fourier Transform of the impulse response using scipy.signal.freqz
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int
|
Position in the GridSpec |
required |
b
|
ndarray
|
Coefficients of the numerator of the filter |
required |
a
|
ndarray
|
Coefficients of the denominator of the filter |
required |
fs
|
float
|
Sampling frequency |
required |
f_cut
|
Optional[float]
|
Cut-off frequency of the filter (Hz) |
None
|
xlim
|
Optional[Tuple[float, float]]
|
Limit of the x-axis (Hz) |
None
|
worN
|
int
|
Number of points for the Discrete Fourier Transform |
1024
|
show_phase
|
bool
|
If |
False
|
xlabel
|
str
|
Label of the x-axis |
'Frequency ($Hz$)'
|
ylabel
|
str
|
Label of the y-axis |
'Magnitude ($dB$)'
|
Examples:
- Frequency Domain Plot Example:
DetectionFrequencyPlot
Bases: BasePlot
Plot the spectrum of a received signal, with threshold and detected frequencies. Receiving a sampling frequency \(f_s\) and a signal \(s(t)\) and performing the Fourier transform of the signal, according to the expression below.
Where
- \(S(f)\): Signal in the frequency domain.
- \(s(t)\): Signal in the time domain.
- \(\mathcal{F}\): Fourier transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int
|
Position of the plot |
required |
fs
|
float
|
Sampling frequency |
required |
signal
|
ndarray
|
Signal to be plotted |
required |
threshold
|
float
|
Threshold of the signal |
required |
fc
|
float
|
Central frequency |
0.0
|
Examples:
- Frequency Domain Plot Example:
BersnrPlot
Bases: BasePlot
Plot BER curves as a function of Eb/N0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int
|
Position in the GridSpec |
required |
EbN0
|
ndarray
|
Array of Eb/N0 values (dB) |
required |
ber_curves
|
List[ndarray]
|
List of BER curves |
required |
labels
|
List[str]
|
Labels of each curve |
required |
linestyles
|
List[str]
|
List of line styles |
None
|
markers
|
List[str]
|
List of marker styles |
None
|
xlabel
|
str
|
Label of the x-axis |
'$E_b/N_0$ ($dB$)'
|
ylabel
|
str
|
Label of the y-axis |
'Bit Error Rate ($BER$)'
|
logy
|
bool
|
Whether to use a log scale for the y-axis |
True
|
Examples:
- BER vs Eb/N0 Plot Example:
SincronizationPlot
Bases: BasePlot
Plot a signal in the time domain with synchronization marks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int ou tuple
|
Position in the GridSpec |
required |
t
|
ndarray
|
Array of time |
required |
signal
|
ndarray
|
Signal in the time domain |
required |
sync_start
|
float
|
Start time of the synchronization word |
required |
sync_end
|
float
|
End time of the synchronization word |
required |
max_corr
|
float
|
Time of the peak of correlation |
required |
time_unit
|
str
|
Time unit for plotting ("ms" by default, can be "s"). |
'ms'
|
Examples:
- Time Domain Synchronization Plot Example:
CorrelationPlot
Bases: BasePlot
Plot correlation vector \(c[k]\) as a function of the index \(k\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int ou tuple
|
Position in the GridSpec |
required |
corr_vec
|
ndarray
|
Correlation vector \(c[k]\) |
required |
fs
|
float
|
Signal sampling rate in \(Hz\) |
required |
xlim
|
Tuple[float, float]
|
Time limits in \(ms\) |
required |
Examples:
- Correlation Plot Example:
WaterfallPlot
Bases: BasePlot
Waterfall plot of the power matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int ou tuple
|
Position in the GridSpec |
required |
power_matrix
|
ndarray
|
Power matrix |
required |
fs
|
float
|
Signal sampling rate in \(Hz\) |
required |
N
|
int
|
Number of samples |
required |
xlim
|
Tuple[float, float]
|
Time limits in \(ms\) |
(0, 10)
|
Examples:
- Waterfall Plot Example:
Waterfall3DPlot
Bases: BasePlot
3D waterfall plot of the power matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int ou tuple
|
Position in the GridSpec |
required |
power_matrix
|
ndarray
|
Power matrix |
required |
fs
|
float
|
Signal sampling rate in \(Hz\) |
required |
N
|
int
|
Number of samples |
required |
freq_window
|
tuple[float, float]
|
Frequency limits in \(kHz\) |
(0, 10)
|
threshold
|
float
|
Threshold value |
None
|
smooth
|
bool
|
Whether to smooth the power matrix |
True
|
sigma
|
float
|
Standard deviation for the Gaussian filter |
1.0
|
elev
|
float
|
Elevation angle in degrees |
5.0
|
azim
|
float
|
Azimuth angle in degrees |
-60.0
|
Examples:
- Waterfall 3D Plot Example:
WaterfallDecisionPlot
Bases: BasePlot
Decision waterfall plot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure of the plot |
required |
grid
|
GridSpec
|
GridSpec of the plot |
required |
pos
|
int ou tuple
|
Position in the GridSpec |
required |
matrix
|
ndarray
|
Decision matrix |
required |
fs
|
float
|
Signal sampling rate in \(Hz\) |
required |
N
|
int
|
Number of samples |
required |
xlim
|
Tuple[float, float]
|
Time limits in \(ms\) |
(0, 10)
|
legend_list
|
List[str]
|
List of legend labels |
None
|
Examples:
- Waterfall Detection Plot Example:
- Waterfall Decision Plot Example:
mag2db(signal)
Converts the signal magnitude to a logarithmic scale (\(dB\)). The conversion process is given by the expression below.
Where
- \(x\): Signal to be converted to \(dB\).
- \(x_{peak}\): Peak magnitude of the signal.
- \(10^{-12}\): Constant to avoid division by zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signal
|
ndarray
|
Array with signal data |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Array with signal converted to \(dB\) |
create_figure(rows, cols, figsize=(16, 9))
Creates a figure with GridSpec
, returning the fig
and grid
objects for plotting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rows
|
int
|
Number of rows in the GridSpec |
required |
cols
|
int
|
Number of columns in the GridSpec |
required |
figsize
|
Tuple[int, int]
|
Figure size |
(16, 9)
|
Returns:
Type | Description |
---|---|
Tuple[Figure, GridSpec]
|
Tuple[plt.Figure, gridspec.GridSpec]: Tuple with the figure and GridSpec objects |
save_figure(fig, filename, out_dir='../../out')
Saves the figure in <out_dir>/<filename>
from the script root directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Matplotlib |
required |
filename
|
str
|
Output file name |
required |
out_dir
|
str
|
Output directory |
'../../out'
|
Raises:
Type | Description |
---|---|
ValueError
|
If the output directory is invalid |