import pyfar as pf
import numpy as np
import matplotlib.pyplot as plt
GFB = pf.dsp.filter.GammatoneBands([0, 22050])
x = pf.signals.impulse(2**13)
real, imag = GFB.process(x)
env = pf.Signal(np.abs(real.time + 1j * imag.time), 44100)
pf.plot.use()
plt.figure()
ax = pf.plot.time(real[2], label='real part', unit='ms')
pf.plot.time(imag[2], label='imaginary part', unit='ms')
pf.plot.time(env[2], label='envelope', unit='ms')
plt.legend()
plt.figure()
ax = pf.plot.freq(real)
ax.set_ylim(-40, 5)
y = GFB.reconstruct(real, imag)
plt.figure()
ax = pf.plot.time_freq(y, label="reconstructed impulse", unit='ms')
ax[0].set_xlim(0, 20)
ax[1].set_ylim(-40, 5)
ax[0].legend()
real.time[20:25] *= .5
imag.time[20:25] *= .5
y = GFB.reconstruct(real, imag)
plt.figure()
ax = pf.plot.time_freq(
    y, unit='ms',
    label="manipulated and reconstructed and impulse")
ax[0].set_xlim(0, 20)
ax[1].set_ylim(-40, 5)
ax[0].legend()
