4 from numpy import linalg
6 from pylab import plot, subplot, figure, show, ylim, yticks
7 from pprint import pprint
10 if __name__ == '__main__':
11 data_fname = 'curcal-out.dat'
12 data_buff = np.loadtxt(data_fname)
17 pwm_val = data_buff[:, np.multiply(phase_ord, 2)]
18 pwm_en = data_buff[:, np.multiply(phase_ord, 2) + 1]
19 cur_raw = data_buff[:, [6, 7, 8]]
21 cur_offs = cur_raw[0, :]
22 cur_zerob = cur_raw[zero_rows:, :] - cur_offs
24 rows = cur_zerob.shape[0]
25 cur_resp = np.ndarray(shape=(rows / 2, 3))
26 cur_resid = np.ndarray(shape=(rows, 3))
27 cur_refall = np.ndarray(shape=(rows, 3))
28 cur_ref = np.ndarray(shape=(rows / 2, 3))
30 for i in range(0, rows):
31 pwmen = pwm_en[zero_rows + i, :]
32 pwmv = np.multiply(pwm_val[zero_rows + i, :], pwmen)
33 pwmcent = np.sum(pwmv) / np.sum(pwmen)
34 pwmv = np.multiply(pwmv - pwmcent, pwmen)
35 cur_refall[i, :] = pwmv
37 for i in range(0, rows / 2):
38 cur_resp[i, :] = (cur_zerob[2 * i, :] - cur_zerob[2 * i + 1, :]) / 2.0
39 cur_resid[2 * i, :] = cur_zerob[2 * i, :] - cur_resp[i, :]
40 cur_resid[2 * i + 1, :] = cur_zerob[2 * i + 1, :] + cur_resp[i, :]
41 cur_ref[i, :] = (cur_refall[2 * i, :] - cur_refall[2 * i + 1, :]) / 2.0
50 C = np.dot(Y, linalg.inv(U))
55 for i in range(0, rows):
56 #print cur_zerob[i, :]
57 print np.dot(C, cur_zerob[i, :].T)