import pyfar as pf
import matplotlib.pyplot as plt
sweep = pf.signals.exponential_sweep_freq(
    2**16, [50, 16e3], 1000, 10e3)
Inversion = pf.dsp.RegularizedSpectrumInversion.from_frequency_range(
    sweep, [50, 16e3], beta='max')
inverted = Inversion.invert
regularization = Inversion.regularization * Inversion.beta_value
pf.plot.use()
fig, axes = plt.subplots(2,1)
pf.plot.freq(sweep, ax=axes[0], label='sweep')
pf.plot.freq(regularization, ax=axes[0], label='regularization')
axes[0].axvline(50, color='k', linestyle='--',
    label='frequency range')
axes[0].axvline(16e3, color='k', linestyle='--')
axes[0].legend(loc='lower center')
pf.plot.freq(inverted, ax=axes[1], color='p',
    label='inverted with regulariztion')
pf.plot.freq(1 / (sweep+1e-10), ax=axes[1], color='y',
    linestyle=':', label='inverted without regulariztion')
axes[1].axvline(50, color='k', linestyle='--',
    label='frequency range')
axes[1].axvline(16e3, color='k', linestyle='--')
axes[1].set_ylim(-120, -20)
axes[1].legend(loc='lower center')
