# Real-Time Feedback in Swimming Exercises Using Embedded Devices in Water
## 2 Materials and Methods
### Computing and Data Transmission  
In Figure 5 below, illustrated are the steps in how the system is used. Figure 4: Communication system used. Figure 5: System usage overview. The MPU6050 motion sensor returns raw data in a 16-bit signed integer format, with values ranging from \(-\)32,768 to 32,767. In the context of this project, the data are normalized by dividing these values, resulting in a reduced range approximately between \(-\)2 and 2, expressed in floating-point format. By dividing the raw values by 16,384, the resulting normalized interval of [\(-\)2, 2] corresponds to the default full-scale range of \(\pm\)2 g in the MPU6050 sensor configuration. However, ESP-NOW, the wireless communication protocol used for data transmission, is optimized for sending unsigned integer values and does not natively support the direct transmission of floating-point numbers. To address this limitation, a conversion strategy is implemented to enable the transfer of floating-point data between devices. Two custom functions--encode_float and decode_float--are developed for this purpose. On the slave devices, where sensor data are acquired, the encode_float function converts floating-point values into integer representations suitable for ESP-NOW transmission. On the master device, the corresponding decode_float function receives these encoded values, unpacks the data, and accurately reconstructs the original floating-point values with up to five decimal places of precision. The ESP-NOW protocol limits data transmission to 250 bytes per frame. Therefore, the transmitting-receiving system was adapted accordingly. At this stage, the transmission of consecutive frames to send multiple datasets is not required. Data acquired from the MPU6050 sensor consist of floating-point values representing 120 samples for each of the X (40), Y (40), and Z (40) axes of both the accelerometer and gyroscope. Each set of 120 values is packaged into a single frame for transmission via the ESP-NOW protocol. In addition to sensor data, four extra bytes are sent from the slave to the master device, representing the node ID, calibration state, training status, and movement votes. Since a standard float occupies 4 bytes, transmitting raw float data would require approximately 484 bytes per frame, exceeding the ESP-NOW frame size limit. Moreover, the utilized library supports only unsigned data. To address this, float values are encoded into 2-byte unsigned integers before transmission and subsequently decoded back to float on the master device. This encoding-decoding process restricts float precision to approximately five decimal places. This limitation does not affect system accuracy, as five-decimal precision is sufficient for the application. Additionally, because the integer part of the DTW cost has a more significant influence on similarity comparison, minor variations in the decimal part have minimal impact on overall similarity evaluation. To determine whether the movement performed during the voting phase corresponds to the intended motion, a comparison between the sensor-acquired data and the target motion pattern is required. For this purpose, the Dynamic Time Warping (DTW) algorithm is employed [17]. Dynamic Time Warping (DTW) is a robust algorithm widely used to measure the similarity between two temporal sequences that may differ in length or speed. It is a fundamental technique in time-series analysis, with applications in domains such as speech recognition, gesture detection, motion sequence analysis, and signal processing. DTW is particularly valuable for comparing sequences that are not perfectly aligned in time, as it can accommodate temporal distortions and variability in data patterns [18; 19]. The algorithm operates by constructing a cost matrix that quantifies the distance between each pair of elements from the two sequences. Each entry in the matrix represents the local distance between corresponding data points.