Polybench® for biosignals / reference 1.34.1
Describes how to synchronize multiple data sources in Polybench

Synchronization of multiple data sources


Polybench has the ability to process data from an unlimited number of data sources simultaneously. If data from multiple data sources have to be mixed, because calculations are performed on samples from either of these data sources, then special care has to be taken.

This section describes how Polybench needs to be set up in order to process independent data streams.


There are two important problems to be coped with when devices should be synchronized:

1. Finding a common starting point
2. Keeping the device synchronous over time

The first problem is something that unfortunately Polybench cannot solve, because Polybench does not know how long it takes to get a measurement from a sensor of a device as a digital value into the computer. There are many factors that may influence this time delay, for example the speed of the sensor, the speed of the digitization process inside the device, how many measurement samples are packed together before they are sent to the computer, and the transportation of digital values to the computer.
If two equal devices are used, then an expert for the device may conclude that the delay described above is equal for both devices. In that case problem 1 is not an issue. But in many cases different kinds of devices are used, so that the delay times can vary a lot.

The only way of getting this first synchronization point, which is a point in the sample streams that describes the same moment in the real-world time, is by provoking an event that is registered on all devices.
For example, to synchronize an electro-physiological signal with a sound signal, one could tab an electrode with its finger, in such a way that the tap is audible on the sound device. In the data recording, the tap on the electrode is visible as a clear artifact in the electro-physiological data as well as the sound file. Now, one file can be shifted so that both artifacts are brought together. It is then assumed that other events during the measurement are also visible together.

But unfortunately that is not necessarily true, and this is problem 2: Different measurement devices never have equal timing, because they function independently and all have their own reference time.

For example, two devices both sample their data with 200 samples per second (Hz). At least, that is what the specification says. Due to small deviations in clock crystals and maybe differences in temperature or other environmental disturbances, one device may actually sample with 200.01 Hz, whereas the other samples with 199.99 Hz. How much the frequency really is, only depends on the reference time that is used to measure the sampling frequency. The faster device could also say that the other device samples with 199.98 Hz, while its own frequency is exactly 200 Hz.

This problem is something that Polybench tries to solve. Polybench has to, because without solving this problem, measurements of different devices cannot be compared to each other well. In the above example, after 100 seconds, the first device has actually recorded 20001 samples and the second only 19999 samples. After one hour time, the signals from both devices have 72 samples deviation, which is 0.36 seconds. Whether this deviation is tolerable or not, is a statistical question.

How to synchronize devices

Polybench adjusts the time of each device that has the Synchronized property, and if that property is set to True. Note that not all device operators offer this property, because some devices output only a constant that is not related to time.

If your application uses only one data source (from a device), then there is probably no need for adjusting the timing. In that case you leave the Synchronized property to False.

If you application uses multiple data sources (multiple devices, or a device combined with signal generators or file replays), and those data sources should be combined in calculations, then you need to set the Synchronize property of the device operators to True. This is necessary, because then all data sources must use the same time system.

Note that if your application uses multiple data sources, but those data sources are never combined - they just run in parallel, but you do not make calculations with signals from more than one data source - then you do not necessarily have to set the Synchronized property to True.

Please also note that immediately after starting the data acquisition, the synchronization error will be higher. The system needs, depending on a number of technical properties of the device, about 10 seconds to one minute to reach its optimal synchronization.

Controlling the synchronization using the DelayTime property

If you have set the Synchronized property of a device to True, then there is another property important to have a look at. That is the DelayTime property (unit in seconds). This property determines what the fixed delay is between data from the device coming into the computer, and the moment the data is output by the device operator.

The DelayTime property actually is very important. It has a minimum value, so it must always be greater than 0. How much this minimum value is, depends on the technical behavior of the device (especially the size of sample bursts) and the Polybench synchronization engine. In general, there must be enough delay so that Polybench has room to adjust the timing of the device. If you put a new device operator onto the drawing board of Polybench Designer, then the default DelayTime in the properties should be seen as the minimum delay time. On the other hand, the delay time should not be too big, because it that makes the ability of the system to adjust the signal timing more sluggish.

By adjusting the DelayTime, you could shift the time line of individual devices, in order to get physical events on the same sample number. But you should not use this property for that! If you require to shift the time line, then use an ordinary Delay operator ("Delay"). The DelayTime property is only there to control the synchronization process, which has a time delay as a result.

How does Polybench adjust the device time

If a device in a synchronized system outputs too few samples compared to what is expected by Polybench, then obviously Polybench has to add samples to the data stream to keep up the sample count. Equally, if a device outputs too many samples compared to other data sources, then Polybench has to leave out samples.

If Polybench has to add samples so that the timing of the signal stays correct, then those samples are copies of the previous sample. In that case you will see a sample doubled every so many samples in the signal.

If Polybench has to cut out samples to keep up timing, then those samples are just thrown away. You will then miss one sample every so many samples in the signal. For physiological signals this is statistically insignificant. However, if you are acquiring a digital (machine) signal, then maybe each sample may contain vital information. For example, if the signal is a pulse train with pulses of one sample period wide, then you could be missing pulses if the device is set in Synchronized mode. Don't use synchronization for a device in that case!

Checking synchronization and trouble shooting

You can monitor the adding or cutting out of samples in a Y-T Viewer, because every time this happens a system event is added to the signal. You can have a look at the _extend event markers for each sample that was doubled, and the _extract event marker for each sample that was cut out.

You will see that for one device there are always both extracts and extends. If a device timing is too slow according to the Polybench synchronization engine, then statistically there will be more extends than extracts, and vice verse.

If you see very many adjustments per time period, for example more than 10 adjustments per second, then this could be caused by two things:

- either the device timing deviates strongly from the Polybench timing system,
- or the Polybench synchronization system cannot get the synchronization right

If the synchronization process fails, then this could be caused by the DelayTime setting of a device operator. Try to increase the delay time and observe if time adjustments are getting less over time. For example, try a delay of 1 second and see what happens.

Please note that if you run multiple devices in one system, that the synchronization behavior per device is different than when this device would run alone. The reason for that is that the PC has to share data communication lines, so that the data flow becomes less smooth. You might need to set the DelayTime property a little higher in that case.

Polybench also monitors the effectiveness of the synchronization. Each device operator that can be set to synchronize also has a variable parameter called MeasuredDelay. The measured delay should be equal to the DelayTime setting, but in reality it will always have small deviations. You can visualize this parameter in a Y-T Viewer, in the following way:

The Variable To Constant ("Variable To Constant") is used to read the MeasuredDelay parameter of the device operator. As can be seen, the DelayTime of this synchronized device is set to 0.2 sec. The time deviation lays within a range of +/- 1 ms, which is justifiable.

The MeasuredDelay parameter tells you what the synchronization error is compared to the system. If the MeasuredDelay for example is 2 ms less than the DelayTime setting, then at that moment the signal leads 2 ms relative to other data sources in your application. If the MeasuredDelay is 2 ms more than the DelayTime setting, then at that moment the signal lags 2 ms relative to other signals in the application.

Of course, the MeasuredDelay deviation should be as small as possible, but it will always be there. You have to decide whether this deviation in time is justifiable for the kind of signals you are measuring. For example, if you are looking at P300 spikes in the brain, then every millisecond deviation could be too much, but if you are looking at the air flow of a breathing patient, then 10 ms deviation is statistically irrelevant.

If Polybench does not manage to get the synchronization of a device right, then this will be obvious from the MeasuredDelay value. If that value is much off the DelayTime setting, or if that value stays at a very different value without recovering within 10 seconds, then there is a synchronization problem. The first thing you then need to have a look at, is the DelayTime setting (try to increase it).

Also note that the hosting computer requires enough processing power to execute the application. If the CPU occupation becomes 100% for an extended period of time, then device synchronization will fail and the application may eventually even crash. You can check the CPU occupation using the Windows Task Manager (Performance tab).