Skip to content

Instantly share code, notes, and snippets.

@francoisluus
Created January 25, 2018 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francoisluus/8c35bd16c13e44f3f56a4b653f005e6f to your computer and use it in GitHub Desktop.
Save francoisluus/8c35bd16c13e44f3f56a4b653f005e6f to your computer and use it in GitHub Desktop.
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