Measuring algorithm for flow of ultrasonic gas meter
Technical Field
The invention relates to the field of ultrasonic flight time calculation, in particular to a flow measurement algorithm of an ultrasonic gas meter.
Background
The ultrasonic gas meter has the advantages of non-contact measurement, no movable part, no pressure loss, extremely high measurement precision and the like, and is a research hotspot in the field of gas measurement. The metering principle of the ultrasonic gas meter is that the instantaneous flow is estimated by utilizing the difference of the time of ultrasonic waves in the forward flow direction and the backward flow direction. The estimation of the surface average flow velocity is governed primarily by the time difference Δ T between the time of flight up and the time of flight down, without considering that the speed of sound is influenced by the environment within the pipe. Limited by the performance of the ultrasonic transducer and the hardware cost, accurate estimation of Δ T cannot rely solely on increasing the sampling density to the target granularity. Therefore, it is necessary to complete accurate estimation of Δ T by numerical calculation at a low sampling frequency.
The existing delay estimation technical routes mainly have three types: the first category is in the time domain, which is based mainly on the fact that the cross-correlation function of the ultrasonic signals conforms to a certain assumed distribution, such as gaussian distribution, parabolic distribution, triangular distribution, etc., and then an unbiased estimation is made on the basis of this assumption. Although the algorithm complexity is low, the route is not accurate, and particularly, the error is large under the condition that the gas consumption is less than 1 sampling period. The second category is to estimate the time difference in the wavenumber domain, either by linear fitting of frequency and phase with reference to the phase factor, or by iteratively minimizing an objective function. This approach is more accurate but time consuming due to the use of global data. The third category is high-order and low-order moments, and the method needs to adjust some hyper-parameters and is relatively troublesome to implement. These methods have advantages and disadvantages, but they are difficult to achieve in cases where the transducer is unstable in high and low temperature environments.
Disclosure of Invention
The invention aims to provide a measuring algorithm of the flow of an ultrasonic gas meter aiming at the measuring characteristics of the ultrasonic gas meter flow meter, which is suitable for high and low temperature environments under the condition of not obviously increasing the calculation amount and improves the measuring accuracy.
The invention is realized by the following technical scheme:
an algorithm for measuring the flow of an ultrasonic gas meter comprises the following steps:
(A) inputting an upward flight signal and a downward flight signal, and respectively performing Fourier transform on the upward flight signal and the downward flight signal;
the purpose of the fourier transform is to convert the original time domain signal into the wavenumber domain, obtain the respective frequency spectrum, and facilitate the calculation of the cross-correlation curve. In particular, the fly-up signal s1(n) and a down flight signal s2(n) Fourier transform to obtain F1(k) And F2(k) Wherein:
where k is 0,1,2, …, N-1, N is 0,1,2, …, N-1, N is the extended sequence length, and j is an imaginary unit.
(B) Calculating to obtain the frequency spectrum of the cross-correlation curve according to the Fourier transform results of the upper flight signal and the lower flight signal; the frequency spectrum F (k) of the cross-correlation curve is F1(k)·F2(k) In that respect The convolution process of the cross-correlation curve in the time domain is equivalent to the multiplication process in the wavenumber domain. The cross-correlation curve calculation is performed to perform noise suppression by taking advantage of the uncorrelated relationship between white gaussian noise generated by the transducer and the desired signal.
(C) Performing inverse Fourier transform on the frequency spectrum of the cross-correlation curve to obtain a correlation curve, searching for a peak point position and at least two points adjacent to the peak point position on the correlation curve through a maximum value, and calculating by using a time domain estimation function to obtain an estimation value of a first model;
the correlation curve Rdc(k) Calculated by the following formula:
calculating to obtain a correlation curve Rdc(k) And then, acquiring a peak point k on the correlation curve, and selecting at least two points near the position of the peak point k. Preferably, the two points k-1 and k +1 are located on either side of the peak point k.
In phaseAfter three points k, k-1 and k +1 are selected on the curve, the estimation value of a first model is calculated, and the estimation value of the first model
The calculation formula of (2) is as follows:
(D) performing Hilbert transform on the frequency spectrum of the cross-correlation curve, taking an imaginary part, and calculating by using a linear interpolation function to obtain an estimated value of a model II;
by means of the hilbert conversion, the generated signal lags behind the pi/2 phase of the original signal, and the magnitude relation between the real value and the sampling value is kept. This produces a positive result, near the peak, model one and model two form the estimate conjugate.
Specifically, H (w) obtained by performing hilbert transform on the frequency spectrum F (k) of the cross-correlation curve is:
H(w)=(-i·sgn(w))·F(w)
wherein w is the angular frequency after fourier transform. Then, taking the imaginary part of H (w)
Searching points m, m-1 and m +1 corresponding to points k, k-1 and k +1 in a curve after Hilbert transform, wherein the time corresponding to the point k is the same as that of the point m, the time corresponding to the point k-1 is the same as that of the point m-1, and the time corresponding to the point k +1 is the same as that of the point m + 1;
then, according to the estimated value of the model two
The calculation formula of (2) is as follows:
(E) And calculating to obtain an estimated value of the model combination according to the estimated value of the first model and the estimated value of the second model.
Estimation value according to model one
And the estimated value of model two
Calculating an estimate of a combination of models
Wherein, w
1(t) and w
2(t) weights for model one and model two, respectively. w is a
1(t) and w
2The value of (t) can be adjusted according to the specific application scene to adjust the weight of the combined model, and further approaches to a true value. In some embodiments, w
1(t)=w
2(t)=0.5。
Further, when the sampling frequency of the transducer of the ultrasonic gas meter is 6-10 times of the center frequency of the transducer, the estimated value is closer to the true value, and in some embodiments, the sampling frequency of the ultrasonic transducer is 8 times of the center frequency.
(F) If the estimated value obtained in the step (E) is more than or equal to one sampling period, taking the estimated value as the estimated value of the flight time; if the estimated value obtained in the step (E) is less than one sampling period and more than or equal to 1/50 sampling period, carrying out frequency domain iterative calculation until the error meets the requirement; and (E) if the estimated value obtained in the step (E) is less than 1/50 of the sampling period, reducing the wave number and then repeating the steps (A) - (E) for calculation.
In the step (F), the estimated value calculated in the step (E) is compared with the sampling period to determine whether to use the estimated value as an estimated value of the time of flight or to perform subsequent calculation. Wherein, the sampling period refers to the sampling period of the ADC.
The comparison result of the estimated value and the sampling period in the step (E) includes the following three cases:
the first case is: the calculated estimate is greater than or equal to one sampling period. In this case, the estimated value is an estimated value of the time of flight.
The second case is: the calculated estimate is less than one sample period but greater than or equal to 1/50 sample period. In this case, the estimated value is iteratively calculated in the frequency domain until the error of the iterative calculation meets the requirement.
The third case is: the calculated estimated value is less than 1/50 of the sampling period. In this case, steps (A) to (E) are repeated after reducing the number of waves to calculate the estimated value.
Further, for the second case, the calculation method specifically includes the following steps:
(F1) constructing a Lagrange fractional delay filter, and calculating a filter difference coefficient of the delay filter;
to simplify the formula, let
And after a hyperparameter M of the finite impulse filter is given, a filter difference coefficient h
D(f)Comprises the following steps:
in the above formula, M is divided into two parts, M1 and M2, when M is an even number, M1 is M2 is M/2, when M is an odd number, M1 is (M-1)/2, M2 is (M +1)/2, and f is the number of iterations.
(F2) Calculating a true estimate and an error of the delay filter;
combining the fly-up signal as s according to the Lagrangian delay filter constructed in the step (F1)1(n) and a down flight signal s2(n) calculating a true estimate s under the delay filter2(n-D (f)) and an error E (n), wherein:
E(n)=s1(n)-s2(n-D(n))
in some embodiments, the iteration error E (n) cannot exceed three thousandths.
(F3) If the error meets the requirement, the calculation is terminated, if the error does not meet the requirement, the estimated value is adjusted, and then the step (F1) is returned to for recalculation until the error meets the requirement.
In this step, the adjustment formula of the estimated value is as follows:
where u is the learning step factor, preferably 0.5.
Further, for the third case, the calculation method is: and (4) taking three waves near the maximum value of the upper flight signal and the lower flight signal to replace the original upper flight signal and lower flight signal, and repeating the steps (A) - (E) to calculate an estimated value.
The principle of the invention is as follows:
(1) constructing two conjugated models in a time domain, inhibiting errors through a model combination formed by a model I and a model II, and performing lower estimation on two pairs of real values of the models when the two pairs of real values of the models are subjected to upper estimation and vice versa;
(2) when the real time delay is more than or equal to 1 sampling period, the error of the conjugate model estimation can be ignored; when the real time delay is larger than or equal to 1/50 sampling period, the adaptive fractional delay filtering estimated value is close to the conjugate model, the estimated value of the conjugate model is used as an initial value, the iteration times can be reduced, and the iteration result is close to the global optimum value;
(3) the large error caused by the instability of the transducer mainly occurs under the extremely low air volume, and only the strongest part of the signal is used by the wave reduction method to suppress the error.
Compared with the prior art, the invention has the following advantages and beneficial effects:
1. the invention relates to a pair of conjugate estimation models to inhibit errors caused by prior distribution hypothesis, and can obtain good accuracy for small flow estimation in a time domain or a wave number domain, and the stability of a calculation result is high;
2. in the invention, when the real time delay is more than or equal to 1 sampling period, the estimation error of the conjugate model can be ignored, and when the real time delay is more than or equal to 1/50 sampling period and less than 1 sampling period, the self-adaptive fractional delay filtering estimation value is close to the conjugate model, the estimation value of the conjugate model is used as an initial value, the iteration times can be reduced, and the iteration result approaches to the global optimum value.
Drawings
The accompanying drawings, which are included to provide a further understanding of the embodiments of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the principles of the invention. In the drawings:
FIG. 1 is a block diagram of a computing flow in an embodiment of the invention;
FIG. 2 is a schematic diagram of estimated samples of a model one according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of estimated samples of a second model according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of the estimation principles of model one and model two according to an embodiment of the present invention;
FIG. 5 is a time difference average calculated at high temperature, normal temperature, and low temperature under the condition of zero gas amount in the embodiment of the present invention;
fig. 6 shows an error comparison between the estimated value obtained by the existing time domain estimation method and the calculation method disclosed by the present invention and the true value under the micro-air volume and normal temperature conditions in the embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to examples and accompanying drawings, and the exemplary embodiments and descriptions thereof are only used for explaining the present invention and are not meant to limit the present invention.
In the description of the present invention, it is to be understood that the terms "front", "rear", "left", "right", "upper", "lower", "vertical", "horizontal", "high", "low", "inner", "outer", etc. indicate orientations or positional relationships based on those shown in the drawings, and are only for convenience of description and simplicity of description, and do not indicate or imply that the referenced devices or elements must have a particular orientation, be constructed and operated in a particular orientation, and therefore, are not to be construed as limiting the scope of the present invention.
Further, the term "connected" used herein may be either directly connected or indirectly connected via other components without being particularly described.
Example 1:
the measurement algorithm for the flow rate of the ultrasonic gas meter shown in fig. 1 to 4 comprises the following steps:
(A) inputting an upward flight signal and a downward flight signal, and respectively performing Fourier transform on the upward flight signal and the downward flight signal;
the purpose of the fourier transform is to convert the original time domain signal into the wavenumber domain, obtain the respective frequency spectrum, and facilitate the calculation of the cross-correlation curve.
(B) Calculating to obtain the frequency spectrum of the cross-correlation curve according to the Fourier transform results of the upper flight signal and the lower flight signal;
the convolution process of the cross-correlation curve in the time domain is equivalent to the multiplication process in the wavenumber domain. The cross-correlation curve calculation is performed to perform noise suppression by taking advantage of the uncorrelated relationship between white gaussian noise generated by the transducer and the desired signal.
(C) Performing inverse Fourier transform on the frequency spectrum of the cross-correlation curve to obtain a correlation curve, searching for a peak point position and at least two points adjacent to the peak point position on the correlation curve through a maximum value, and calculating by using a time domain estimation function to obtain an estimation value of a first model;
(D) performing Hilbert transform on the frequency spectrum of the cross-correlation curve, taking an imaginary part, and calculating by using a linear interpolation function to obtain an estimated value of a model II;
by means of the hilbert conversion, the generated signal lags behind the pi/2 phase of the original signal, and the magnitude relation between the real value and the sampling value is kept. This produces a positive result, near the peak, model one and model two form the estimate conjugate.
(E) And calculating to obtain an estimated value of the model combination according to the estimated value of the first model and the estimated value of the second model.
(F) If the estimated value obtained in the step (E) is more than or equal to one sampling period, taking the estimated value as the estimated value of the flight time; if the estimated value obtained in the step (E) is less than one sampling period and more than or equal to 1/50 sampling period, carrying out frequency domain iterative calculation until the error meets the requirement; and (E) if the estimated value obtained in the step (E) is less than 1/50 of the sampling period, reducing the wave number and then repeating the steps (A) - (E) for calculation.
Example 2:
in step (A), an up-flight signal s is obtained in accordance with example 11(n) and a down flight signal s2(n) Fourier transform to obtain F1(k) And F2(k) Wherein:
where k is 0,1,2, …, N-1, N is 0,1,2, …, N-1, N is the extended sequence length, and j is an imaginary unit.
Then, in step (B), the frequency spectrum F (k) of the cross-correlation curve is F1(k)·F2(k)。
In step (C), the correlation curve Rdc(k) Calculated by the following formula:
as shown in fig. 2, a peak point k is obtained on the correlation curve, and two points k-1 and k +1 are respectively selected on two sides adjacent to the peak point k. After three points are determined, the estimated value of the first model
The calculation formula of (2) is as follows:
in the step (D), the imaginary part obtained by subjecting the frequency spectrum F (k) of the cross-correlation curve to Hilbert transform
The following equation is used to obtain:
H(w)=(-i·sgn(w))·F(w)
wherein w is the angular frequency after fourier transform.
As shown in FIG. 3, points m, m-1 and m +1 corresponding to points k, k-1 and k +1 are searched in the curve after Hilbert transform, wherein the time corresponding to the point k is the same as that of the point m, the time corresponding to the point k-1 and the point m-1 is the same, and the time corresponding to the point k +1 and the point m +1 is the same.
Three are determinedEstimate of model two after points m, m-1, and m +1
The calculation formula of (2) is as follows:
In step (E), the estimated values of the model combinations
Wherein the content of the first and second substances,
is an estimate of the value of the first model,
is an estimate of model two, w
1(t) and w
2(t) weights for model one and model two, respectively.
In some embodiments, w1(t)=w2(t)=0.5。
In some embodiments, when the sampling frequency of the transducer of the ultrasonic gas meter is 6 to 10 times of the center frequency thereof, the estimated value is closer to the true value, and preferably, the sampling frequency of the ultrasonic transducer is 8 times of the center frequency.
And (F) comparing the estimated value obtained in the step (E) with the sampling period to judge whether the estimated value is used as the estimated value of the flight time or to perform subsequent calculation. Wherein, the sampling period refers to the sampling period of the ADC.
The comparison result of the estimated value and the sampling period in the step (E) includes the following three cases:
the first case is: the calculated estimate is greater than or equal to one sampling period. In this case, the estimated value is an estimated value of the time of flight.
The second case is: the calculated estimate is less than one sample period but greater than or equal to 1/50 sample period. In this case, the estimated value is iteratively calculated in the frequency domain until the error of the iterative calculation meets the requirement.
The third case is: the calculated estimated value is less than 1/50 of the sampling period. In this case, steps (A) to (E) are repeated after reducing the number of waves to calculate the estimated value.
Further, for the second case, the calculation method specifically includes the following steps:
(F1) constructing a Lagrange fractional delay filter, and calculating a filter difference coefficient of the delay filter;
to simplify the formula, let
And after a hyperparameter M of the finite impulse filter is given, a filter difference coefficient h
D(f)Comprises the following steps:
in the above formula, M is divided into two parts, M1 and M2, when M is an even number, M1 is M2 is M/2, when M is an odd number, M1 is (M-1)/2, M2 is (M +1)/2, and f is the number of iterations.
(F2) Calculating a true estimate and an error of the delay filter;
combining the fly-up signal as s according to the Lagrangian delay filter constructed in the step (F1)1(n) and a down flight signal s2(n) calculating theTrue estimate s under delay filter2(n-D (f)) and an error E (n), wherein:
E(n)=s1(n)-s2(n-D(n))
in some embodiments, the iteration error E (n) cannot exceed three thousandths.
(F3) If the error meets the requirement, the calculation is terminated, if the error does not meet the requirement, the estimated value is adjusted, and then the step (F1) is returned to for recalculation until the error meets the requirement.
In this step, the adjustment formula of the estimated value is as follows:
where u is the learning step factor, preferably 0.5.
Further, for the third case, the calculation method is: and (4) taking three waves near the maximum value of the upper flight signal and the lower flight signal to replace the original upper flight signal and lower flight signal, and repeating the steps (A) - (E) to calculate an estimated value.
The technical scheme relates to a pair of conjugate estimation models to inhibit errors caused by prior distribution hypothesis, can obtain good accuracy for small flow estimation in a time domain or a wave number domain, and has high stability of a calculation result.
Example 3:
on the basis of examples 1 and 2, the calculation was carried out by substituting the specific numerical values into the above formula.
Zero gas volume case: in the case of zero air amount, the high temperature (55 ℃) data 421 groups 117870, the low temperature (-15 ℃) data 467 groups 13076 and the normal temperature (20 ℃) data 432 groups 120960. Under three temperature conditions, the estimated time difference average values calculated by the formula are-0.3062 ns, 0.1763ns and 0.1187ns respectively, and the mean square error is 0.4667ns, 0.6078ns and 0.2769 ns. As shown in fig. 5, the time difference average is close to 0ns with strong consistency in the three temperature cases. The mean square error is slightly amplified at high and low temperatures, but is in the range of ± 2ns overall.
Micro-air volume condition: the average gas volume is 13L/h at normal temperature, and the gas volume is disturbed, and 100 groups of 28000 data are calculated by a time domain estimation method and the calculation method disclosed by the invention respectively, and signal recovery is carried out by the Nyquist sampling theorem to be used as a true value. As shown in fig. 6, under the conditions of minute volume and normal temperature, the time domain estimation method and the true value have large errors, and the error between the estimated value and the true value obtained by using the lagrangian fractional delay filter disclosed by the present invention is significantly reduced.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are merely exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.