import pyfar as pf
import numpy as np
import matplotlib.pyplot as plt
sweep = pf.signals.linear_perfect_sweep(2**8)
auto_correlation = np.empty(2**8)
for idx, shift in enumerate(range(-2**7, 2**7)):
    auto_correlation[idx] = np.dot(
        sweep.time.flatten(),
        np.roll(sweep.time.flatten(), shift))
auto_correlation /= pf.dsp.energy(sweep)
with pf.plot.context():
    plt.plot(np.arange(-2**7, 2**7), auto_correlation)
    plt.gca().set_xlim(-2**7, 2**7)
    plt.gca().set_xlabel('time lag in samples')
    plt.gca().set_ylabel('auto correlation')
