GON - Angular velocity estimation
Difficulty Level:
Tags extract☁gon☁angle☁velocity☁acceleration

Goniometers are instruments that measure the relative angle between two points. In the case of PLUX"s Goniometer (GON) sensor , the measurement is made between two plaques.

Given the temporal evolution of the angle between the two plaques, through the application of simple physical principles, it is possible to calculate both angular velocity and angular acceleration .

In this Jupyter Notebook , we will demonstrate how to calculate the angular velocity starting with a signal acquired using the Goniometer and how to compute those values using Python .


1 - Import the required packages

First, we will import the required Python packages that will facilitate our job later in this notebook.

In [1]:
# Import the biosignalsnotebooks Python package
import biosignalsnotebooks as bsnb

# Import some functions of the numpy Python package that will help us in the mathematical steps of the notebook
from numpy import diff

2 - Load the GON signal

For example purposes, we will use a previously acquired signal.

In [2]:
# Define the path of the file that has the signals of each device
file_name = '../../signal_samples/GON.h5'

# Load the data from the file
acquisition, header = bsnb.load(file_name, get_header=True)

# Get the signal that was acquired in the channel 2 of the device
gon_signal = acquisition['CH2']

# Get the sampling rate of the acquisition
sr = header['sampling rate']
In [3]:
# Generate the time axis
time_axis = bsnb.generate_time(gon_signal, sample_rate=sr)

# lowPass filter to get rid of noise
gon_signal = bsnb.lowpass(gon_signal, f=1, fs=sr, use_filtfilt=True)

# Plot the signal
bsnb.plot(time_axis, gon_signal, y_axis_label="Raw Units (a.u.)", title='Goniometer Signal')

2.1 - Conversion to Physical Units

In order to convert the signal to its physical units, we need to apply the transfer function for the Goniometer sensor that is present in the sensor datasheet .

Note: If you find this step troubling, we invite you to read the Goniometer Sensor - Unit Conversion

In [4]:
# Vcc value of the device
vcc = 3

# Resolution used during the acquisition (the index 1, serves to get the resolution of CH2)
resolution = header['resolution'][1]

# Applying the transfer function to the signals
gon_signal_converted = ((vcc / (2**resolution - 1)) * gon_signal - (vcc / 2)) / ((vcc / 2) * 606e-5)
In [5]:
# Plot the signal
bsnb.plot(time_axis, gon_signal_converted, y_axis_label="Degrees (\u00BA)", title='Goniometer Signal')

3 - Calculate the angular velocity

To calculate the angular velocity given the variation of the angle over time, we need to apply a math operation called derivative.

In physics, a velocity of some sort corresponds to the variation of a given variable over time ($dt$). In this case, angular velocity ($\omega$), as the name indicates, corresponds to the variation of an angle ($d\theta$).

A variation can be represented as the derivative of a function or a signal, if the time interval is short enough, and is usually represented as:

$$ \omega = \frac{d\theta}{dt} $$

In practical terms, the time between samples is sufficient to apply the simplified/discrete version, in which the velocity corresponds to the mean velocity between two points in time. Thus, in this case it is represented as:

$$ \omega = \frac{\Delta\theta}{\Delta t} = \frac{\theta_i - \theta_{i-1}}{t_i - t_{i-1} } $$

Thus, the velocity in each point corresponds to the difference between the present value ($\theta_i$) and the previous one ($\theta_{i-1}$) divided by the present time instant ($t_i$) minus the previous one ($t_{i-1}$). The variation of time corresponds then to the period of acquisition, which is the time between two consecutive samples.

Hence, to calculate the velocity, we first need to calculate the period of acquisition, that is the inverse of the sampling rate.

In [6]:
period_acquisition = 1/sr

Then, we need to calculate the difference between consecutive samples to divide by the period of acquisition. Fortunately, numpy has that same function implemented and, so, we only need to use it.

In [7]:
diff_consecutive_samples = diff(gon_signal_converted)

The last step left includes the calculation of the angular velocity. This step consists on dividing the difference between consecutive samples (diff_consecutive_samples) by the time between consecutive samples (period).

In [8]:
angular_velocity = diff_consecutive_samples / period_acquisition
In [9]:
time_velocity = bsnb.generate_time(angular_velocity)
bsnb.plot(time_velocity, angular_velocity, y_axis_label="Angular Velocity (\u00BA/s)", title='Angular Velocity Signal')

The same could be made to calculate the angular acceleration : calculate the difference between consecutive points of the angular velocity signal and divide by the period of the acquisition to end up with the angular acceleration signal.

In this notebook, you learned how to calculate the angular velocity given the angle over time, by calculating the ( pseudo ) derivative of the signal. Thus, you can apply the same rationale to calculate velocity for every signal that represents position, angle or other over time.

We hope that you have enjoyed this guide. biosignalsnotebooks is an environment in continuous expansion, so don"t stop your journey and learn more with the remaining Notebooks !

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