Capacitive liquid level sensor temperature compensation method based on improved BP neural network
Through the improved BP neural network method, combined with PSO and GA algorithms to optimize weights and thresholds, the dielectric constant in the liquid level sensor is corrected, and the temperature drift problem of the liquid level sensor when temperature changes is solved, significantly improving the temperature compensation accuracy.
Patent Information
- Application Number
- CN202510063444.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2045-01-15
AI Technical Summary
The existing liquid level sensors have temperature drifting when the ambient temperature changes, resulting in measurement errors. The traditional temperature compensation method ignores the influence of the dielectric constant and lacks accuracy.
Using the improved BP neural network method, the dielectric constant is corrected to achieve more accurate temperature compensation by constructing a BP neural network that fits the relative dielectric constant of air and water, and combining PSO and GA algorithms to optimize weights and thresholds.
By fully considering the influence of ambient temperature on the dielectric constant, the temperature compensation accuracy of the liquid level sensor is significantly improved and the measurement error is reduced.
Smart Images

Figure CN119962384A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of sensor temperature compensation, and in particular to a temperature compensation method for a capacitive liquid level sensor based on an improved BP neural network. Background Art
[0002] In the industrial field, accurate liquid level measurement is very important, which has promoted the development and widespread application of various technologies. However, when the ambient temperature changes greatly, the liquid level sensor will have obvious temperature drift, resulting in measurement errors of the liquid level sensor. Therefore, it is necessary to perform temperature compensation on the liquid level sensor to ensure high-precision measurement of the sensor.
[0003] In the prior art, commonly used temperature compensation methods include hardware compensation and software compensation. Hardware compensation methods include line compensation method, bridge compensation method, etc. In practical applications, hardware compensation has the disadvantages of complex circuits, poor versatility, difficult debugging, and high cost, which is not conducive to engineering applications. Software compensation methods include least squares method, multivariate regression, neural network method, etc. In the actual model, the temperature affects the dielectric constant of the liquid and air in the capacitive liquid level sensor, which causes its output capacitance to change, making the liquid level inaccurate. The traditional temperature compensation model obtains the compensated liquid level by inputting temperature data and the liquid level data to be compensated, which is equivalent to directly finding the relationship between temperature and sensor liquid level, while ignoring the influence of the intermediate variable dielectric constant, which leads to the problem of insufficient compensation accuracy. Summary of the invention
[0004] The present invention provides a temperature compensation method for a capacitive liquid level sensor based on an improved BP neural network to overcome the above technical problems.
[0005] In order to achieve the above object, the technical solution of the present invention is:
[0006] A temperature compensation method for a capacitive liquid level sensor based on an improved BP neural network specifically comprises the following steps:
[0007] S1: Establish a capacitance output model of a capacitive liquid level sensor for temperature compensation based on relative dielectric constant, and the relative dielectric constant includes the relative dielectric constant of air and the relative dielectric constant of water affected by temperature;
[0008] S2: Based on the capacitance output model of the capacitive liquid level sensor, the relative dielectric constants of air and water of the capacitive liquid level sensor under different ambient temperature conditions are obtained according to different liquid level values as sample data;
[0009] And randomly divide the sample data into a sample training set and a sample test set;
[0010] S3: Constructing the temperature compensation BP neural network of capacitive liquid sensor;
[0011] The temperature compensation BP neural network includes a first BP neural network for fitting the relative dielectric constant of air and a second BP neural network for fitting the relative dielectric constant of water;
[0012] S4: optimizing the initial weights and thresholds of the temperature compensation BP neural network according to the sample training set and the sample test set to obtain the optimized temperature compensation BP neural network;
[0013] Optimizing the initial weights and thresholds includes:
[0014] Based on the PSO algorithm, the initial weights and thresholds of the first BP neural network are optimized and fitted; based on the GA algorithm, the initial weights and thresholds of the second BP neural network are optimized and fitted;
[0015] S5: Based on the optimized temperature compensation BP neural network, the temperature compensation of the capacitive liquid level sensor under different ambient temperatures is realized.
[0016] Furthermore, the random division into a sample training set and a sample test set includes:
[0017] including a first sample training set based on ambient temperature, air relative dielectric constant, and liquid level value;
[0018] A second sample training set based on ambient temperature, relative dielectric constant of water, and liquid level value;
[0019] A first sample test set based on ambient temperature, relative permittivity of air, and liquid level values;
[0020] A second sample test set based on ambient temperature, relative permittivity of water, and liquid level values.
[0021] Furthermore, the first BP neural network constructed in S2 has the same structure as the second BP neural network, including an input layer, at least one hidden layer, and an output layer connected in sequence;
[0022] And the input layer includes a temperature input layer and a dielectric constant input layer;
[0023] The temperature input layer is used to input the acquired ambient temperature of the capacitive liquid level sensor into the hidden layer;
[0024] The dielectric constant input layer is used to input the relative dielectric constant of the capacitive liquid level sensor capacitance output model into the hidden layer;
[0025] The hidden layer is used to perform nonlinear fitting operation on the input of the temperature input layer and the input of the dielectric constant input layer;
[0026] The output layer is used to obtain the liquid level value of the capacitive liquid level sensor according to the output of the hidden layer.
[0027] Furthermore, in S4, based on the Adam optimization algorithm, the initial weights and thresholds of the temperature compensation BP neural network are optimized according to the sample training set and the sample test set to obtain the optimized temperature compensation BP neural network, specifically:
[0028] S41: taking the ambient temperature and the relative dielectric constant of air as input data, and taking the liquid level value of the capacitive liquid level sensor as output data;
[0029] The initial weight and threshold of the first BP neural network are defined as the encoding information of the individual particles in the population to obtain the initial particle population of the PSO algorithm;
[0030] S42: Based on the population particle algorithm, according to the first sample training set combined with the initial particle population, the first BP neural network is trained to obtain a trained first BP neural network;
[0031] S43: Testing the trained first BP neural network using the first sample test set:
[0032] If the output of the trained first BP neural network converges or reaches a preset number of training iterations, the trained first BP neural network is the optimal first BP neural network;
[0033] Otherwise, the particle position and velocity are updated by using the particle position update formula and the weighted velocity update formula, and step S42 is repeated;
[0034] S44: taking the ambient temperature and the relative dielectric constant of water as input data, and taking the liquid level value of the capacitive liquid level sensor as output data;
[0035] The initial weight and threshold of the second BP neural network are defined as the encoding information of the population individuals to obtain the initial population of the GA algorithm;
[0036] S45: Based on the GA algorithm, according to the second sample training set and the initial population, the second BP neural network is trained to obtain a trained second BP neural network;
[0037] S46: Testing the trained second BP neural network using the second sample test set:
[0038] If the output of the trained second BP neural network converges or reaches a preset number of training iterations, the trained second BP neural network at this time is the optimal second BP neural network;
[0039] Otherwise, the population of the GA algorithm is sorted in descending order according to fitness to obtain a fitness sequence table;
[0040] And according to the preset fitness threshold, the population of the GA algorithm is divided into a first segmentation population that meets the preset fitness threshold and a second segmentation population that does not meet the preset fitness threshold according to the fitness sequence table;
[0041] By performing crossover / mutation operations on the second split population, an optimized population is obtained;
[0042] The optimized population is merged with the first segmented population to obtain a new population, and the new population is used as the initial population, and step S45 is repeated.
[0043] Furthermore, the particle position update formula and the weighted velocity update formula in S43 are expressed as follows:
[0044] v i (k+1)=ω·v i (k)+c1·r1·[P best·i -x i (k)]+c2·r2·[G best -x i (k)]
[0045] x i (k+1)=x i (k)+v i (k+1)
[0046] Where: v i (k+1) and x i (k+1) represent the velocity and position of particle i in the k+1th iteration respectively; v i (k) and x i (k) represent the velocity and position of particle i in the kth iteration respectively; P best·i represents the individual extreme value of particle i in the current iteration; G best represents the global extreme value of the particle population; c1 and c2 represent learning factors; ω represents the inertia weight; r1 and r2 represent random numbers in [0,1].
[0047] Furthermore, it is determined whether the first BP neural network or the second BP neural network after training outputs a converged fitness function, i.e., a loss function, which is expressed as
[0048]
[0049] Where: E represents the mean square error between the actual liquid level value and the liquid level value calculated by the formula of the compensated relative dielectric constant output by the network; N represents the number of samples in the test set, h i represents the dielectric constant output by the BP neural network of the i-th test sample, and the liquid level value of the capacitive liquid level sensor is obtained, h' iis the actual liquid level value of the i-th test sample.
[0050] Furthermore, the capacitance output model of the capacitive liquid level sensor established in S1 is expressed as follows:
[0051]
[0052] Where: C p Represents the overall output capacitance of the capacitive liquid level sensor; C a Indicates the capacitance of the capacitive liquid level sensor above the liquid level with air as the medium; C w Indicates the capacitance below the liquid level with liquid as the medium; C F,a Indicates the capacitance in the air when the insulating sheath is used as the medium; while the capacitance in the liquid is C F,w Indicates the capacitance in the liquid when the insulating sheath is used as the medium; C 01 With C 02 They represent the additional capacitance of the capacitive liquid level sensor caused by the edge effect at the bottom of the inner and outer electrodes; R1 represents the design parameter of the inner electrode outer diameter; R3 represents the design parameter of the outer electrode inner diameter; R2 represents the design parameter of the outer diameter of the insulating sheath; H represents the distance between the inner electrode and the bottom of the outer electrode; h0 represents the total length of the container of the capacitive liquid level sensor; h represents the height of the liquid level in the container; H1 represents the length of the inner electrode immersed in the liquid; h1 represents the height of the air part above the liquid surface and h1=h0-h; ε0 represents the dielectric constant of an ideal vacuum; ε a Represents the relative dielectric constant of air; ε w Represents the relative dielectric constant of water; ε F Represents the relative dielectric constant of the insulating medium; C0 represents the capacitance of the bottom edge space of the capacitive liquid level sensor; ε e Represents the equivalent dielectric constant of the insulating medium and liquid in the edge space.
[0053] Beneficial effects: The present invention provides a temperature compensation method for a capacitive liquid level sensor based on an improved BP neural network. Compared with the traditional method of directly performing temperature compensation, the present invention corrects the relative dielectric constant of air and the relative dielectric constant of water respectively by constructing a first BP neural network that fits the relative dielectric constant of air and a second BP neural network that fits the relative dielectric constant of water to confirm the liquid level data after temperature compensation of the capacitive liquid level sensor. By fully considering the influence of ambient temperature on the dielectric constant of the intermediate variable, the temperature compensation accuracy is greatly improved. At the same time, considering the characteristics of the air dielectric constant and the relative dielectric constant of water changing with temperature, the PSO algorithm and the GA algorithm are respectively used to optimize the weights and thresholds of the BP neural network of the dielectric constants of air and water. That is, since the value of the relative dielectric constant of air does not change much with temperature, the PSO is directly optimized in the local area, avoiding the problem of being easily trapped in the local optimum; and since the relative dielectric constant of water decreases with the increase of temperature, the GA algorithm is used to enhance the global search capability to determine the solution space, which greatly improves the accuracy and efficiency of temperature compensation of the capacitive liquid level sensor. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0055] Figure 1 It is a flow chart of the temperature compensation method of the capacitive liquid level sensor based on the improved BP neural network of the present invention;
[0056] Figure 2 Schematic diagram of the structure of the capacitive liquid level sensor in this embodiment;
[0057] Figure 3 : is the topological diagram of the temperature compensation BP neural network in this embodiment;
[0058] Figure 4 This is a flowchart of the optimization of the PSO algorithm for the BP neural network weights and thresholds in this embodiment;
[0059] Figure 5 This is a flowchart of optimizing the BP neural network weights and thresholds using the GA algorithm in this embodiment. DETAILED DESCRIPTION
[0060] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0061] This embodiment provides a temperature compensation method for a capacitive liquid level sensor based on an improved BP neural network. Figure 1 As shown, the specific steps include:
[0062] S1: Establish a capacitance output model of a capacitive liquid level sensor for temperature compensation based on relative dielectric constant, and the relative dielectric constant includes the relative dielectric constant of air and the relative dielectric constant of water affected by temperature;
[0063] Specifically, the capacitance output model of the capacitive liquid level sensor is established, and its expression is:
[0064]
[0065] Where: C p Represents the overall output capacitance of the capacitive liquid level sensor; C a Indicates the capacitance of the capacitive liquid level sensor above the liquid level with air as the medium; C w Indicates the capacitance below the liquid level with liquid as the medium; C F,a Indicates the capacitance in the air when the insulating sheath is used as the medium; while the capacitance in the liquid is C F,w Indicates the capacitance in the liquid when the insulating sheath is used as the medium; C 01 With C 02 They represent the additional capacitance of the capacitive liquid level sensor caused by the edge effect at the bottom of the inner and outer electrodes; R1 represents the design parameter of the outer diameter of the inner electrode, such as Figure 2 As shown, 1 represents the outer diameter of the inner electrode J; 2 represents the insulating sheath; 3 represents the outer electrode K; 4 represents the solution; and the inner electrode J is a solid stainless steel round tube with an outer diameter of 2R1; R3 represents the design parameter of the inner diameter of the outer electrode, and the outer electrode K is a hollow stainless steel round tube with an inner diameter of 2R3; R2 represents the design parameter of the outer diameter of the insulating sheath, and the outer diameter of the insulating sheath is 2R2; H represents the distance between the inner electrode and the bottom of the outer electrode; h0 represents the total length of the capacitive liquid level sensor container; h represents the liquid level height in the container; H1 represents that the inner electrode is long enough to extend out of the top of the container and the length of the inner electrode immersed in the liquid; h1 represents the height of the air part above the liquid surface and h1=h0-h; ε0 represents the dielectric constant of an ideal vacuum; ε a Represents the relative dielectric constant of air; εw Represents the relative dielectric constant of water; ε F represents the relative dielectric constant of the insulating medium; C0 represents the capacitance of the bottom edge space of the capacitive liquid level sensor obtained by finite element analysis, wherein the method for implementing the capacitance of the bottom edge space of the capacitive liquid level sensor obtained by finite element analysis is a known technical means, which is not the invention of the present application and will not be described in detail here; ε e Represents the equivalent dielectric constant of the insulating medium and liquid in the edge space;
[0066] S2: Based on the capacitance output model of the capacitive liquid level sensor, the relative dielectric constants of air and water of the capacitive liquid level sensor under different ambient temperature conditions are obtained according to different liquid level values as sample data;
[0067] And randomly divide the sample data into a sample training set and a sample test set;
[0068] Specifically, the random division into a sample training set and a sample test set includes:
[0069] including a first sample training set based on ambient temperature, air relative dielectric constant, and liquid level value;
[0070] A second sample training set of ambient temperature, relative dielectric constant of water, and liquid level values;
[0071] A first sample test set regarding ambient temperature, relative permittivity of air, and liquid level values;
[0072] A second sample test set regarding ambient temperature, relative permittivity of water, and liquid level values;
[0073] In this embodiment, considering the different degrees of influence of ambient temperature on the intermediate variable dielectric constant, the sample data are divided into two types of data sets, so that the influence of different dielectric constants on the temperature compensation of the capacitive liquid level sensor can be fully considered in the subsequent BP neural network training to improve the temperature compensation accuracy; wherein, due to the vacuum dielectric constant ε0 and the relative dielectric constant ε0 of the insulating medium in the capacitance output model of the capacitive liquid level sensor, the temperature compensation accuracy of the capacitive liquid level sensor is improved. F It is not affected by temperature, so only the relative dielectric constant of air and the relative dielectric constant of water affected by ambient temperature are considered;
[0074] S3: Constructing the temperature compensation BP neural network of capacitive liquid sensor;
[0075] The temperature compensation BP neural network includes a first BP neural network for fitting the relative dielectric constant of air and a second BP neural network for fitting the relative dielectric constant of water;
[0076] Specifically, Figure 3As shown, the structure of the first BP neural network constructed is the same as that of the second BP neural network, including an input layer, at least one hidden layer and an output layer connected in sequence;
[0077] And the input layer includes a temperature input layer and a dielectric constant input layer;
[0078] The temperature input layer is used to input the acquired ambient temperature of the capacitive liquid level sensor into the hidden layer;
[0079] The dielectric constant input layer is used to input the relative dielectric constant of the capacitive liquid level sensor capacitance output model into the hidden layer;
[0080] The hidden layer is used to perform nonlinear fitting operation on the input of the temperature input layer and the input of the dielectric constant input layer;
[0081] The output layer is used to obtain the liquid level value of the capacitive liquid level sensor according to the output of the hidden layer.
[0082] In this embodiment, the BP neural network topology structure is determined, that is, according to the actual needs of the temperature compensation of the capacitive liquid level sensor, the number of nodes in the input layer and output layer of the BP neural network, the number of nodes in the hidden layer, and the number of hidden layers is selected as one layer to realize any nonlinear fitting, wherein the sigmoid activation function is also selected after the input layer to activate the output data, which is conducive to controlling the signal within a valid range; the purelin function is selected after the hidden layer to perform identity mapping processing on the output of the hidden layer to ensure the possibility of various values of the output signal, wherein the confirmation formula of the number of hidden layer nodes is:
[0083]
[0084] Where: p represents the number of hidden layer nodes; p in With p out Respectively represent the number of nodes in the input layer and the output layer; c represents a constant between 1 and 10 selected according to experience;
[0085] S4: Based on the Adam optimization algorithm, the initial weights and thresholds of the temperature compensation BP neural network are optimized according to the sample training set and the sample test set to obtain the optimized temperature compensation BP neural network;
[0086] In this embodiment, since it is known from experience that the relative dielectric constant of air is less affected by temperature changes, while the relative dielectric constant of water is more affected by temperature changes, and its value decreases when the temperature rises, the PSO algorithm can be used to optimize the BP neural network that fits the relative dielectric constant of air, and the GA algorithm can be used to optimize the BP neural network that fits the relative dielectric constant of water;
[0087] Optimizing the initial weights and thresholds includes:
[0088] Based on the PSO algorithm, the initial weights and thresholds of the first BP neural network are optimized and fitted; based on the GA algorithm, the initial weights and thresholds of the second BP neural network are optimized and fitted;
[0089] Among them, the particle swarm optimization (PSO) algorithm is an intelligent optimization algorithm that simulates the foraging behavior of bird flocks or fish schools. It iteratively searches the position and speed of particles in D-dimensional space to find the global optimal solution; the genetic algorithm (GA) algorithm can conduct extensive searches in the solution space through operations such as selection, crossover, and mutation, and has strong global search capabilities;
[0090] The specific steps include:
[0091] S41: taking the ambient temperature and the relative dielectric constant of air as input data, and taking the liquid level value of the capacitive liquid level sensor as output data; and defining the initial weight and threshold of the first BP neural network as the encoding information of the individual particles of the population, so as to obtain the initial particle population of the PSO algorithm;
[0092] In a specific embodiment, Figure 4 As shown in the figure, the initial weights and thresholds of the first BP neural network are represented as a D-dimensional vector, which is the encoding information of the individual particle swarm. That is, one encoding information contains all weights and thresholds of the entire BP neural network, that is, one particle individual. Before using the swarm particle algorithm, it also includes initializing PSO parameters, that is, setting the number of individual particles in the particle swarm, the maximum number of iterations T, and the upper and lower limits of the position of the particle swarm x. max With x min , the particle speed upper and lower limits v max With v min , learning factors c1 and c2, inertia weight ω, and the particle position is set randomly. Since the relative dielectric constant of air does not change much, a smaller particle speed is set according to the empirical value;
[0093] S42: Based on the population particle algorithm, according to the first sample training set combined with the initial particle population, the first BP neural network is trained to obtain a trained first BP neural network;
[0094] S43: Testing the trained first BP neural network using the first sample test set:
[0095] If the output of the trained first BP neural network converges or reaches a preset number of training iterations, the trained first BP neural network is the optimal first BP neural network;
[0096] Otherwise, the particle position and velocity are updated by using the particle position update formula and the weighted velocity update formula, and step S42 is repeated;
[0097] Specifically, the particle position update formula and the weighted velocity update formula are expressed as: i (k+1)=ω·v i (k)+c1·r1·[P best·i -x i (k)]+c2·r2·[G best -x i (k)]
[0098] x i (k+1)=x i (k)+v i (k+1)
[0099] Where: v i (k+1) and x i (k+1) represent the velocity and position of particle i in the k+1th iteration respectively; v i (k) and x i (k) represent the velocity and position of particle i in the kth iteration respectively; P best·i represents the individual extreme value of particle i in the current iteration; G best represents the global extreme value of the particle population; c1 and c2 represent learning factors; ω represents inertia weight; r1 and r2 represent random numbers in [0,1];
[0100] S44: taking the ambient temperature and the relative dielectric constant of water as input data, and taking the liquid level value of the capacitive liquid level sensor as output data; and defining the initial weight and threshold of the second BP neural network as the encoding information of the population individuals to obtain the initial population of the GA algorithm;
[0101] In a specific embodiment, Figure 5 As shown, before using the GA algorithm, at least the GA parameters need to be initialized, the number of individuals in the population needs to be set, and the maximum number of iterations needs to be set.
[0102] S45: Based on the GA algorithm, according to the second sample training set and the initial population, the second BP neural network is trained to obtain a trained second BP neural network;
[0103] S46: Testing the trained second BP neural network using the second sample test set:
[0104] If the output of the trained second BP neural network converges or reaches a preset number of training iterations, the trained second BP neural network at this time is the optimal second BP neural network;
[0105] Otherwise, the population of the GA algorithm is sorted in descending order according to fitness to obtain a fitness sequence table;
[0106] According to the preset fitness threshold, the population of the GA algorithm is divided into a first segmentation population G1 that meets the preset fitness threshold and a second segmentation population G2 that does not meet the preset fitness threshold according to the fitness sequence table;
[0107] By performing crossover / mutation operations on the second segmented population G2, an optimized population is obtained;
[0108] The optimized population is merged with the first segmented population G1 to obtain a new population, and the new population is used as the initial population, and step S45 is repeated;
[0109] The re-merging is to randomly mix the optimized population with the first segmented population G1;
[0110] S5: Based on the optimized temperature compensation BP neural network, the temperature compensation of the capacitive liquid level sensor under different ambient temperatures is realized.
[0111] In a specific embodiment, it is determined whether the first BP neural network or the second BP neural network after training outputs a converged fitness function, that is, a loss function, which is expressed as:
[0112]
[0113] Where: E represents the mean square error between the actual liquid level value and the liquid level value calculated by the formula of the compensated relative dielectric constant output by the network; N represents the number of samples in the test set, h i represents the dielectric constant output by the BP neural network of the i-th test sample, and the liquid level value of the capacitive liquid level sensor is obtained, h' i is the actual liquid level value of the i-th test sample.
[0114] In this embodiment, the relative dielectric constant is corrected by optimizing the temperature compensation BP neural network after training, and the corrected dielectric constant is used in the capacitance output model of the capacitive liquid level sensor to determine the liquid level value after temperature compensation. Compared with the traditional method of direct temperature compensation, this embodiment constructs a first BP neural network that fits the relative dielectric constant of air and a second BP neural network that fits the relative dielectric constant of water, and corrects the relative dielectric constant of air and water respectively to confirm the liquid level data after temperature compensation of the capacitive liquid level sensor. By fully considering the influence of ambient temperature on the intermediate variable dielectric constant, the temperature compensation accuracy is greatly improved. At the same time, considering the characteristics of the relative dielectric constant of air and water changing with temperature, the PSO algorithm and GA algorithm are used to optimize the weights and thresholds of the BP neural network of the dielectric constants of air and water, respectively. That is, since the value of the relative dielectric constant of air does not change much with temperature, the PSO algorithm is directly optimized locally, avoiding the problem of being easily trapped in the local optimum; and since the relative dielectric constant of water decreases with increasing temperature, the GA algorithm is used to enhance the global search capability to determine the solution space, which greatly improves the accuracy and efficiency of temperature compensation of the capacitive liquid level sensor.
[0115] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A temperature compensation method for a capacitive liquid level sensor based on an improved BP neural network, characterized in that: The specific steps include: S1: Establish a capacitance output model of a capacitive liquid level sensor for temperature compensation based on relative dielectric constant, and the relative dielectric constant includes the relative dielectric constant of air and the relative dielectric constant of water affected by temperature; S2: Based on the capacitance output model of the capacitive liquid level sensor, the relative dielectric constants of water and air in the corresponding capacitive liquid level sensor under different ambient temperature conditions are obtained according to different liquid level values as sample data; And randomly divide the sample data into a sample training set and a sample test set; S3: Constructing the temperature compensation BP neural network of capacitive liquid sensor; The temperature compensation BP neural network includes a first BP neural network for fitting the relative dielectric constant of air and a second BP neural network for fitting the relative dielectric constant of water; S4: Based on the Adam optimization algorithm, the initial weights and thresholds of the temperature compensation BP neural network are optimized according to the sample training set and the sample test set to obtain the optimized temperature compensation BP neural network; Optimizing the initial weights and thresholds includes: Based on the PSO algorithm, the initial weights and thresholds of the first BP neural network are optimized and fitted; Based on the GA algorithm, the initial weights and thresholds of the second BP neural network are optimized and fitted; S5: Based on the optimized temperature compensation BP neural network, the temperature compensation of the capacitive liquid level sensor under different ambient temperatures is realized.
2. According to the temperature compensation method of a capacitive liquid level sensor based on an improved BP neural network as described in claim 1, it is characterized in that: The random division into a sample training set and a sample test set includes: including a first sample training set based on ambient temperature, air relative dielectric constant, and liquid level value; A second sample training set based on ambient temperature, relative dielectric constant of water, and liquid level value; A first sample test set based on ambient temperature, relative permittivity of air, and liquid level values; A second sample test set based on ambient temperature, water relative permittivity, and liquid level values.
3. The temperature compensation method of a capacitive liquid level sensor based on an improved BP neural network according to claim 2 is characterized in that: The first BP neural network constructed in S2 has the same structure as the second BP neural network, including an input layer, at least one hidden layer and an output layer connected in sequence; And the input layer includes a temperature input layer and a dielectric constant input layer; The temperature input layer is used to input the acquired ambient temperature of the capacitive liquid level sensor into the hidden layer; The dielectric constant input layer is used to input the relative dielectric constant of the capacitive liquid level sensor capacitance output model into the hidden layer; The hidden layer is used to perform nonlinear fitting operation on the input of the temperature input layer and the input of the dielectric constant input layer; The output layer is used to obtain the liquid level value of the capacitive liquid level sensor according to the output of the hidden layer.
4. The temperature compensation method of a capacitive liquid level sensor based on an improved BP neural network according to claim 3 is characterized in that: In S4, based on the Adam optimization algorithm, the initial weights and thresholds of the temperature compensation BP neural network are optimized according to the sample training set and the sample test set to obtain the optimized temperature compensation BP neural network, specifically: S41: taking the ambient temperature and the relative dielectric constant of air as input data, and taking the liquid level value of the capacitive liquid level sensor as output data; The initial weight and threshold of the first BP neural network are defined as the encoding information of the individual particles in the population to obtain the initial particle population of the PSO algorithm; S42: Based on the population particle algorithm, according to the first sample training set combined with the initial particle population, the first BP neural network is trained to obtain a trained first BP neural network; S43: Testing the trained first BP neural network using the first sample test set: If the output of the trained first BP neural network converges or reaches a preset number of training iterations, the trained first BP neural network is the optimal first BP neural network; Otherwise, the particle position and velocity are updated by using the particle position update formula and the weighted velocity update formula, and step S42 is repeated; S44: taking the ambient temperature and the relative dielectric constant of water as input data, and taking the liquid level value of the capacitive liquid level sensor as output data; The initial weight and threshold of the second BP neural network are defined as the encoding information of the population individuals to obtain the initial population of the GA algorithm; S45: Based on the GA algorithm, according to the second sample training set and the initial population, the second BP neural network is trained to obtain a trained second BP neural network; S46: Testing the trained second BP neural network using the second sample test set: If the output of the trained second BP neural network converges or reaches a preset number of training iterations, the trained second BP neural network at this time is the optimal second BP neural network; Otherwise, the population of the GA algorithm is sorted in descending order according to fitness to obtain a fitness sequence table; And according to the preset fitness threshold, the population of the GA algorithm is divided into a first segmentation population that meets the preset fitness threshold and a second segmentation population that does not meet the preset fitness threshold according to the fitness sequence table; By performing crossover / mutation operations on the second split population, an optimized population is obtained; The optimized population is merged with the first segmented population to obtain a new population, and the new population is used as the initial population, and step S45 is repeated.
5. The temperature compensation method of a capacitive liquid level sensor based on an improved BP neural network according to claim 4 is characterized in that: The particle position update formula and weighted velocity update formula in S43 are expressed as follows: in i (k+1)=ω v i (k)+c1 r1 [P best·i -x i (k)]+c2 r2 [G best -x i (k)] x i (k+1)=x i (k)+v i (k+1) Where: v i (k+1) and x i (k+1) represent the velocity and position of particle i in the k+1th iteration respectively; v i (k) and x i (k) represent the velocity and position of particle i in the kth iteration respectively; P best·i represents the individual extreme value of particle i in the current iteration; G best represents the global extreme value of the particle population; c1 and c2 represent learning factors; ω represents the inertia weight; r1 and r2 represent random numbers in [0,1].
6. The temperature compensation method of a capacitive liquid level sensor based on an improved BP neural network according to claim 4 is characterized in that: The fitness function or loss function is used to determine whether the first BP neural network or the second BP neural network after training outputs convergence. The expression is: Where: E represents the mean square error between the actual liquid level value and the liquid level value calculated by the formula of the compensated relative dielectric constant output by the network; N represents the number of samples in the test set, h i represents the dielectric constant output by the BP neural network of the i-th test sample, and the liquid level value of the capacitive liquid level sensor is obtained, h' i is the actual liquid level value of the i-th test sample.
7. The temperature compensation method of a capacitive liquid level sensor based on an improved BP neural network according to claim 1, characterized in that: The capacitance output model of the capacitive liquid level sensor established in S1 is expressed as follows: Where: C p Represents the overall output capacitance of the capacitive liquid level sensor; C a Indicates the capacitance of the capacitive liquid level sensor above the liquid level with air as the medium; C w Indicates the capacitance below the liquid level with liquid as the medium; C F,a Indicates the capacitance in the air when the insulating sheath is used as the medium; while the capacitance in the liquid is C F,w Indicates the capacitance in the liquid when the insulating sheath is used as the medium; C 01 With C 02 They represent the additional capacitance of the capacitive liquid level sensor caused by the edge effect at the bottom of the inner and outer electrodes; R1 represents the design parameter of the inner electrode outer diameter; R3 represents the design parameter of the outer electrode inner diameter; R2 represents the design parameter of the outer diameter of the insulating sheath; H represents the distance between the inner electrode and the bottom of the outer electrode; h0 represents the total length of the container of the capacitive liquid level sensor; h represents the height of the liquid level in the container; H1 represents the length of the inner electrode immersed in the liquid; h1 represents the height of the air part above the liquid surface and h1=h0-h; ε0 represents the dielectric constant of an ideal vacuum; ε a Represents the relative dielectric constant of air; ε w Represents the relative dielectric constant of water; ε F Represents the relative dielectric constant of the insulating medium; C0 represents the capacitance of the bottom edge space of the capacitive liquid level sensor; ε e Represents the equivalent dielectric constant of the insulating medium and liquid in the edge space.
Citation Information
Patent Citations
Silicon microaccelerometer temperature compensation method and system based on GA-optimized BP neural network
CN108073075A
Roller compacted concrete compaction degree evaluation method based on GA-BP network
CN109783988A
Cited By
Multi-parameter compensation type combustible gas detection method and system based on thermal conductivity coefficient principle
CN120629281A