# Simple Ultrasonic-Based Localization System for Mobile Robots
## 3 System Design
Meanwhile, in the beacon, the received HF signal is processed, and 20 periods of the ultrasonic signal with a frequency of 40 kHz are generated. The number of periods was determined through experimental verification, where multiple possibilities were tested. Using an oscilloscope, measurements of the envelope of the received signal on the ultrasonic receiver were taken for various distances from the ultrasonic transmitter. Specifically, the distances were 1.5, 2.5, and 3.5 m. For these distances, measurements were taken with different numbers of periods (10, 12, \(\ldots\), 40). For each distance, the maximum of the received signal envelope was evaluated. The maximum for periods less than 20 exhibited lower values than the maximum for 20 periods. For periods with values above 20, the maximum did not increase further, but there was an area where the derivative of the maximum was equal to zero at multiple points (not just one). Based on these measurements, the sufficient number of periods turned out to be exactly 20. After the time required for the ultrasonic signal to travel 1 m (dead zone not required) sent from the tag elapses, the tag starts sampling the ADC channel with a period of 4 microseconds. After collecting N all = 2700 samples, a fast Fourier transformation calculation is initiated in the microcontroller. The use of 2700 samples represent, under normal conditions, the passage of the ultrasonic signal approximately 3.75 m, so after adding the dead zone, we are able to evaluate the distance from 1 m to 4.75 m. Of course, considering the nature of the fast Fourier transform (FFT) calculation and signal evaluation after N = 125 samples, it is evident that the last approximately 175 cm is not calculated. It is not a problem to determine the distance up to 4.5 m, which fully satisfies our requirements for the typical type of buildings. Due to the sufficiently fast calculation, the step of evaluating the signal magnitude in the 40 kHz range from the collected samples was set to N/2. Lowering the step setting slightly increased repeatability and accuracy in experiments but significantly extended the FFT calculation time. When using a budget microcontroller STM clocked at 64 MHz and performing a simple FFT calculation, the computation takes 11.4 ms. This time, together with the sampling time (10.7 ms), communication time with the nRF module (0.2 ms), and the time needed for data collection delay (3 ms), determines the time required for evaluating the distance from a single beacon (25.3 ms). For detecting and evaluating distances from three beacons, a total time of 25.5 ms is required, which represents the sampling frequency for determining position as 13 Hz. Figure 3 presents the measured results for various distances. The graph has been created from measurements for distances of 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, and 4.4 m, representing the range where we expect robot position measurements to be necessary. Naturally, the measured values are in the ideal position, meaning that both the beacon and the tag are aligned. The horizontal axis in the graph represents the sample number, which are dimensionless, measured using the ADC. On the right side of the graph, there is a scale and axis values of the 8-bit signal from the ADC (\(-\)128; 127). The bottom part shows the received signals for different distances, displaying the outer envelope of the received signal and its profile. The left axis shows the FFT magnitude values for 40 kHz. The magnitude precedes the signal envelope by 125/2 samples, as evident from the calculation's nature. The strength of the received ultrasonic signal decreases at higher distances. The signal is strongest, as well as its magnitude, for the shortest distance, i.e., 1.5 m, see in Figure 4.  
Figure 4: Measured signal at distance 1.5 m and its FFT magnitude for 40 kHz. Figure 3: Measured signal at different distances and its FFT magnitude for 40 kHz. During the measurements, the repeatability of the measurement principle was crucial, which can be determined using the standard deviation.