Commit 84d931fb3d85d2a8df0488a1b3074753b53db527
1 parent
98e71dda5c
Exists in
master
.
Showing 1 changed file with 45 additions and 0 deletions Inline Diff
ringdown.py
File was created | 1 | import matplotlib.pyplot as plt | ||
2 | import numpy as np | |||
3 | import csv, glob, sys | |||
4 | from scipy.optimize import curve_fit | |||
5 | ||||
6 | list_files = (glob.glob(sys.argv[1])) | |||
7 | ||||
8 | data = [] | |||
9 | ||||
10 | for f in list_files: | |||
11 | data_iter = csv.reader(open(f, 'r'), delimiter = ',', quotechar = '"') | |||
12 | for i in range(2): | |||
13 | data_iter.next() | |||
14 | #temp_data = [value for value in data_iter] #if ends with a number | |||
15 | temp_data = [value[:-1] for value in data_iter]#if ends with a comma | |||
16 | data.extend(temp_data) | |||
17 | ||||
18 | data = np.asarray(data, dtype = float) | |||
19 | ||||
20 | del(temp_data, list_files, value, f) | |||
21 | ||||
22 | plt.subplot(111) | |||
23 | plt.clf() | |||
24 | ||||
25 | plt.plot(data[data[:,0]>=0,0], data[data[:,0]>=0,1], label ='mes') | |||
26 | ||||
27 | def func(t, tau, A, w , a, b): | |||
28 | return A * np.exp(-t/tau) * np.sin((w+a*t)*t) + b | |||
29 | ||||
30 | popt, pcov = curve_fit(func, data[data[:,0]>=0,0], data[data[:,0]>=0,1], p0 = [1e-5, 1e-2, 1e5, 1e10, 1e-4], maxfev=10000) | |||
31 | yfit = func(data[data[:,0]>=0,0], *popt) | |||
32 |