Optimal sampling method for electric digital power meter, power meter and device
By building an LSTM model to predict the optimal sampling point position of the electric digital power meter, the problem of not capturing the dynamic change characteristics of the power signal is solved, the measurement accuracy is improved, and the hardware cost and complexity are reduced.
Patent Information
- Application Number
- CN202411652066.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2044-11-19
AI Technical Summary
Existing digital power meters have fixed sampling points and are unable to accurately capture the dynamic changes in power signals, resulting in reduced measurement accuracy and increased hardware costs and signal processing complexity.
A neural network algorithm is used to build a sampling prediction model, and the LSTM model is used to predict the optimal sampling point position in each sampling period. The sampling point position is optimized to improve measurement accuracy and reduce hardware costs and signal processing complexity.
The measurement accuracy of the electric power digital power meter is improved, the demand for high-cost hardware such as high-speed A/D converters is reduced, the complexity of signal processing is reduced, and the overall efficiency is improved.
Smart Images

Figure CN119691636B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electric power data measurement, and specifically to an optimal sampling method for an electric power digital power meter, a power meter, and equipment. Background Art
[0002] In power systems, digital power meters, as a key measurement device, are widely used for the precise measurement and analysis of circuit parameters (such as voltage, current, and power). This measurement data plays a vital role in power system monitoring, fault diagnosis, energy efficiency assessment, and design optimization. To improve sampling accuracy, some existing digital power meters attempt to increase the number of sampling points. However, this not only increases the data processing burden but also significantly increases hardware costs, such as the use of high-speed A / D converters. The large amount of sampled data also increases the complexity of subsequent signal processing and analysis, reducing overall efficiency.
[0003] Furthermore, existing digital power meters typically use fixed sampling points for signal acquisition, a method that ignores the dynamic characteristics of power signals across different cycles. Because power signals often contain complex waveform, time, and frequency domain characteristics, fixed sampling points may not accurately capture key signal features, resulting in reduced measurement accuracy. To address this issue, we propose an optimal sampling method, power meter, and device for digital power meters. Summary of the Invention
[0004] The object of the present invention is to provide an optimal sampling method for an electric digital power meter, a power meter and a device to solve the problems raised in the above background technology.
[0005] To achieve the above object, the present invention provides the following technical solution: a method for optimizing sampling of an electric digital power meter, the method comprising the following specific steps:
[0006] Step 1: Use a neural network algorithm to build and train a sampling prediction model. The sampling prediction model is used to predict the optimal sampling point position of the power meter in each sampling period based on the power signal generated by the circuit. The specific steps of building and training the sampling prediction model include:
[0007] Step 1.1: Collect historically sampled power signal data, including time series data of voltage and current;
[0008] Step 1.2: Preprocess the collected power signal data to extract signal features. The extracted signal features include basic features of voltage and current, waveform features, time domain features, and frequency domain features. Basic features include the frequency, amplitude, and phase of the signal. Waveform features include the waveform shape, waveform symmetry, and waveform smoothness of the signal. Time domain features include the mean, variance, skewness, rise rate, and fall rate of the signal. Frequency domain features include the spectral distribution, spectral peak, and spectral width of the signal.
[0009] Step 1.3: Clean the extracted feature data to handle missing values and outliers.
[0010] Step 1.4: Standardize the cleaned feature data;
[0011] Step 1.5: Mark the optimal sampling point position of each data, and together with the corresponding feature data, form a training data set. The training data set is further divided into a training set and a validation set.
[0012] Step 1.6: Select the Long Short-Term Memory (LSTM) model to build a sampling prediction model and initialize the model parameters.
[0013] Step 1.7: Iteratively train the LSTM model using the training set data. During the training process, regularly evaluate the model performance using the validation set until the model performance meets the requirements.
[0014] Step 1.8: After training is complete, save the weights and biases of the LSTM model and deploy the model for subsequent sampling position prediction.
[0015] Step 2: Collect the time series data of voltage and current in the circuit under test in real time, and extract the basic characteristics, waveform characteristics, time domain characteristics and frequency domain characteristics of voltage and current;
[0016] Step 3: Input the signal features extracted in step 2 into the sampling prediction model trained in step 1 to obtain the optimal sampling point location list of the power meter in each sampling period;
[0017] Step 4: Apply the position list of the optimal sampling points in each sampling period obtained in step 3 to the sampling strategy of the power meter, and the power meter performs real-time sampling according to the predicted optimal sampling point positions.
[0018] Preferably, for the basic characteristics, the frequency is obtained by calculating the number of cycles of the signal in unit time; the amplitude is obtained by calculating the maximum value of the signal; and the phase is obtained by calculating the initial offset of the signal;
[0019] As for the waveform characteristics, the waveform shape is obtained by calculating the peak and valley values of the signal and the change period between the two; the waveform symmetry is obtained by comparing the similarity between the positive half-cycle and the negative half-cycle of the signal. The calculation formula is: The waveform smoothness is obtained by calculating the degree of change of the first or second derivative of the signal. The smoothness represents the average value of the rate of change of the derivative.
[0020] For time domain features, the mean is obtained by calculating the average value of all sample points of the signal. The calculation formula is: where x i is the i-th sample point of the signal, N is the total number of samples; the variance is obtained by calculating the average of the squares of the differences between all sample points of the signal and its mean, and the calculation formula is: Skewness is used to measure the direction and degree of skewness of the signal distribution. The calculation formula is: The rising rate is obtained by calculating the average slope of all rising segments in the signal. For each rising segment, the slope is where x start and x end are the starting and ending sample points of the rising segment, respectively. start and end are the serial numbers corresponding to the starting and ending sample points, respectively. The falling rate is obtained by calculating the average slope of all falling segments in the signal. For each falling segment, the slope is calculated in the same way as the rising rate, but in the opposite direction.
[0021] For frequency domain features, the spectrum distribution is converted from the time domain to the frequency domain through Fourier transform to obtain the spectrum of the signal. The calculation formula is: Where x(t) is the time domain signal, X(f) is its corresponding frequency representation, and f is the frequency; the spectrum peak is the frequency of the point with the maximum amplitude in the signal spectrum, and the calculation formula is: Spectrum peak = max f |X(f)|; Spectral width is used to measure the distribution width of the signal spectrum on the frequency axis. The calculation formula is: Spectral width = f2-f1, where f1 and f2 are the lowest and highest frequency points in the spectrum where the amplitude exceeds the threshold.
[0022] Preferably, in step 1.3, for missing values, a linear interpolation algorithm is used to fill them; for outliers, a threshold judgment method is used to regard data points that exceed the preset threshold range as outliers and replace them with the mean of their neighboring points.
[0023] Preferably, in step 1.4, the Z-score normalization method is used to subtract the mean of each eigenvalue and divide it by its standard deviation so that the processed data conforms to the standard normal distribution. The formula for the normalization process is: Where X is the original data, μ is the mean of the original data, σ is the standard deviation of the original data, and Z is the standardized data.
[0024] Preferably, the parameters for initializing the LSTM model in step 1.6 specifically include:
[0025] i) Initializing the structural parameters of the LSTM model, including the feature dimension of the input layer, the number of hidden layers and the number of hidden units in each layer, and the number of nodes in the output layer. The feature dimension of the input layer matches the number of extracted power signal features, and the number of nodes in the output layer is equal to the number of predicted optimal sampling point positions.
[0026] ii) Initialize the model weights and biases using small random numbers;
[0027] iii) Setting the activation function of the LSTM model, including setting the Sigmoid function for the gating mechanism and the Tanh function for calculating candidate memory cells and hidden states;
[0028] iv) Configure the optimization algorithm and set the learning rate parameters.
[0029] Preferably, in step 1.7, the LSTM model is iteratively trained using the training set data. In each iteration, a batch of input data is fed into the LSTM model, and the memory units and hidden states are updated by calculating the values of the input gate, forget gate, and output gate, and finally a predicted output sequence is obtained; the loss function value is calculated based on the predicted output and the true label; the gradient of the loss function with respect to the model parameters is calculated by the backpropagation algorithm; the model weights and biases are updated according to the gradient using the optimization algorithm; during the training process, the validation set is regularly used to evaluate the model performance, and the learning rate is adjusted or the training is stopped early as needed to prevent overfitting.
[0030] Preferably, a power meter comprises:
[0031] Sampling prediction module, which deploys the sampling prediction model pre-trained using the above-mentioned optimal sampling method;
[0032] Real-time data acquisition module, used to collect time series data of voltage and current in the measured circuit in real time, and extract basic characteristics, waveform characteristics, time domain characteristics and frequency domain characteristics of voltage and current;
[0033] The optimal sampling point prediction module is used to input the signal features extracted by the real-time data acquisition module into the sampling prediction model trained in the sampling prediction module to obtain the optimal sampling point position list of the power meter in each sampling period;
[0034] The sampling strategy application module is used to apply the position list of the optimal sampling points in each sampling period obtained by the optimal sampling point prediction module to the sampling strategy of the power meter, so that the power meter performs real-time sampling according to the predicted optimal sampling point positions.
[0035] Preferably, an electronic device includes a memory and a processor, wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the above-mentioned power meter optimal sampling method.
[0036] Compared with the prior art, the present invention has the following beneficial effects:
[0037] By building and training a sampling prediction model through a neural network algorithm, it is possible to predict the optimal sampling point position within each sampling cycle, thereby more accurately capturing the key features of the power signal and significantly improving the measurement accuracy of the power meter.
[0038] Because this method optimizes sampling point locations and eliminates unnecessary sampling points, it reduces the need for high-cost hardware such as high-speed A / D converters, thereby lowering overall hardware costs. By reducing the number of sampling points, this method significantly reduces the complexity of subsequent signal processing and analysis, lowering the data processing burden and improving overall efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 A diagram showing the processing steps of the method of the present invention;
[0040] Figure 2 Flowchart for optimizing training and validation of a sampled prediction model. DETAILED DESCRIPTION
[0041] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only 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 making creative efforts are within the scope of protection of the present invention.
[0042] See also Figure 1-2 The present invention provides a technical solution: an optimal sampling method for an electric digital power meter, the specific steps of the method comprising:
[0043] Step 1: Build and train a sampling prediction model
[0044] Step 1.1 Data collection: First, collect historical sampled power signal data, including time series data of voltage and current. The data should cover different power system operating states to ensure the generalization ability of the model.
[0045] Step 1.2 Data Preprocessing: Preprocess the collected power signal data to extract signal features. The extracted signal features include basic voltage and current characteristics, waveform characteristics, time domain characteristics, and frequency domain characteristics. Specifically, basic characteristics include the signal's frequency, amplitude, and phase; waveform characteristics include the signal's waveform shape, waveform symmetry, and waveform smoothness; time domain characteristics include the signal's mean, variance, skewness, rate of rise, and rate of fall; and frequency domain characteristics include the signal's spectral distribution, spectral peak, and spectral width.
[0046] Step 1.3 Data cleaning: Clean the extracted feature data to handle missing values and outliers, including filling missing values, smoothing outliers, etc., to ensure the integrity and consistency of the data.
[0047] For outliers, the threshold judgment method is used to regard data points that exceed the preset threshold range as outliers and replace them with the mean of their neighboring points.
[0048] Step 1.4 Data standardization: Standardize the cleaned feature data to eliminate the dimensional differences between different features and improve the training efficiency of the model.
[0049] Using the Z-score standardization method, each eigenvalue is subtracted from its mean and divided by its standard deviation so that the processed data conforms to the standard normal distribution. The formula for standardization is: Where X is the original data, μ is the mean of the original data, σ is the standard deviation of the original data, and Z is the standardized data.
[0050] Step 1.5: Construct a training dataset: Mark the optimal sampling point for each data point and combine it with the corresponding feature data to form a training dataset. The training dataset is further divided into a training set and a validation set for model training and validation.
[0051] Step 1.6 Model Selection and Initialization: Select the Long Short-Term Memory (LSTM) model to construct the sampling prediction model and initialize the model parameters. The LSTM model is selected as the preferred model for this invention because it can handle the long-term dependencies of time series data.
[0052] Step 1.7: Model training: Iteratively train the LSTM model using the training set data. During training, periodically evaluate model performance using the validation set until the model meets the requirements, including reducing prediction error and improving the accuracy of sampling point location predictions.
[0053] Step 1.8 Model deployment: After training is complete, save the weights and biases of the LSTM model and deploy the model for subsequent sampling position prediction.
[0054] Step 2: Real-time signal feature extraction
[0055] The time series data of voltage and current in the circuit under test are collected in real time, and the basic characteristics, waveform characteristics, time domain characteristics and frequency domain characteristics of voltage and current are extracted.
[0056] Step 3: Sampling point location prediction
[0057] The signal features extracted in step 2 are input into the sampling prediction model trained in step 1 to obtain a list of optimal sampling point locations for the power meter in each sampling period. These locations are dynamically predicted based on the current power signal characteristics and can accurately capture the key features of the signal.
[0058] Step 4: Apply the optimal sampling strategy
[0059] The list of optimal sampling point locations within each sampling period, obtained in step 3, is applied to the power meter's sampling strategy. The power meter then performs real-time sampling based on the predicted optimal sampling point locations, improving sampling accuracy and reducing sampling costs.
[0060] As a specialized form of recurrent neural network (RNN), the LSTM model effectively addresses the vanishing or exploding gradient issues of traditional RNNs when processing long sequences of data by introducing three gating mechanisms: a forget gate, an input gate, and an output gate. This enables the LSTM model to capture long-term dependencies in power signals and provides enhanced modeling capabilities for the complex dynamics of time series data such as voltage and current in power systems. Because the LSTM model can process long sequences of data and retain key information, it can more accurately predict the optimal sampling point location within each sampling cycle, which is crucial for improving the measurement accuracy of digital power meters, especially when power signals experience large fluctuations or complex nonlinear relationships.
[0061] The LSTM model is highly adaptable and can process power signal data of varying lengths and characteristics. This allows the constructed sampling prediction model to be applicable to a variety of power system environments and operating conditions, improving the model's generalization and practicality. Compared to traditional fixed sampling point locations, the LSTM-based sampling prediction model can dynamically adjust sampling point locations based on real-time power signal characteristics. This dynamic adjustment capability enables the power meter to more flexibly respond to emergencies and changes in the power system, improving the real-time and accuracy of measurements.
[0062] The present invention will be further described below in conjunction with Examples 1 to 3:
[0063] Example 1:
[0064] Before starting training the sampling prediction model, the LSTM model needs to be initialized, including:
[0065] i) LSTM model structure parameter initialization
[0066] Input layer feature dimension setting: According to the number of extracted power signal features, the feature dimension of the LSTM model input layer is set to ensure that the input layer can receive and process all key power signal features.
[0067] Hidden layer configuration: Determine the number of hidden layers and the number of hidden units in each layer. The hidden layer design should be able to fully capture the temporal dependencies and nonlinear characteristics in the power signal.
[0068] Setting the number of nodes in the output layer: According to the number of predicted optimal sampling point positions, set the number of nodes in the output layer of the LSTM model to ensure that the output layer can generate prediction results corresponding to the sampling point positions.
[0069] ii) Model weight and bias initialization
[0070] Small random numbers are used to initialize the weights and biases of the LSTM model. This initialization method helps the model maintain a small deviation at the beginning of training and improves the stability of training.
[0071] iii) Activation function setting
[0072] Gating mechanism activation function: Set the Sigmoid function as the activation function of the LSTM model's gating mechanism. The Sigmoid function outputs a value between 0 and 1, which is suitable for controlling the flow and forgetting of information.
[0073] Memory cell and hidden state activation function: Set the Tanh function as the activation function for the candidate memory cells and hidden states of the LSTM model. The Tanh function can output a value between -1 and 1, providing nonlinear transformation and maintaining gradient stability.
[0074] iv) Optimize algorithm configuration and learning rate settings
[0075] Configure an optimization algorithm suitable for the LSTM model, such as Adam or RMSprop. Adam or RMSprop optimization algorithms can update model parameters based on gradient information and accelerate the training process.
[0076] Set an appropriate learning rate parameter. The learning rate determines the update speed of the model during training. Too high a learning rate may cause the model to be unstable, while too low a learning rate may cause the training process to be too slow.
[0077] After initializing the LSTM model, we start training the model. The iterative training process is as follows:
[0078] i) Iteratively train the LSTM model using the training set data.
[0079] ii) In each iteration, a batch of input data is selected from the training set and fed into the LSTM model.
[0080] iii) The LSTM model calculates the values of the input gate, forget gate, and output gate, updates the memory unit and hidden state, and finally obtains the predicted output sequence.
[0081] iv) Calculate the loss function value based on the predicted output and the true label to evaluate the prediction accuracy of the model in the current iteration.
[0082] v) Calculate the gradient of the loss function with respect to the model parameters through the back-propagation algorithm.
[0083] vi) Update the weights and biases of the LSTM model based on the gradients using the configured optimization algorithm (such as Adam or RMSprop).
[0084] vii) Repeat the above iterative process until the predetermined number of iterations is reached or other stopping conditions are met
[0085] During the training process, regularly use the validation set to evaluate the performance of the LSTM model, calculate the loss function value on the validation set, and observe its changing trend during training. If the performance on the validation set begins to decline, it indicates that overfitting may have occurred. At this time, the learning rate should be adjusted or training should be stopped early.
[0086] Adjust the learning rate based on the performance results on the validation set. If the loss function value on the validation set continues to decrease, it means that the model is learning, and you can maintain or increase the learning rate appropriately. If the loss function value on the validation set starts to increase, it means that overfitting may have occurred, and you should reduce the learning rate.
[0087] When the LSTM model achieves satisfactory performance on the validation set, save the model's weights and biases.
[0088] Example 2:
[0089] The extracted signal features include basic features of voltage and current, waveform features, time domain features, and frequency domain features. Specifically, the basic features include the frequency, amplitude, and phase of the signal.
[0090] Frequency extraction: To calculate the number of cycles in a signal per unit time, the signal must first be sampled, ensuring that the sampling frequency is high enough to capture all important signal features. The signal's period is then determined by analyzing its periodicity, such as by looking for repetitive patterns or zero-crossing points. Finally, the frequency is obtained by dividing the unit time (e.g., 1 second) by the signal's period.
[0091] Amplitude extraction: Extracting the amplitude of a signal is relatively simple. During the entire sampling period of the signal, all sample points are traversed and the maximum value is recorded. This maximum value is the amplitude of the signal, indicating the maximum amplitude of the signal during the sampling period.
[0092] Phase Extraction: Phase extraction typically involves comparison with a reference signal. First, a reference signal is selected; it should be a standard signal with the same frequency and waveform as the signal to be measured. The phase is then determined by comparing the initial offset between the signal to be measured and the reference signal. This can be achieved by calculating the time delay or sample point offset between the two signals. Once the time delay is determined, it can be converted to a phase angle, expressed in degrees or radians.
[0093] Waveform characteristics include waveform shape, waveform symmetry and waveform smoothness of the signal wave.
[0094] Waveform shape extraction: To extract the waveform shape of a signal, the signal must first be sampled, ensuring that the sampling frequency is high enough to capture all of the signal's important features. The overall trend and variation of the signal, including its peaks and valleys, and the changes between them, are then analyzed. By marking these key points and connecting them, the waveform shape of the signal can be depicted.
[0095] Waveform symmetry extraction: Waveform symmetry extraction involves comparing the positive and negative half-cycles of a signal. First, the positive and negative peaks of the signal are found and the time intervals between them, i.e., the positive and negative half-cycles, are determined. The areas of these two half-cycles are then calculated and compared for similarity. Similarity can be assessed by calculating the ratio of the absolute value of the difference between the areas of the two half-cycles to their sum, using the formula: The closer this ratio is to 0, the better the waveform symmetry.
[0096] Extracting Waveform Smoothness: Extracting waveform smoothness involves analyzing the rate of change of a signal. First, the signal is differentiated by the first or second order to obtain its derivative. The degree of variation of the derivative within a specific time window is then calculated, which can be achieved by calculating the variance or mean of the derivative. Smaller variations indicate smoother waveforms; larger variations indicate rougher waveforms. By comparing the degree of variation within different time windows, the overall smoothness of the waveform can be assessed.
[0097] Time domain features include the mean, variance, skewness, rise rate and fall rate of the signal.
[0098] For time domain features, the mean is the average level of the signal in the time domain, indicating the central tendency of the signal. First, the signal is sampled to obtain a series of discrete data points, and then the arithmetic mean of these data points is calculated, that is, the sum of all data points divided by the total number of data points. The calculation formula is: where x i is the i-th sample point of the signal, and N is the total number of samples. The variance is obtained by calculating the average of the squares of the differences between all sample points of the signal and its mean. On the basis of extracting the mean, the difference between each data point and the mean is calculated, and then the squares of these differences are calculated. Finally, the average of these squared differences is calculated. The calculation formula is: Skewness is an indicator that measures the direction and degree of skewness in the signal distribution. First, calculate the mean and standard deviation (square root of the variance) of the signal. Then, divide the third-order central moment (the average of the cube of the difference between all data points and the mean) by the cube of the standard deviation to calculate the skewness. The calculation formula is: The rise rate is used to describe the slope of the rising section in the signal. First, the rising section in the signal is identified by comparing the sizes of adjacent data points. Then, for each rising section, its slope is calculated, that is, the ordinate difference between the end point and the starting point of the section is divided by the abscissa difference (for discrete signals, the abscissa difference is usually an integer multiple of the sampling interval). Finally, the average of the slopes of all rising sections is calculated as the overall rise rate. The slope can be expressed as where x start and x end are the starting and ending sample points of the rising segment, respectively, and start and end are the serial numbers corresponding to the starting and ending sample points respectively; the method of extracting the decline rate is similar to that of the rising rate, but it is aimed at the declining segment in the signal. First, the declining segment in the signal is identified, and then for each declining segment, its slope is calculated. Finally, the average of the slopes of all declining segments is calculated as the overall decline rate.
[0099] Frequency domain features include the signal's spectrum distribution, spectrum peak, and spectrum width.
[0100] For frequency domain features, the spectrum distribution describes the energy distribution of the signal at different frequencies. In order to extract the spectrum distribution, the signal must first be Fourier transformed to convert the signal from the time domain to the frequency domain. The Fourier transform decomposes the signal into a superposition of sine and cosine components of different frequencies, thereby obtaining the spectrum representation of the signal. The spectrum distribution is usually displayed by drawing a spectrum graph, where the horizontal axis represents the frequency and the vertical axis represents the energy (or amplitude) at the corresponding frequency. The calculation formula is: Where x(t) is the time domain signal, X(f) is its corresponding frequency representation, and f is the frequency; the spectrum peak is the point with the maximum energy (or amplitude) in the spectrum, which corresponds to the main frequency component of the signal. In order to extract the spectrum peak, it is first necessary to perform Fourier transform on the signal to obtain the spectrum. Then, all frequency points in the spectrum are traversed to find the point with the largest amplitude. The frequency of this point is the spectrum peak. When extracting, the maximum value in the spectrum array and its corresponding index (i.e., frequency) are directly searched by programming. The calculation formula is: Spectrum peak = max f |X(f)|; Spectral width is a measure of the range of a signal's spectrum along the frequency axis. There are various ways to define and calculate spectral width, a common method being based on the width of an amplitude threshold. First, an amplitude threshold is set (usually determined based on the specific signal conditions and requirements). Then, the lowest and highest frequency points in the spectrum where the amplitude exceeds the threshold are found. The difference between these two frequency points is the spectral width based on the amplitude threshold. The calculation formula is: Spectral width = f2 - f1, where f1 and f2 are the lowest and highest frequency points in the spectrum where the amplitude exceeds the threshold, respectively.
[0101] The following is a code example for extracting frequency domain features using the Python programming language:
[0102] import numpy as np
[0103] import matplotlib.pyplot as plt
[0104] #Generate synthetic signal
[0105] fs=1000#sampling frequency
[0106] t = np.arange(0,1,1 / fs) #time vector
[0107] f1,f2=50,120#Two frequency components of the signal
[0108] signal=0.6*np.sin(2*np.pi*f1*t)+2*np.sin(2*np.pi*f2*t)
[0109] #Calculate the spectrum
[0110] signal_fft=np.fft.fft(signal)
[0111] freqs=np.fft.fftfreq(len(signal),1 / fs)
[0112] #Extract spectrum distribution
[0113] magnitude_spectrum=np.abs(signal_fft)
[0114] #Extract spectrum peak
[0115] peak_freq=freqs[np.argmax(magnitude_spectrum)]
[0116] #Extract spectrum width (based on amplitude threshold)
[0117] threshold=0.5*np.max(magnitude_spectrum)
[0118] above_threshold=magnitude_spectrum>threshold
[0119] width_freqs=freqs[above_threshold]
[0120] spectral_width=np.max(width_freqs)-np.min(width_freqs)
[0121] #Draw the spectrum
[0122] plt.figure()
[0123] plt.plot(freqs[:len(freqs) / / 2],
[0124] magnitude_spectrum[:len(freqs) / / 2])#Draw only the positive frequency part
[0125] plt.title('Magnitude Spectrum')
[0126] plt.xlabel('Frequency(Hz)')
[0127] plt.ylabel('Magnitude')
[0128] plt.grid()
[0129] plt.axvline(x=peak_freq,color='r',linestyle='--',label='PeakFrequency')
[0130] plt.axvspan(np.min(width_freqs),np.max(width_freqs), color='y',alpha=0.3,label='Spectral Width')
[0131] plt.legend()
[0132] plt.show()
[0133] # Output results
[0134] print(f"The frequency corresponding to the spectrum peak is: {peak_freq:.2f}Hz")
[0135] print(f"The spectrum width based on the amplitude threshold is: {spectral_width:.2f}Hz")
[0136] The above code describes how to use the Python programming language and the NumPy library to extract three frequency domain features of a signal: spectral distribution, spectral peak, and spectral width based on amplitude threshold. The specific steps are:
[0137] Step 1: Generate a synthetic signal
[0138] First, a synthetic signal consisting of two sine wave components is generated. This signal can be constructed by setting the sampling frequency, time vector, and two sine wave components of different frequencies.
[0139] Step 2: Calculate the spectrum
[0140] Next, the fast Fourier transform (FFT) function in the NumPy library is used to calculate the spectrum of the signal. The FFT function converts the signal from the time domain to the frequency domain, obtains the complex representation of the spectrum, and calculates the corresponding frequency vector for subsequent analysis.
[0141] Step 3: Extract spectrum distribution
[0142] Then, the spectrum distribution characteristics are extracted. By calculating the amplitude of the spectrum (i.e. the modulus of the complex number), the spectrum distribution can be obtained, which describes the energy distribution of the signal at different frequencies.
[0143] Step 4: Extract spectrum peaks
[0144] Next, we extract the spectrum peak feature. The spectrum peak is the point with the largest amplitude in the spectrum, which corresponds to the main frequency component of the signal. By traversing the spectrum amplitude array and finding the maximum value and its corresponding frequency, we can obtain the spectrum peak.
[0145] Step 5: Extract spectrum width (based on amplitude threshold)
[0146] Finally, we extract the spectrum width feature based on the amplitude threshold. First, we set an amplitude threshold, then find the lowest and highest frequency points in the spectrum where the amplitude exceeds the threshold. The difference between these two frequency points is the spectrum width based on the amplitude threshold.
[0147] Example 3:
[0148] The power meter described in the present invention is mainly composed of the following modules:
[0149] Sampling Prediction Module: This module deploys a sampling prediction model pre-trained using the power meter's optimal sampling method. This model, trained based on historical or simulated data, predicts the optimal sampling point locations under different circuit conditions.
[0150] Real-time data acquisition module: This module is responsible for collecting real-time time series data of voltage and current in the measured circuit. It further extracts basic characteristics (such as mean and peak values), waveform characteristics (such as waveform shape and distortion), time domain characteristics (such as rate of change in the time domain), and frequency domain characteristics (such as spectrum distribution).
[0151] Optimal Sampling Point Prediction Module: This module inputs the signal features extracted by the real-time data acquisition module into the trained sampling prediction model in the sampling prediction module. Through model calculations, it obtains a list of optimal sampling point locations for the power meter during each sampling period.
[0152] Sampling strategy application module: This module applies the position list of the optimal sampling points in each sampling period output by the optimal sampling point prediction module to the sampling strategy of the power meter, so that the power meter can perform real-time sampling according to the predicted optimal sampling point positions, thereby improving the accuracy and efficiency of the measurement.
[0153] The present invention further provides an electronic device, which includes a memory and a processor, and is specifically implemented as follows:
[0154] Memory: used to store one or more computer instructions. These instructions are necessary to implement the above-mentioned power meter optimal sampling method.
[0155] Processor: Executes one or more computer instructions stored in the memory. By executing these instructions, the processor can implement the above-mentioned power meter sampling prediction, data acquisition, optimal sampling point prediction and sampling strategy application functions.
[0156] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus.
[0157] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.
Claims
1. An optimal sampling method for an electric digital power meter, characterized in that: The method specifically comprises the following steps: Step 1: Use a neural network algorithm to build and train a sampling prediction model. The sampling prediction model is used to predict the optimal sampling point position of the power meter in each sampling period based on the power signal generated by the circuit. The specific steps of building and training the sampling prediction model include: Step 1.1: Collect historically sampled power signal data, including time series data of voltage and current; Step 1.2: Preprocess the collected power signal data to extract signal features. The extracted signal features include basic features of voltage and current, waveform features, time domain features, and frequency domain features. Basic features include the frequency, amplitude, and phase of the signal. Waveform features include the waveform shape, waveform symmetry, and waveform smoothness of the signal. Time domain features include the mean, variance, skewness, rise rate, and fall rate of the signal. Frequency domain features include the spectral distribution, spectral peak, and spectral width of the signal. Step 1.3: Clean the extracted feature data to handle missing values and outliers. Step 1.4: Standardize the cleaned feature data; Step 1.5: Mark the optimal sampling point position of each data, and together with the corresponding feature data, form a training data set. The training data set is further divided into a training set and a validation set. Step 1.6: Select the Long Short-Term Memory (LSTM) model to build a sampling prediction model and initialize the model parameters. Step 1.7: Iteratively train the LSTM model using the training set data. During the training process, regularly evaluate the model performance using the validation set until the model performance meets the requirements. Step 1.8: After training is complete, save the weights and biases of the LSTM model and deploy the model for subsequent sampling position prediction. Step 2: Collect the time series data of voltage and current in the circuit under test in real time, and extract the basic characteristics, waveform characteristics, time domain characteristics and frequency domain characteristics of voltage and current; Step 3: Input the signal features extracted in step 2 into the sampling prediction model trained in step 1 to obtain the optimal sampling point location list of the power meter in each sampling period; Step 4: Apply the position list of the optimal sampling points in each sampling period obtained in step 3 to the sampling strategy of the power meter, and the power meter performs real-time sampling according to the predicted optimal sampling point positions.
2. The method for optimizing sampling of a digital power meter according to claim 1, wherein: For basic features, the frequency is obtained by calculating the number of cycles of the signal in unit time; the amplitude is obtained by calculating the maximum value of the signal; the phase is obtained by calculating the initial offset of the signal; As for the waveform characteristics, the waveform shape is obtained by calculating the peak and valley values of the signal and the change period between the two; the waveform symmetry is obtained by comparing the similarity between the positive half-cycle and the negative half-cycle of the signal. The calculation formula is: The waveform smoothness is obtained by calculating the degree of change of the first or second derivative of the signal. The smoothness represents the average value of the rate of change of the derivative. For time domain features, the mean is obtained by calculating the average value of all sample points of the signal. The calculation formula is: where x i is the i-th sample point of the signal, and N is the total number of samples; The variance is obtained by calculating the average of the squares of the differences between all sample points of the signal and its mean. The calculation formula is: Skewness is used to measure the direction and degree of skewness of the signal distribution. The calculation formula is: The rising rate is obtained by calculating the average slope of all rising segments in the signal. For each rising segment, the slope is where x start and x end are the starting and ending sample points of the rising segment, respectively. start and end are the serial numbers corresponding to the starting and ending sample points, respectively. The falling rate is obtained by calculating the average slope of all falling segments in the signal. For each falling segment, the slope is calculated in the same way as the rising rate, but in the opposite direction. For frequency domain features, the spectrum distribution is converted from the time domain to the frequency domain through Fourier transform to obtain the spectrum of the signal. The calculation formula is: Where x(t) is the time domain signal, X(f) is its corresponding frequency representation, and f is the frequency; the spectrum peak is the frequency of the point with the maximum amplitude in the signal spectrum, and the calculation formula is: Spectrum peak = max f |X(f)|; Spectral width is used to measure the distribution width of the signal spectrum on the frequency axis. The calculation formula is: Spectral width = f2-f1, where f1 and f2 are the lowest and highest frequency points in the spectrum where the amplitude exceeds the threshold.
3. The method for optimizing sampling of a digital power meter according to claim 2, characterized in that: In step 1.3, for missing values, linear interpolation algorithm is used to fill them; for outliers, threshold judgment method is used to regard data points that exceed the preset threshold range as outliers and replace them with the mean of their neighboring points.
4. The method for optimizing sampling of a digital power meter according to claim 3, wherein: In step 1.4, the Z-score normalization method is used to subtract the mean of each feature value and divide it by its standard deviation so that the processed data conforms to the standard normal distribution. The formula for normalization is: Where X is the original data, μ is the mean of the original data, σ is the standard deviation of the original data, and Z is the standardized data.
5. The method for optimizing sampling of a digital power meter according to claim 4, characterized in that: The parameters for initializing the LSTM model in step 1.6 include: i) Initializing the structural parameters of the LSTM model, including the feature dimension of the input layer, the number of hidden layers and the number of hidden units in each layer, and the number of nodes in the output layer. The feature dimension of the input layer matches the number of extracted power signal features, and the number of nodes in the output layer is equal to the number of predicted optimal sampling point positions. ii) Initialize the model weights and biases using small random numbers; iii) Setting the activation function of the LSTM model, including setting the Sigmoid function for the gating mechanism and the Tanh function for calculating candidate memory cells and hidden states; iv) Configure the optimization algorithm and set the learning rate parameters.
6. The method for optimizing sampling of a digital power meter according to claim 5, characterized in that: In step 1.7, the LSTM model is iteratively trained using the training set data. In each iteration, a batch of input data is fed into the LSTM model. By calculating the values of the input gate, forget gate, and output gate, the memory cells and hidden states are updated to obtain the predicted output sequence. The loss function value is calculated based on the predicted output and the true label. The gradient of the loss function with respect to the model parameters is calculated using the backpropagation algorithm. The model weights and bias are updated based on the gradient using the optimization algorithm. During training, the validation set is regularly used to evaluate model performance, and the learning rate is adjusted or training is stopped early as needed to prevent overfitting.
7. A power meter, characterized in that: The power meter comprises: A sampling prediction module, in which a sampling prediction model pre-trained using the method described in any one of claims 1 to 6 is deployed; Real-time data acquisition module, used to collect time series data of voltage and current in the measured circuit in real time, and extract basic characteristics, waveform characteristics, time domain characteristics and frequency domain characteristics of voltage and current; The optimal sampling point prediction module is used to input the signal features extracted by the real-time data acquisition module into the sampling prediction model trained in the sampling prediction module to obtain the optimal sampling point position list of the power meter in each sampling period; The sampling strategy application module is used to apply the position list of the optimal sampling points in each sampling period obtained by the optimal sampling point prediction module to the sampling strategy of the power meter, so that the power meter performs real-time sampling according to the predicted optimal sampling point positions.
8. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the power meter optimal sampling method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for sampling electric monitoring signal
CN102809679A
Broadband high-precision digital power meter and rapid optimization sampling method
CN112557747A