Synchrony - Accelerometer Signal
Difficulty Level:
Tags pre-process☁synchrony☁accelerometer

OpenSignals software allows to acquire signals from multiple devices at the same time and using the synchronisation cable, available in https://store.plux.info/cables/231-synchronization-cable.html , the signals are automatically sinchronised in real time.

However, there might be cases in which it is not possible to use the synchronisation cable and the acquired signals may be dephased. In some cases, it might be helpful to synchronise the signals in order to compare them in the time domain. This can be achieved after acquisition by using the </span> biosignalsnotebooks Python package.

The low-level explanation of synchronisation techniques is available in the Device Synchronisation - Cable, Light and Sound Approaches notebook.

In this Jupyter Notebook we will show how you can use the accelerometer sensor to synchronise all of your signals acquired with different devices.


1 - Import the required packages

In order to have access to all functionalities of </span> biosignalsnotebooks Python package, we have to import it.

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

2 - Open the files to see the signals

In this case, two accelerometer signals were acquired at the same time but dephased, because the acquisitions did not start at the same instant. In order to use this type of signals to synchronise data, it is suggested to produce a distinctive event where it can be visually possible to perceive the instant of synchronisation. Accelerometers acquire three-dimensional data on the x, y and z axis.
In this case, the distinctive event was to repeatedly vertically move the accelerometer sensors, thus, the event occurred on the z axis (if you have trouble understanding why, we suggest you to take a look at the accelerometer datasheet ).

In [2]:
path = '../../signal_samples/'
file_name_1 = path + 'sync_acc_1.txt'
file_name_2 = path + 'sync_acc_2.txt'

file_1 = bsnb.load(file_name_1)
file_2 = bsnb.load(file_name_2)
In [3]:
import numpy as np
bsnb.plot([np.arange(len(file_1['CH3'])), np.arange(len(file_2['CH3']))], [file_1['CH3'], file_2['CH3']])

3 - Synchronising the signals

The last step consists on the application of the function synchronise_signals , available in the biosignalsnotebooks Python package, using the signals of the channels that we want.

In [4]:
channels = ('CH3', 'CH3')
dephase, signal_1, signal_2 = bsnb.synchronise_signals(file_1[channels[0]], file_2[channels[1]])
In [5]:
bsnb.plot([np.arange(len(signal_1)), np.arange(len(signal_2))], [signal_1, signal_2])

3.1 - Create synchronised files

It is possible to synchronise the signals of different files or even from the same file and to produce a new file with the synchronised signals. In this case, all of the signals available in the files(s) will be synchronised - even when there is more than one channel in each file.

In [6]:
# path to all the input files - txt and h5 files
input_paths = ([path + 'sync_acc_1.txt', path + 'sync_acc_2.txt'], [path + 'sync_acc_1.h5', path + 'sync_acc_2.h5'])

# channels of the signals used in synchrony
channels = (3, 3)

# path to the generated file
new_path = path + 'new_file'

# Function to generate the new file with all the synchronised signals
bsnb.create_synchronised_files(input_paths)

Now we have created a new file containing the synchronised signals of the input file(s). The generated file can be opened by OpenSignals or in Python using the load function of the biosignalsnotebooks package, because they are structured as the files produced by the software.

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 [7]:
from biosignalsnotebooks.__notebook_support__ import css_style_apply
css_style_apply()
.................... CSS Style Applied to Jupyter Notebook .........................
Out[7]: