# Real-Time Feedback in Swimming Exercises Using Embedded Devices in Water
## 2 Materials and Methods
### Vote Request  
For the voting process to be executed, the system requires that either the learning routine has been previously completed or that a motion template is already stored in non-volatile memory. Data acquisition is performed from slave-type nodes. The system implementation is designed to manage data reading in a way that avoids executing verification algorithms on every reading cycle. Not all data values retrieved from the sensors are considered eligible for evaluation. When entering the evaluation phase (referred to as the voting routine), the system aims to assess the movement attempted by the user. Performing verification at every acquisition step would reduce system performance. In the current implementation, sensor data are sampled every 50 ms. Each sample contains acceleration and rotational values along all three axes, resulting in a total of 240 values per sample. The Dynamic Time Warping (DTW) algorithm is applied to evaluate the similarity of the recorded movement to a reference pattern. The execution time for DTW on the current dataset is approximately 8.5 ms, which is relatively low. However, future improvements aim to increase the sampling frequency, which would, in turn, increase the computational load and execution time of the DTW algorithm [21; 22; 23]. The voting routine is initiated by the master node and executed on the slave node. Once invoked, it runs continuously until either the execution mode changes or the system is powered down. The initial condition-checking phase resembles that of the learning routine; specific criteria must be met for the sensor data acquisition to begin. Sensor readings are sampled every 50 ms and processed through both the stationery and motion detection functions. If no significant difference is detected between successive readings over 25 iterations, the system performs an origin recalibration by averaging these 25 values. However, if significant variation is observed, the system bypasses the stationary check and proceeds to motion detection. Based on live measurements conducted under stationary conditions, the drift in the readable sensor data was not significant enough to noticeably affect the system's output similarity. To prevent unwanted measurements including gyroscope drift data, the stationary detection and recalibration functions continuously update the calibration dataset. This ongoing process helps maintain system stability and ensures reliable monitoring. Gyroscope data contribute to approximately 50% of the calculated similarity metric, with the remaining contribution derived from accelerometer data. Therefore, minor drift in the sensor's output does not significantly influence the overall similarity result. The motion detection logic verifies whether substantial movement is present on any of the six axes (acceleration and rotation on X, Y, Z). If movement is detected consistently over 10 consecutive samples, the system continues collecting an additional 30 samples, resulting in a complete set of 40 readings during active motion. Upon reaching motion validation, the voting algorithm is triggered. This algorithm utilizes Dynamic Time Warping (DTW) to compare the captured motion sequence with the previously learned template. The DTW algorithm computes a similarity score, returning a percentage value that quantifies the degree of correspondence between the observed motion and the stored reference pattern. The total time from the initiation of a movement to the completion of the similarity computation is approximately 2.10 s. This duration accounts for the acquisition of 40 sensor readings, captured at 50-ms intervals, resulting in a total collection time of 2 s per movement cycle.