freqz frequency unit format example#

This example illustrates the effect of the freq_units argument of freqz() and related methods.

Here, freqz_fir() is used as we deal with an FIR filter.

import matplotlib.pyplot as plt
from mplsignal.freq_plots import freqz_fir
from mplsignal.ticker import PiRationalFormatter
from scipy.signal import remez

fig, ax = plt.subplots(5, 1, figsize=(6.4, 13), layout='compressed')

h = remez(31, [0, 0.2, 0.25, 0.5], [1, 0])

for i, freq_unit in enumerate(('rad', 'deg', 'norm', 'fs', 'normfs')):
    freqz_fir(h, freq_unit=freq_unit, style='magnitude', ax=ax[i], fs=1000)
    ax[i].set_title(f"freq_unit={freq_unit!r}")

fig.show()
freq_unit='rad', freq_unit='deg', freq_unit='norm', freq_unit='fs', freq_unit='normfs'

It is also possible to get rational multiples of \(\pi\) by using PiRationalFormatter as formatter. In the phase plot, pi_always_in_numerator is set to False to illustrate the difference.

fig, ax = plt.subplots(2, 1, layout='compressed')
freqz_fir(h, ax=ax)
ax[0].xaxis.set_major_formatter(PiRationalFormatter())
ax[1].xaxis.set_major_formatter(PiRationalFormatter(pi_always_in_numerator=False))

fig.show()
freqz frequency units

Total running time of the script: (0 minutes 1.262 seconds)

Gallery generated by Sphinx-Gallery