Synchrony - Acoustic Signal
Difficulty Level:
Tags pre-process☁synchrony☁sound

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 synchronised 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 and 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 an acoustic sensor to synchronise all of your signals acquired with different devices.


1 - Import the required packages

In order to have access 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 acoustic 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, which ensures that we can visually perceive the instant of synchronisation. In this case, the distinctive event was to clap in a silent environment.

In [2]:
path = '../../signal_samples/'
file_name_1 = path + 'sync_acoustic_1.txt'
file_name_2 = path + 'sync_acoustic_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['CH1'])), np.arange(len(file_2['CH1']))], [file_1['CH1'], file_2['CH1']])

3 - Synchronising the signals

The last step is to apply the function synchronise_signals available in the biosignalsnotebooks Python package using the signals of the channels that we want.

In [4]:
channels = ('CH1', 'CH1')
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 present 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_acoustic_1.txt', path + 'sync_acoustic_2.txt'], [path + 'sync_acoustic_1.h5', path + 'sync_acoustic_2.h5'])

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

# 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 !

**Auxiliary Code Segment (should not be replicated by the user)**

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