sdr.plot.filter(filter: FIR | IIR | ArrayLike | tuple[ArrayLike, ArrayLike], sample_rate: float | None = None, N_time: int | None = None, N_freq: int = 1024, x_axis: 'one-sided' | 'two-sided' | 'log' = 'two-sided', decades: int = 4)

Plots the magnitude response \(|H(\omega)|^2\), impulse response \(h[n]\), and zeros and poles 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_time: int | None = None

The number of samples \(N_t\) in the time domain. If None, the length of b is used for FIR filters and 100 for IIR filters.

N_freq: int = 1024

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

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

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.

decades: int = 4

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

Examples

See the FIR filters example.

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

In [2]: plt.figure(figsize=(8, 6)); \
   ...: sdr.plot.filter(h_srrc)
   ...: 
../../_images/sdr_plot_filter_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(figsize=(8, 6)); \
   ...: sdr.plot.filter(iir, N_time=30)
   ...: 
../../_images/sdr_plot_filter_2.png