sdr.plot.magnitude_response(filter: FIR | IIR | ArrayLike | tuple[ArrayLike, ArrayLike], sample_rate: float | None = None, N: int = 1024, ax: plt.Axes | None = None, x_axis: 'auto' | 'one-sided' | 'two-sided' | 'log' = 'auto', y_axis: 'linear' | 'log' = 'log', decades: int = 4, **kwargs)

Plots the magnitude response \(|H(\omega)|^2\) of the filter.

Parameters:
filter: FIR | IIR | ArrayLike | tuple[ArrayLike, ArrayLike]

The filter definition.

  • sdr.FIR, sdr.IIR: The filter object.

  • npt.ArrayLike: The feedforward coefficients \(b_i\).

  • tuple[npt.ArrayLike, npt.ArrayLike]: The feedforward coefficients \(b_i\) and feedback coefficients \(a_j\).

sample_rate: float | None = None

The sample rate \(f_s\) of the signal in samples/s. If None, the x-axis will be labeled as “Normalized frequency”.

N: int = 1024

The number of samples \(N\) in the frequency response.

ax: plt.Axes | None = None

The axis to plot on. If None, the current axis is used.

x_axis: 'auto' | 'one-sided' | 'two-sided' | 'log' = 'auto'

The x-axis scaling. Options are to display a one-sided spectrum, a two-sided spectrum, or one-sided spectrum with a logarithmic frequency axis. The default is "auto" which selects "one-sided" for real-valued filters and "two-sided" for complex-valued filters.

y_axis: 'linear' | 'log' = 'log'

The y-axis scaling. Options are to display a linear or logarithmic magnitude response.

decades: int = 4

The number of decades to plot when x_axis="log".

**kwargs

Additional keyword arguments to pass to matplotlib.pyplot.plot().

Examples

See the FIR filters example.

In [1]: h_srrc = sdr.root_raised_cosine(0.5, 10, 10)

In [2]: plt.figure(); \
   ...: sdr.plot.magnitude_response(h_srrc)
   ...: 
../../_images/sdr_plot_magnitude_response_1.png

See the IIR filters example.

In [3]: zero = 0.6; \
   ...: pole = 0.8 * np.exp(1j * np.pi / 8); \
   ...: iir = sdr.IIR.ZerosPoles([zero], [pole, pole.conj()])
   ...: 

In [4]: plt.figure(); \
   ...: sdr.plot.magnitude_response(iir)
   ...: 
../../_images/sdr_plot_magnitude_response_2.png
In [5]: plt.figure(); \
   ...: sdr.plot.magnitude_response(h_srrc, x_axis="two-sided")
   ...: 
../../_images/sdr_plot_magnitude_response_3.png
In [6]: plt.figure(); \
   ...: sdr.plot.magnitude_response(iir, x_axis="log", decades=3)
   ...: 
../../_images/sdr_plot_magnitude_response_4.png