diff options
-rwxr-xr-x | bin/msp430-etv | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/bin/msp430-etv b/bin/msp430-etv index afe885f..4954304 100755 --- a/bin/msp430-etv +++ b/bin/msp430-etv @@ -15,6 +15,22 @@ import time opt = dict() +def running_mean(x: np.ndarray, N: int) -> np.ndarray: + """ + Compute `N` elements wide running average over `x`. + + :param x: 1-Dimensional NumPy array + :param N: how many items to average. Should be even for optimal results. + """ + + # to ensure that output.shape == input.shape, we need to insert data + # at the boundaries + boundary_array = np.insert(x, 0, np.full((N // 2), x[0])) + boundary_array = np.append(boundary_array, np.full((N // 2 + N % 2), x[-1])) + print(boundary_array) + cumsum = np.cumsum(boundary_array) + return (cumsum[N:] - cumsum[:-N]) / N + def measure_data(filename, duration): # libmsp430.so must be available if not 'LD_LIBRARY_PATH' in os.environ: @@ -274,6 +290,9 @@ if __name__ == '__main__': print('Average per-peak energy (delta over baseline): {:.0f} µJ : {:.9f}'.format( delta_energy * 1e6 / len(peaks), delta_energy / len(peaks))) + power_from_current = data[:, 1] * data[:, 2] * 1e-12 + power_from_energy = ((data[1:, 3] - data[:-1, 3]) * 1e-9) / ((data[1:, 0] - data[:-1, 0]) * 1e-6) + mean_power = running_mean(power_from_energy, 10) if 'stat' in opt: mean_voltage = np.mean(data[:, 2]) @@ -286,8 +305,9 @@ if __name__ == '__main__': if 'plot' in opt: # nA * mV = pW - pwrhandle, = plt.plot(data[:, 0] * 1e-6, data[:, 1] * data[:, 2] * 1e-12, 'b-', label='P=U*I', markersize=1) - energyhandle, = plt.plot(data[1:, 0] * 1e-6, ((data[1:, 3] - data[:-1, 3]) * 1e-9) / ((data[1:, 0] - data[:-1, 0]) * 1e-6), 'r-', label='P=ΔE/Δt', markersize=1) + pwrhandle, = plt.plot(data[:, 0] * 1e-6, power_from_current, 'b-', label='P=U*I', markersize=1) + energyhandle, = plt.plot(data[1:, 0] * 1e-6, power_from_energy, 'r-', label='P=ΔE/Δt', markersize=1) + energyhandle2, = plt.plot(data[1:, 0] * 1e-6, mean_power, 'y-', label='E/Δt', markersize=1) plt.legend(handles=[pwrhandle, energyhandle]) plt.xlabel('Time [s]') plt.ylabel('Power [W]') |