Skip to content

Instantly share code, notes, and snippets.

@ChrisLane
Created March 4, 2018 17:08
Show Gist options
  • Save ChrisLane/177616d814ae9cce61c626c03e08339d to your computer and use it in GitHub Desktop.
Save ChrisLane/177616d814ae9cce61c626c03e08339d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import matplotlib as mp
import matplotlib.pyplot as plt
import numpy as np
import sys
import peakutils as pu
from scipy import signal
# Read trace input file
c = np.fromfile(sys.argv[1], np.int8)
# Calculate mean
y_mean = [np.mean(c)]*len(c)
# Remove annoying first spike
c_trim = c[np.argmax(c > y_mean):]
# Get local minima
#wut = pu.indexes(c_trim, thres=0.9, min_dist=1000)
#wut = np.asarray(map(lambda i: c_trim[i], wut))
wut = signal.argrelmax(c_trim)
print(wut)
# Get local maxima
# Plot graph
fig,graph = plt.subplots()
data_line = graph.plot(c_trim, label='Trace Data')
mean_line = graph.plot(y_mean, label='Mean', linestyle='--')
wut_line = graph.plot(wut, label='Wut', linestyle='--', color='red')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment