graph_accelerometer: Support axis-level comparison of adxl345 data
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
This commit is contained in:
parent
b6908e56aa
commit
2d8945dc1c
|
@ -139,6 +139,8 @@ class CalibrationData:
|
||||||
self.psd_y = psd_y
|
self.psd_y = psd_y
|
||||||
self.psd_z = psd_z
|
self.psd_z = psd_z
|
||||||
self._psd_list = [self.psd_sum, self.psd_x, self.psd_y, self.psd_z]
|
self._psd_list = [self.psd_sum, self.psd_x, self.psd_y, self.psd_z]
|
||||||
|
self._psd_map = {'x': self.psd_x, 'y': self.psd_y, 'z': self.psd_z,
|
||||||
|
'all': self.psd_sum}
|
||||||
self.data_sets = 1
|
self.data_sets = 1
|
||||||
def join(self, other):
|
def join(self, other):
|
||||||
np = self.numpy
|
np = self.numpy
|
||||||
|
@ -159,6 +161,8 @@ class CalibrationData:
|
||||||
psd /= self.freq_bins + .1
|
psd /= self.freq_bins + .1
|
||||||
# Remove low-frequency noise
|
# Remove low-frequency noise
|
||||||
psd[self.freq_bins < MIN_FREQ] = 0.
|
psd[self.freq_bins < MIN_FREQ] = 0.
|
||||||
|
def get_psd(self, axis='all'):
|
||||||
|
return self._psd_map[axis]
|
||||||
|
|
||||||
|
|
||||||
CalibrationResult = collections.namedtuple(
|
CalibrationResult = collections.namedtuple(
|
||||||
|
|
|
@ -113,7 +113,7 @@ def plot_frequency(datas, lognames, max_freq):
|
||||||
fig.tight_layout()
|
fig.tight_layout()
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
def plot_compare_frequency(datas, lognames, max_freq):
|
def plot_compare_frequency(datas, lognames, max_freq, axis):
|
||||||
fig, ax = matplotlib.pyplot.subplots()
|
fig, ax = matplotlib.pyplot.subplots()
|
||||||
ax.set_title('Frequency responses comparison')
|
ax.set_title('Frequency responses comparison')
|
||||||
ax.set_xlabel('Frequency (Hz)')
|
ax.set_xlabel('Frequency (Hz)')
|
||||||
|
@ -122,7 +122,7 @@ def plot_compare_frequency(datas, lognames, max_freq):
|
||||||
for data, logname in zip(datas, lognames):
|
for data, logname in zip(datas, lognames):
|
||||||
calibration_data = calc_freq_response(data, max_freq)
|
calibration_data = calc_freq_response(data, max_freq)
|
||||||
freqs = calibration_data.freq_bins
|
freqs = calibration_data.freq_bins
|
||||||
psd = calibration_data.psd_sum[freqs <= max_freq]
|
psd = calibration_data.get_psd(axis)[freqs <= max_freq]
|
||||||
freqs = freqs[freqs <= max_freq]
|
freqs = freqs[freqs <= max_freq]
|
||||||
ax.plot(freqs, psd, label="\n".join(wrap(logname, 60)), alpha=0.6)
|
ax.plot(freqs, psd, label="\n".join(wrap(logname, 60)), alpha=0.6)
|
||||||
|
|
||||||
|
@ -243,7 +243,8 @@ def main():
|
||||||
opts.error("Only 1 input is supported in specgram mode")
|
opts.error("Only 1 input is supported in specgram mode")
|
||||||
fig = plot_specgram(datas[0], args[0], options.max_freq, options.axis)
|
fig = plot_specgram(datas[0], args[0], options.max_freq, options.axis)
|
||||||
elif options.compare:
|
elif options.compare:
|
||||||
fig = plot_compare_frequency(datas, args, options.max_freq)
|
fig = plot_compare_frequency(datas, args, options.max_freq,
|
||||||
|
options.axis)
|
||||||
else:
|
else:
|
||||||
fig = plot_frequency(datas, args, options.max_freq)
|
fig = plot_frequency(datas, args, options.max_freq)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue