ACC Sensor - Unit Conversion
Difficulty Level:
Tags pre-process☁ACC☁conversion

The OpenSignals outputted file formats contain raw data, so each sample has a digital unit.

In scientific terms it is recommended the use of specific units, like electric tension (V) or electric current (A). Each sensor that PLUX commercialise has a datasheet where a transfer function is mentioned for unit conversion be done.

The next lines are intended to explain how this conversion can be programmatically done.

In spite of the unit conversion procedure has some common steps applicable to all sensors, the current Jupyter Notebook is dedicated to the unit conversion procedure of signals acquired with Accelerometer sensor.

1 - Importation of the needed packages

In [1]:
# biosignalsnotebooks Python package with useful functions that support and complement the available Notebooks
import biosignalsnotebooks as bsnb

# Function used for creating a numpy array, where a mathematical operation can be applied to each entry in an easy and automatic way. On the other side, linspace, here will be used for generation of a time-axis.
from numpy import array, linspace

2 - Download of the sensor datasheet from our Support Page. ). In this case we are working with ACC, being our file located here.

In [2]:
# Embedding of .pdf file
from IPython.display import IFrame
IFrame('../../images/pre-process/unit_conversion_ACC/ACC_Sensor_Datasheet.pdf#page=2', width="100%", height="350")
Out[2]:

3 - Extraction of the transfer function from the beginning of the second page

\begin{equation} ACC{(g)} = \frac{ADC-{C_{min}}}{{C_{max}}-{C_{min}}}\times{2}-{1} \end{equation}
$ACC{(g)}$ - ACC value in g-force (g) $ADC$ - Value sampled from the acquisition channel $C_{min}$ - Minimum calibration value $C_{max}$ - Maximum calibration value

Quoting the description available on the sensor datasheet:

This sensor requires a calibration to provide reliable measurements. The resulting calibration values ($C_{min}$ and $C_{max}$) which are needed for the transfer function are determined by performing a very slow 360º rotation of the sensor around each axis to force the accelerometer to cross the gravity-imposed −1g and 1g

So, $C_{min}$ and $C_{max}$ are the minimum and maximum RAW values registered on each channel during the calibration procedure.

4 - Loading of data stored in biosignalsnotebooks own signal library

In [3]:
# Data loading
data, header = bsnb.load_signal("https://drive.google.com/open?id=1Tky7YNZ95VkFN3F2rxM6Fwf_x2YTMYmx", get_header=True)

In the following cell, some relevant information is stored inside variables. This relevant information includes the mac-address of the device, channel number and signal acquisition parameters such as resolution and sampling rate.

For a detailed explanation of how to access this info, the "Signal Loading - Working with File Header" Notebook should be consulted.

In [4]:
ch_X= "CH1" # Channel (X-axis)
ch_Y = "CH2" # Channel (Y-axis)
ch_Z= "CH3"# Channel (Z-axis)
sr = 1000 # Sampling rate
resolution = 16 # Resolution (number of available bits)

For our specific case (16 bits acquisition), the calibration values ($C_{min}$ and $C_{max}$) are:

In [5]:
c_min = 28000
c_max = 38000

Access to acquired signal samples and storage inside a new variable.

In [6]:
signal_X = data[ch_X]
signal_Y = data[ch_Y]
signal_Z = data[ch_Z]

5 - Final unit conversion (to g ) by applying the transfer function sample by sample

In [7]:
signal_X_ = ((array(signal_X) - c_min) / (c_max - c_min)) * 2 - 1
signal_Y_= ((array(signal_Y) - c_min) / (c_max - c_min)) * 2 - 1
signal_Z_ = ((array(signal_Z) - c_min) / (c_max - c_min)) * 2 - 1

6 - Time axis generation

In [8]:
time = bsnb.generate_time(signal_X_, sr)

Comparison between RAW and mV signal.

In [9]:
bsnb.plot([time, time,time,time, time,time], [signal_X, signal_X_,signal_Y,signal_Y_, signal_Z,signal_Z_], y_axis_label=["Raw Data", "Acceleration (g)", "Raw Data", "Acceleration (g)","Raw Data", "Acceleration (g)"], title=["X Channel (Raw)", "X Channel (g)", "Y Channel (Raw)", "Y Channel (g)", "Z Channel(RAW)","Z Channel(g)"], grid_lines=3, grid_columns=2, grid_plot=True)

Similar Notebooks , dedicated to the unit conversion of other sensors, are available in the following "conversion" section of Notebooks Grouped by Tag page

In [10]:
from biosignalsnotebooks.__notebook_support__ import css_style_apply
css_style_apply()
.................... CSS Style Applied to Jupyter Notebook .........................
Out[10]: