Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
line_autocorrelation()
def line_autocorrelation(compamp, width):
framelen = compamp.shape[0]
# zero mean, does influence a minority of lines in some plots
arr = compamp - compamp.mean()
# Hanning window for smoothing sharp time series start/end in freq. dom.
arr = np.multiply(arr, np.hanning(framelen))
# FFT all blocks separately and arrange correctly
arr = fft.fftshift(fft.fft(arr, 2 * framelen))
arr = np.square(np.abs(arr)) # FFT(AC(x)) = FFT(x)FFT*(x) = abs(x)^2
arr = fft.ifftshift(fft.ifft(arr)) # AC(x) = iFFT(abs(x)^2) and arrange correctly
arr = np.abs(arr[framelen:framelen*3/2]) # magnitude of AC
arr = arr.reshape(width, arr.shape[0]/width).max(axis=(1)) # maxpool to width
# log to reduce darkening on sides of spectrum, due to AC triangling
arr = np.log(arr + 0.000001)
arr[0] = 0 # set zero-delay to 0
arr -= arr.mean()
arr /= 5*arr.std()
arr += 0.6
arr = np.clip(arr * 255., 0, 255)
return arr.astype(np.uint8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment