Accelerometer Alan Variance Calculation in Python

Alan distributed calculation in Python

Alan dispersion is used to know the noise and bias characteristics of MEMS sensors such as angular velocity sensors. The sensor output obtained from the test that is allowed to stand for 1 hour is summarized in CSV, and the Alan variance is calculated from it.

Language used python Modules used allantools, pylab, numpy, pandas, csv Environment windows 10 64bit

Environment

Install the Alan distribution calculation module with the following command.

python -m pip install AllanTools

Script example

In the following example, the time-series sensor information written in a comma-separated text file called LOG00.TXT is read, and the Alan variance is calculated from it.

import allantools
import matplotlib.pyplot as plt
#import pylab as plt
import numpy as np
import pandas as pd
import csv

#Graph font settings

col_names = ['a{0:02d}'.format(i) for i in range(15)]       #By specifying the column name, pandas can be read even if there is empty data.
#Read txt file and convert to pandas data frame format. No header, column name col_names(a0 ~ a15)Designated to
df = pd.read_table('LOG00031.TXT',sep=',',header=None, names=col_names)
print(df) 
#Extract only specific columns of the relevant data
sim_time = df.iloc[:,0]
gyro_x_df = df.iloc[:,6]
gyro_y_df = df.iloc[:,7]
gyro_z_df = df.iloc[:,8]
#df(Data frame format)Convert from to list format
gyro_x = gyro_x_df.values.tolist()
gyro_y = gyro_y_df.values.tolist()
gyro_z = gyro_z_df.values.tolist()
#plt.plot(sim_time, gyro_x)

#-------------------------
#Alan variance calculation
#-------------------------
#numpy logspace creates an even array on the log scale
#np.logspace(Start point, end point, number of elements, radix)
t = np.logspace(0, 4, 100)  
#y = allantools.noise.white(10000)  # Generate some frequency data
r = 30 # sample rate in Hz of the input data
(t2_x, ad_x, ade, adn) = allantools.mdev(gyro_x, rate=r, data_type="freq", taus=t)  # Compute the overlapping ADEV
(t2_y, ad_y, ade, adn) = allantools.mdev(gyro_y, rate=r, data_type="freq", taus=t)  # Compute the overlapping ADEV
(t2_z, ad_z, ade, adn) = allantools.mdev(gyro_z, rate=r, data_type="freq", taus=t)  # Compute the overlapping ADEV
#fig = plt.loglog(t2, ad) # Plot the results


#plt.rcParams['text.usetex'] = True
#Font specification
plt.rcParams['font.family'] = 'Times New Roman' 

#figure()Create a graph display area with. Specify an object called fig.
fig = plt.figure()
#plt.title('$f(x) = \sin(\pi x)$')
#Positioning the graph to plot(Height 2,Width 2,Quadrant)
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
#ax4 = fig.add_subplot(2,2,4)

#Graph plot (this time loglog graph)
ax1.loglog(t2_x,ad_x, color="black")
ax2.loglog(t2_y,ad_y, color="black")
ax3.loglog(t2_z,ad_z, color="black")
#ax4.loglog(t2,ad)
#Show scale on graph
ax1.grid(which='minor')
ax2.grid()
ax3.grid()
#Graph range setting
ax1.set_ylim([0.001,0.01])
ax2.set_ylim([0.0001,0.01])
ax3.set_ylim([0.0001,0.01])
#Graph title
ax1.set_xlabel(r"$\tau$ [s]")
ax1.set_ylabel(r"Gyro X $\sigma(\tau)$ [deg/hr]") #Writing formulas in LaTex format
ax2.set_xlabel(r"$\tau$ [s]")
ax2.set_ylabel(r"Gyro Y $\sigma(\tau)$ [deg/hr]")
ax3.set_xlabel(r"$\tau$ [s]")
ax3.set_ylabel(r"Gyro Z $\sigma(\tau)$ [deg/hr]")

#graph display
#plt.legend()#Legend display
plt.show()

Graph

Alan variance of the angular velocity sensor output in the 3-axis direction.

image.png

Recommended Posts

Accelerometer Alan Variance Calculation in Python
Date calculation in python
Date calculation in Python
Shapley value calculation in Python
Quantum chemistry calculation in Python (Psi4)
Let's make a combination calculation in Python
Time comparison: Correlation coefficient calculation in Python
Quadtree in Python --2
Python in optimization
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Calculation result after the decimal point in Python
Sorted list in Python
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 18 in Python
Singleton pattern in Python
File operations in Python
Experience the good calculation efficiency of vectorization in Python
Key input in Python
Daily AtCoder # 33 in Python