# Improved Measurement Accuracy Based on Moving Sine-Wave Fitting for Ultrasonic Ranging

Authors: Xuanze Wang; Aihui Wang; Jinping Yin; Hang Zhao; Zhengqiong Dong; Yiyan Fan; Zhongsheng Zhai
Journal: Shock and Vibration
 (2022)

---

## Abstract

In ultrasonic ranging system, the time-of-flight (TOF), which acquired by the determination of two special points of ultrasonic echo, is important for accuracy and speed. The published calculation of TOF processing methods is too enormous to affect the real-time performance. To improve its measurement accuracy and speed, we proposed a new algorithm called “moving sine-wave fitting” to calculate the envelope of ultrasonic echo for each calibration point. Then, the absolute feature point (AFP) corresponding to half of the envelope peak can be defined and used to find out the relative feature point (RFP); the linear relationship between the RFPs and the known distances should be obtained referring to calibration points. At last, the distance on the measure can be acquired by using linear interpolation according to the above relationship. The measurement experiments have been performed on a set of distances, which shows a good measurement resolution that the overall measurement accuracy is 0.513 mm, and the linear correlation coefficient between the RFPs and the obtained distances isR2 = 0.806.


---

## Body

## 1. Introduction

As its advantages of nondestructive and rapidity, ultrasonic ranging has been widely used in architecture, metal industry, automobile reverse anticollision systems [1–4], and so on. Its basis is analyzing the variation of phase or time-of-flight (TOF) between the transmitted and reflected ultrasonic wave from the object in the ultrasonic distance measuring system [5, 6]. The former method based on phase analysis requires a whole period of sampling for Fourier transform and is not suitable for real-time measurement. In comparison, the latter one TOF-based is easy and simple to handle [7, 8], which can be classified as variable threshold detection and cross-correlation function method [9–11]. The working principle of the TOF method is to calculate the duration of propagation of the ultrasonic signal between the transmitter and the receiver. Since the energy of the ultrasonic signal wave is extremely weakened during transmission, the signal-to-noise ratio (SNR) of the echo signal is low. Therefore, accurately locating the position of the echo signal is significant for the ultrasonic signal processing of the measurement. A number of scholars have deeply researched in this area and proposed many signal processing methods.Considering the measurement accuracy of distance largely depends on the quality of the determined TOF, aiming at these problems above, Wu et al. [12] proposed a method easy to implement in hardware; however, it shows a good measurement result only if the signal-to-noise ratio (SNR) is relatively low. Liang et al. [13] and Brassier et al. [14] proposed to extract the stable feature of points located in echo signals based on cross-correlation algorithm, but it needs large computation and also cannot work in real time. Recently, data envelopment analysis (DEA) has been introduced to calculate TOF by extracting the feature points of echo signals. For example, Angrisani et al. [15] gave a model based on unscented Kalman filtering to estimate TOF by the start and end time of the envelope. Although it can provide a wealth of information, the measurement accuracy and range are unsatisfactory due to the starting point of the echo signal being regarded as the feature position, and the small amplitude of starting point will be disturbed by noise.In this paper, we propose to improve the measurement accuracy of TOF based on moving sine-wave fitting (MSWF) and linear interpolation algorithm. Figure1 shows the echo signals of known distance, the half-peak point of the envelope curve is defined as the absolute feature point (AFP), and a peak point near the AFP is expressed as the relative feature point (RFP). The mathematical relationship between the distance l and the sampling sequence of RFP can be established, which converts the distance measurement to the calculation of RFP’s sampling sequence value, thus making the measurement result more noise-resistant and accurate. Owing to the limitation of sampling frequency and noise jamming, average values of repeated measurements at the same distance are used to eliminate random error. The RFP’s sampling sequence can be calculated using the average one of AFP and the average feature offset (FO) [16]. In the ranging process, the AFP is obtained from the envelope curve which is calculated by the MSWF algorithm. The FO, computed by the linear interpolation with AFP, is applied to the calculation of the RFP’s position. After the final compensation of phase method, the accurate distance can be obtained by the mathematic relation between the RFP’s sampling sequence and the distance. This method combines both the high accuracy advantage of phase detection and the absolute measurement advantage of TOF [12–17].Figure 1
An envelope of echo and the corresponding locations of AFP and RFP.


## 2. Theory

### 2.1. Echo Envelope Calculation Using Moving Sine-Wave Fitting Algorithm

In the ultrasonic ranging, the echo signal reflected from an object is a modulated sine-wave [18], hence the measurement data Y with interval Δ = 2π/n and length N can be fit recursively according to the moving sine-wave fitting algorithm.For measurement data,Yk = {yk, yk+1, yk+2, …, yk+n} in data Y, the amplitude of the sample data can be considered as constant within one cycle. Therefore, the formulation of the Yk can be expressed as(1)yk+i=Akcosθk+Δi+ck+εi,where Ak, θk, ck, and εi represent the amplitude, the phase angle, the offset, and the random error, respectively. Obviously, equation (1) can be also be rewritten as(2)yk+i=akcosΔi+bksinΔi+ck+εk,where parameters a and b satisfied the following constraint condition as(3)Ak=ak2+bk2.The problem to calculate the echo envelope, therefore, is converted to determinea and b, and they can be obtained by using the least square method as(4)ak,bk,ck=argmin∑i=0n−1yk+i−akcosΔi−bksinΔi−ci2.The optimal solution in the fitting problem can be obtained at the extreme point in the function of the right part in equation (4). Hence, by taking the partial derivative on ak, bk, and ck, we can obtain(5)akbkck=Tk−1Sk,where the transmission matrix S and T can be expressed as(6)Sk=∑i=0n−1yk+icosΔi∑i=0n−1yk+isinΔi∑i=0n−1yk+i,Tk=∑i=0n−1cos2Δi∑i=0n−1sinΔicosΔi∑i=0n−1cosΔi∑i=0n−1sinΔicosΔi∑i=0n−1sin2Δi∑i=0n−1sinΔi∑i=0n−1cosΔi∑i=0n−1sinΔi∑i=0n−11.Once the parametersak, bk, and ck are calculated, the formulation of the measurement data in one cycle are determined, and by moving the measurement data from y1 to yN−n+1, all the expression curves of the measurement data can be represented, as shown in Figure 2.Figure 2
The schematic diagram of fitting process.In order to reduce the amount of calculation in the fitting process, the parametersak and bk are calculated recursively with the moving sine-wave fitting algorithm, since the transmission matrix Sk of the Yk can be described as(7)Sk=sk1sk2sk3.Then, the transmission matrixSk+1 of the Yk+1 can be formulated as follows:(8)Sk+1=sk1−ykcos2πn+sk2sin2πn+yk+ncosn−12πn−sk1−yksin2πn+sk2cos2πn+yk+nsinn−12πnsk3−yk+yk+n.According to the proposed method, all the measurement data and amplitudeA2, A3, …, AN, of the echo can be obtained reclusively once the Y1 is calculated. Therefore, the proposed method can be well applied to avoid the redundant calculation, and the echo envelop is obtained once all the amplitude is determined.


### 2.2. Determination of the Relationship between RFPs and Distances

Generally, there is the fluctuation of the echo signal in any position, and the range of fluctuation can be as large as one sampling interval. Therefore, the position of AFP should be located at the half of the peak with the largest inclined rate point, which gets the closest fluctuation range in theX-axis. From the calculated amplitudes of echo envelope including A1, A2, …, An, the half of peak Amax is determined as AFP, whose sampling sequence is denoted by M.Because the sampling sequence of AFP is easily disturbed by random noise or the other echo, for a given group of calibrated distancesL = {l1, l2, …, lj, lj+1, …, lN} with the same step of ∆l, the sampling sequences M = {M1, M2, …, Mj, …,MN} corresponding AFPs can be determined. When the RFP1 of l1 is selected as the value nearest AFP1 in echo, the next RFP2 will move a distance ∆x = ∆l · f/ v (f and v are the sampling frequency and ultrasonic velocity, respectively) and also locate in a specific peak theoretically. Then, the sampling sequences MR = {MR1, MR2, …, MRj, …, MRN} of RFPs are linear related to the distance on the measure, which can be calculated according to the above rule.If the calculated RFP of the distance on measure does not coincide with a peak located in echo, equation (9) based on linear interpolation is utilized to acquire the feature offset FOx, which equals to the difference between the sampling sequence of RFP and AFP, as shown in Figure 3.(9)FOx=FOj+1−FOjMx−MjMj+1−Mj+FOj,j≤x≤j+1,j=1,2,…,N−1,where Mx denotes the sampling sequence for the distance on measure. Further, wrapped phases of echo are analyzed to improve the accuracy of measurement distance, whose description is expressed as(10)θi=arctan−biai,θi∈−π,π,where ai and bi are the coefficients of the sine and cosine waves described in equation (2), respectively, as shown in Figure 4. In the last, the sampling sequence MRx of RFP corresponding to the distance on the measure can be obtained by(11)MRx=Mx+FOx+θcf2πF,where θc is calculated by equation (10), c = Mx + Fox, f is the sampling frequency, and F is the transmitted frequency of ultrasound.Figure 3
The sketch of FO and ∆x.Figure 4
Phase values of the sample points.


## 2.1. Echo Envelope Calculation Using Moving Sine-Wave Fitting Algorithm

In the ultrasonic ranging, the echo signal reflected from an object is a modulated sine-wave [18], hence the measurement data Y with interval Δ = 2π/n and length N can be fit recursively according to the moving sine-wave fitting algorithm.For measurement data,Yk = {yk, yk+1, yk+2, …, yk+n} in data Y, the amplitude of the sample data can be considered as constant within one cycle. Therefore, the formulation of the Yk can be expressed as(1)yk+i=Akcosθk+Δi+ck+εi,where Ak, θk, ck, and εi represent the amplitude, the phase angle, the offset, and the random error, respectively. Obviously, equation (1) can be also be rewritten as(2)yk+i=akcosΔi+bksinΔi+ck+εk,where parameters a and b satisfied the following constraint condition as(3)Ak=ak2+bk2.The problem to calculate the echo envelope, therefore, is converted to determinea and b, and they can be obtained by using the least square method as(4)ak,bk,ck=argmin∑i=0n−1yk+i−akcosΔi−bksinΔi−ci2.The optimal solution in the fitting problem can be obtained at the extreme point in the function of the right part in equation (4). Hence, by taking the partial derivative on ak, bk, and ck, we can obtain(5)akbkck=Tk−1Sk,where the transmission matrix S and T can be expressed as(6)Sk=∑i=0n−1yk+icosΔi∑i=0n−1yk+isinΔi∑i=0n−1yk+i,Tk=∑i=0n−1cos2Δi∑i=0n−1sinΔicosΔi∑i=0n−1cosΔi∑i=0n−1sinΔicosΔi∑i=0n−1sin2Δi∑i=0n−1sinΔi∑i=0n−1cosΔi∑i=0n−1sinΔi∑i=0n−11.Once the parametersak, bk, and ck are calculated, the formulation of the measurement data in one cycle are determined, and by moving the measurement data from y1 to yN−n+1, all the expression curves of the measurement data can be represented, as shown in Figure 2.Figure 2
The schematic diagram of fitting process.In order to reduce the amount of calculation in the fitting process, the parametersak and bk are calculated recursively with the moving sine-wave fitting algorithm, since the transmission matrix Sk of the Yk can be described as(7)Sk=sk1sk2sk3.Then, the transmission matrixSk+1 of the Yk+1 can be formulated as follows:(8)Sk+1=sk1−ykcos2πn+sk2sin2πn+yk+ncosn−12πn−sk1−yksin2πn+sk2cos2πn+yk+nsinn−12πnsk3−yk+yk+n.According to the proposed method, all the measurement data and amplitudeA2, A3, …, AN, of the echo can be obtained reclusively once the Y1 is calculated. Therefore, the proposed method can be well applied to avoid the redundant calculation, and the echo envelop is obtained once all the amplitude is determined.


## 2.2. Determination of the Relationship between RFPs and Distances

Generally, there is the fluctuation of the echo signal in any position, and the range of fluctuation can be as large as one sampling interval. Therefore, the position of AFP should be located at the half of the peak with the largest inclined rate point, which gets the closest fluctuation range in theX-axis. From the calculated amplitudes of echo envelope including A1, A2, …, An, the half of peak Amax is determined as AFP, whose sampling sequence is denoted by M.Because the sampling sequence of AFP is easily disturbed by random noise or the other echo, for a given group of calibrated distancesL = {l1, l2, …, lj, lj+1, …, lN} with the same step of ∆l, the sampling sequences M = {M1, M2, …, Mj, …,MN} corresponding AFPs can be determined. When the RFP1 of l1 is selected as the value nearest AFP1 in echo, the next RFP2 will move a distance ∆x = ∆l · f/ v (f and v are the sampling frequency and ultrasonic velocity, respectively) and also locate in a specific peak theoretically. Then, the sampling sequences MR = {MR1, MR2, …, MRj, …, MRN} of RFPs are linear related to the distance on the measure, which can be calculated according to the above rule.If the calculated RFP of the distance on measure does not coincide with a peak located in echo, equation (9) based on linear interpolation is utilized to acquire the feature offset FOx, which equals to the difference between the sampling sequence of RFP and AFP, as shown in Figure 3.(9)FOx=FOj+1−FOjMx−MjMj+1−Mj+FOj,j≤x≤j+1,j=1,2,…,N−1,where Mx denotes the sampling sequence for the distance on measure. Further, wrapped phases of echo are analyzed to improve the accuracy of measurement distance, whose description is expressed as(10)θi=arctan−biai,θi∈−π,π,where ai and bi are the coefficients of the sine and cosine waves described in equation (2), respectively, as shown in Figure 4. In the last, the sampling sequence MRx of RFP corresponding to the distance on the measure can be obtained by(11)MRx=Mx+FOx+θcf2πF,where θc is calculated by equation (10), c = Mx + Fox, f is the sampling frequency, and F is the transmitted frequency of ultrasound.Figure 3
The sketch of FO and ∆x.Figure 4
Phase values of the sample points.


## 3. Experiments and Result Analysis

The sketch of the ultrasonic ranging system applied here is shown in Figure5. A signal Nsig. with the frequency of 1 Hz is generated to control MCU A and B simultaneously, and then a square wave containing eight pulses with the frequency of 40 kHz is excited from the transducer Tx. By sampling the echo signal with the frequency of 1 MHz, the distance between two transducers can be successfully calculated.Figure 5
Ultrasonic ranging system.In order to determine the distance effectively, a calibration process is conducted to define the formulation between the distance and the sample sequence. Measurement is performed at every 5 mm and distance groupl = {l1, l2, l3, …, l25} is recorded correspondingly. Hence, according to the proposed model which shows the relationship between Mex and lx, the distance measurement can be easily obtained by linear interpolation.During the experiment, the sound velocity is assumed as 346 m/s under a temperature of 25.7°C, and ∆x is about 15. In order to reduce the interference of noise, the AFP and RFP sequences are averaged with ten measurements, as shown in Table 1.Table 1
Average fixed distance and the two average feature points.
Average distance (mm)AverageMAverageMRAverageFOAverage distance (mm)AverageMAverageMRAverageFO50.02130833325115.0334895142555.01231934425120.0745015272660.08333335825125.0695155422765.03434637226130.0255275633670.05435738427135.0485355723775.06137540126140.0485495873880.05338841426145.0405605993985.03840643125150.0185756154090.02941944324155.0965926313995.01843645923160.05860664438100.05744847123165.08662666135105.08646348623170.03264567328110.04747650024Temperature: 25.7°CThe relationship between the feature offset (FO) and the AFP’s sample sequence is shown in Figure6. It can be seen from Figure 6 that the FO obtained in each measurement does not exceed two ultrasonic cycles, namely, the RFP will not be too far from the AFP. Meanwhile, an obvious relationship between the FO and the AFP’s sampling sequence value can be perceived with the similar correspondence at each measurement, so the average measurement data in Figure 6 can be used as the sample of the linear interpolation. Furthermore, a good reproducibility can be verified from the consistent figures.Figure 6
Relationship between FO and AFP’s sampling sequence value.Substituting the sampling sequence value of the randomly measured 48 AFP (M) into equation (11) to calculate the RFP’s compensation value MR, the RFP-distance relationship and the AFP-distance relationship can be established, which is presented in Figure 7.Figure 7
AFP-distance and RFP-distance relationship.As shown in Figure7, the linear correlation coefficient (LCC) between MR and the distance is 0.806, and the LCC between the M and the distance is 0.682. Besides, though the sampling sequences of both the AFP and the RFP overlap at some specific distance, the higher LCC can be reached at the RFP sampling sequence. The result proves that the RFP’s sampling sequence value is much closer to the actual distance and verifies the proposed method effectively.By fitting the curve in Figure7, the equation between the standard distance and the RFP’s sampling sequence value can be expressed as(12)l=0.35×Me−65.Therefore, the distanceln can be easily calculated once the RFP sampling sequences are determined. Compared with the standard distance measured by the grating ruler ls, the distance error can be represented as Δl = ln − ls, and the error distribution of 48 random RFP sampling sequences is shown in Figure 8 in percentage form. The results measured using RFP are significantly better than those using AFP. In addition, the error fluctuation of the measurement system is random, and the standard deviation of the results of the 48 groups measured using RFP is δ = 0.171 mm. According to the 3δ evaluation principle, the measurement accuracy of this method is ±3δ = 0.513 mm. By contrast, the standard deviation of the distance error obtained by fitting the AFP’s sampling sequence value (M) with standard distance is 0.387 mm and the measurement accuracy is 1.161 mm. Therefore, the measurement accuracy is improved by 55.8% within our proposed method, and a great potential advantage is discovered in the application of high-precision ultrasonic measurement.Figure 8
Values of AFP and RFP measurement error percentage.


## 4. Conclusions

In this work, we proposed MSWF to extract the envelope curves rapidly from echo signals without iteration. Then, the AFP was described as half-peak point in the ultrasonic ranging TOF based, which can be determined in the measurements, and theFOx is interpolated from AFP and the feature offsets on the known distances obtained ahead during the calibration test. Then, the RFP can be located quickly, and we readjusted the position of RFP applying phase analysis further. When the measurement distance is within 50 mm∼170 mm, the measurement accuracy is 0.513 mm, and the LCC is 0.806. Experiments show that the localization method of RFP has the capability of noise suppression and the ranging method has higher accuracy and application potential [19–21].



---

*Source: 9570857-2022-04-05.xml*