Alternating current frequency calculation method and device, computer equipment and storage medium
Through periodic sampling, inverse cosine calculation and least squares linear fitting, the accuracy problem of zero crossing point measurement under distorted waveform in AC frequency calculation is solved, and high-precision frequency calculation is achieved.
Patent Information
- Application Number
- CN202411464060.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2044-10-21
AI Technical Summary
The existing AC frequency calculation methods are difficult to accurately measure zero crossing points when AC waveform distortion (high noise or harmonic content), and the measurement accuracy is affected by the initial phase and the number of samples.
Periodic sampling is used to obtain the AC current signal, perform inverse cosine calculation and top-cut bottoming, search the interval between the preset minimum value and the maximum value, obtain a straight line through the least squares normal linear fit, and calculate the horizontal coordinate of the line's zero-crossing point The difference value is then calculated by sine wave period and frequency.
Even when AC waveform distortion, the method can calculate the frequency with high accuracy, avoiding the impact of the initial phase and the number of samples on the measurement, and improving the accuracy of frequency calculation.
Smart Images

Figure CN118962234A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of alternating current technology, and in particular to an alternating current frequency calculation method, device, computer equipment and storage medium. Background Art
[0002] As a core parameter in the electrical field, the calculation and application of alternating current (AC) frequency are widely present in all aspects of our daily life and industrial production.
[0003] The frequency of AC power, usually measured in Hertz (Hz), represents the number of periodic changes per unit time. Its calculation formula is frequency (f) = 1 / T, where f represents the frequency and T represents the period of the signal. This formula reveals the inverse relationship between frequency and period, and provides a theoretical basis for us to accurately calculate the frequency of AC power.
[0004] The calculation and application of AC frequency has broad application prospects and important roles in the fields of power systems, electrical equipment, communications and information technology. With the continuous advancement of science and technology and the rapid development of the power industry, the calculation and application of AC frequency will become more accurate and efficient, bringing more convenience and benefits to our lives and work.
[0005] In the traditional method of calculating the frequency of AC power, the voltage comparison method is generally used to measure the zero-crossing time interval. This method has two shortcomings: first, when the AC power waveform has a certain distortion (high noise or harmonic content), the zero-crossing point is difficult to measure; second, even if the AC power waveform is not highly distorted, the accuracy of measuring the zero-crossing point will be affected by the initial phase and the number of samples, which will ultimately affect the frequency calculation accuracy. Summary of the invention
[0006] The purpose of the embodiments of the present invention is to provide an AC frequency calculation method, device, computer equipment and storage medium to solve the problem that the zero crossing point is difficult to measure when the AC waveform has a certain distortion (high noise or harmonic content) in the existing AC frequency calculation method.
[0007] In order to solve the above technical problems, the present invention provides a method for calculating the frequency of alternating current, which adopts the following technical solution, including:
[0008] Acquire AC power signal;
[0009] The alternating current signal is periodically sampled to obtain a sampling sequence S1, S2, S3, ..., Sn, where n is the number of sampling points;
[0010] Performing arccosine calculation on the sampling sequences S1, S2, S3, ..., Sn to obtain arccosine values Cn;
[0011] The arccosine value Cn is clipped to obtain a clipped value Dn;
[0012] Searching for two intervals with the same direction of change between the preset minimum value and the preset maximum value in the value Dn after the top and bottom are cut, namely Di~Di+kk, Dj~Dj+k;
[0013] Perform the least squares linear fitting on the two intervals to obtain two straight lines and , and ;
[0014] Calculate two straight lines separately and The horizontal coordinate when it crosses zero and , calculate the horizontal coordinate and The difference between them is used to calculate the sine wave period according to the sampling period, that is, , and then calculate the frequency based on the sine wave period, .
[0015] Preferably, the step of periodically sampling the AC signal to obtain a sampling sequence S1, S2, S3, ..., Sn specifically includes:
[0016] Select the sampling frequency;
[0017] Determine the sampling period;
[0018] Synchronous trigger sampling;
[0019] Select sampling points to obtain a sampling sequence S1, S2, S3, ..., Sn;
[0020] Store sampling sequence S1, S2, S3, ..., Sn.
[0021] Preferably, the step of performing arccosine calculation on the sampling sequences S1, S2, S3, ..., Sn to obtain the arccosine value Cn specifically includes:
[0022] calculate , where A is the AC signal amplitude, that is .
[0023] Preferably, the step of clipping the arccosine value Cn to obtain the clipped value Dn specifically comprises:
[0024] calculate .
[0025] Preferably, the step of searching for two intervals with the same direction of change between a preset minimum value and a preset maximum value, namely Di to Di+k and Dj to Dj+k, in the truncated value Dn specifically comprises:
[0026] Set specific values for the preset minimum value and the preset maximum value;
[0027] Traverse the clipped value Dn, search for two intervals with the same direction of change between the preset minimum value and the preset maximum value, and obtain Di~Di+k, Dj~Dj+k.
[0028] Preferably, the least squares linear fitting is performed on the two intervals to obtain two straight lines. and , and The steps specifically include:
[0029] Determine the fitting interval and ;
[0030] Setting up the linear model ;
[0031] In the fitting interval, according to the set linear model, determine , , and The value of is obtained by least squares linear fitting to obtain two straight lines and ,
[0032] .
[0033] Preferably, the two straight lines are calculated separately and The horizontal coordinate when it crosses zero and , calculate the horizontal coordinate and The difference between them is used to calculate the sine wave period according to the sampling period, that is, , and then calculate the frequency based on the sine wave period, The steps specifically include:
[0034] make ;
[0035] make ;
[0036] The sine wave period is calculated according to the sampling period, that is, ;
[0037] Calculate the frequency based on the sine wave period, .
[0038] In order to solve the above technical problems, the present invention further provides an alternating current frequency calculation device, which adopts the following technical solution, including:
[0039] An acquisition module, used for acquiring an alternating current signal;
[0040] A sampling module, used for periodically sampling the AC signal to obtain a sampling sequence S1, S2, S3, ..., Sn, where n is the number of sampling points;
[0041] An arccosine calculation module, used for performing arccosine calculation on the sampling sequences S1, S2, S3, ..., Sn to obtain an arccosine value Cn;
[0042] A clipping module, used for clipping the arccosine value Cn to obtain a clipped value Dn;
[0043] A search module is used to search for two intervals with the same change direction between a preset minimum value and a preset maximum value in the value Dn after being clipped, namely Di~Di+k, Dj~Dj+k;
[0044] The linear fitting module is used to perform the least squares linear fitting on two intervals to obtain two straight lines. and , and ;
[0045] Frequency calculation module, used to calculate two straight lines separately and The horizontal coordinate when it crosses zero and , calculate the horizontal coordinate and The difference between them is used to calculate the sine wave period according to the sampling period, that is, , and then calculate the frequency based on the sine wave period, .
[0046] In order to solve the above technical problems, the present invention also provides a computer device, which adopts the technical solution described below, including a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the above-mentioned AC frequency calculation method when executing the computer-readable instructions.
[0047] In order to solve the above technical problems, the present invention also provides a computer-readable storage medium, which adopts the technical solution described below, and stores computer-readable instructions on the computer-readable storage medium, which implement the steps of the above-mentioned AC frequency calculation method when executed by the processor.
[0048] Compared with the prior art, the present invention mainly has the following beneficial effects: firstly, an alternating current signal is acquired; periodically samples the alternating current signal to obtain a sampling sequence; inverse cosine calculation is performed on the sampling sequence to obtain an inverse cosine value; the inverse cosine value is clipped to obtain a clipped value; two intervals with the same direction of change between a preset minimum value and a preset maximum value are retrieved from the clipped value; the two intervals are respectively linearly fitted by the least square method to obtain two straight lines; the horizontal coordinates of the two straight lines when they cross zero points are respectively calculated, the difference between the horizontal coordinates is calculated, and then the sine wave period is calculated according to the sampling period, and then the frequency is calculated according to the sine wave period; even when the alternating current waveform has a certain distortion (high noise or harmonic content), the zero-crossing point measurement is still not affected, the accuracy of measuring the zero-crossing point is not affected by the initial phase and the number of samples, and the frequency calculation accuracy is high. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the scheme in the present invention, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present invention. 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 any creative work.
[0050] Figure 1 is a flow chart of an embodiment of the method for calculating the frequency of alternating current of the present invention;
[0051] Figure 2 It is a schematic diagram of a sampling sequence generated after periodic sampling of an AC signal in the AC frequency calculation method of the present invention;
[0052] Figure 3 It is a schematic diagram of performing arccosine calculation on a sampling sequence in the method for calculating the frequency of alternating current of the present invention;
[0053] Figure 4 It is a schematic diagram of the arccosine calculation result after being truncated in the AC frequency calculation method of the present invention;
[0054] Figure 5 Schematic diagram of two intervals used in the method for calculating the frequency of alternating current of the present invention;
[0055] Figure 6 is a schematic structural diagram of an embodiment of an alternating current frequency calculation device of the present invention;
[0056] Figure 7 It is a schematic structural diagram of an embodiment of a computer device of the present invention. DETAILED DESCRIPTION
[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present invention; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention; the terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present invention or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0058] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0059] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings.
[0060] It should be noted that the AC power frequency calculation method provided in the embodiment of the present invention is generally executed by a server / terminal device, and accordingly, the AC power frequency calculation device is generally arranged in the server / terminal device.
[0061] It should be understood that the number of terminal devices, networks and servers is only illustrative. Depending on the implementation requirements, there can be any number of terminal devices, networks and servers.
[0062] Embodiment 1
[0063] Please refer to Figure 1 , shows a flow chart of an embodiment of the method for calculating the frequency of alternating current of the present invention. The method for calculating the frequency of alternating current comprises the following steps:
[0064] Step S1, obtaining an alternating current signal.
[0065] In this embodiment, the electronic device (e.g., server / terminal device) on which the AC frequency calculation method is running can receive the AC frequency calculation request through a wired connection or a wireless connection. It should be noted that the above wireless connection method may include but is not limited to 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAXX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.
[0066] The acquisition of AC signals is the premise and basis for frequency calculation. Depending on the actual application scenario, there are various methods to obtain AC signals, mainly including generators, oscillators, power inverters, and grid power supply.
[0067] Generators are a traditional and common method of obtaining AC signals. The basic principle is to generate AC by converting mechanical energy into electrical energy using the principle of electromagnetic induction. Generators can be designed and adjusted as needed to generate sinusoidal AC signals with specific frequency, amplitude, and phase.
[0068] As one of the main sources of AC signals, the generator has the characteristics of flexibility and adjustability. By adjusting its parameters, it is easy to obtain AC signals of different frequencies, amplitudes and phases to meet various application requirements.
[0069] An oscillator is a circuit device that is specifically used to generate a stable sinusoidal alternating current signal. Its basic principle is to form a loop through an amplifier and a feedback circuit, and use the positive feedback mechanism to make the circuit self-oscillate, thereby generating a sinusoidal waveform.
[0070] You can also get an AC signal through a power inverter. A power inverter is a device that converts DC power to AC power.
[0071] Step S2, periodically sampling the AC signal to obtain a sampling sequence S1, S2, S3, ..., Sn, where n is the number of sampling points.
[0072] Periodic sampling is a method of obtaining the amplitude and phase information of the signal by sampling the AC signal multiple times within a complete cycle, and then calculating the frequency. During the sampling process, it is necessary to ensure that the sampling frequency satisfies the sampling theorem, that is, the sampling frequency should be greater than or equal to twice the highest frequency of the signal to ensure the integrity and accuracy of the signal.
[0073] Figure 2 FIG. 1 is a schematic diagram of a sampling sequence generated by periodically sampling an AC signal in the AC frequency calculation method of the present invention. Figure 2 As shown, in this embodiment, step S2 may further include the steps of:
[0074] S21, select sampling frequency.
[0075] The selection of sampling frequency is the first step in periodic sampling. According to the sampling theorem, the sampling frequency should be greater than or equal to twice the highest frequency of the signal. In practical applications, in order to obtain higher sampling precision and accuracy, a higher sampling frequency is usually selected. The determination of the sampling frequency needs to consider factors such as signal characteristics, measurement accuracy requirements, and the performance of the sampling equipment.
[0076] S22, determine the sampling period.
[0077] The sampling period is the reciprocal of the sampling frequency, which indicates the time interval between each sampling. When determining the sampling period, it is necessary to ensure that the sampling period is small enough to obtain enough sampling points in a complete period to accurately reflect the waveform and frequency characteristics of the signal. The determination of the sampling period also needs to consider factors such as the speed of change of the signal and the response speed of the sampling device.
[0078] S23, synchronous trigger sampling.
[0079] Synchronous trigger sampling is one of the key steps in periodic sampling. In order to ensure the accuracy and synchronization of sampling, a synchronous trigger signal is usually used to control the sampling process. The synchronous trigger signal should have the same frequency and phase as the AC signal to be measured so that sampling can be performed at a fixed time point within each cycle. The synchronous trigger signal can be implemented by a circuit such as a phase-locked loop (PLL) to ensure synchronization between sampling and the signal.
[0080] S24, select sampling points to obtain a sampling sequence S1, S2, S3, ..., Sn.
[0081] On the basis of synchronous trigger sampling, it is necessary to select appropriate sampling points for sampling. The selection of sampling points should meet certain requirements, such as equal-interval sampling, equal-phase sampling, etc. Equal-interval sampling means sampling at fixed time intervals in each sampling cycle; equal-phase sampling means sampling at fixed phase points in each cycle based on the phase information of the signal. The selection of sampling points depends on factors such as signal characteristics, sampling purpose, and performance of the sampling equipment.
[0082] S25, store the sampling sequence S1, S2, S3, ..., Sn.
[0083] During the sampling process, the sampled data sampling sequence S1, S2, S3, ..., Sn needs to be stored. The sampled data is usually represented in digital form and can be stored in computer memory, hard disk or other storage devices. In order to facilitate subsequent data processing and analysis, the sampled data needs to be formatted and stored, including information such as data format, storage location and timestamp.
[0084] Step S3, performing arc cosine calculation on the sampling sequences S1, S2, S3, ..., Sn to obtain arc cosine value Cn.
[0085] Figure 3 FIG. 1 is a schematic diagram of the method for calculating the frequency of alternating current in the present invention after the arc cosine calculation is performed on the sampling sequence. Figure 3 As shown, in this embodiment, step S3 specifically includes:
[0086] calculate , where A is the AC signal amplitude, that is .
[0087] As a mathematical tool, arccosine calculation has high calculation accuracy. In AC frequency calculation, the introduction of arccosine calculation can improve the accuracy and reliability of measurement, providing a strong guarantee for the stable operation of the power system.
[0088] Step S4, truncating the arc cosine value Cn to obtain a truncated value Dn.
[0089] The arccosine value Cn is clipped at the top and bottom, that is, the top and bottom of the arccosine value Cn are flattened.
[0090] Figure 4 FIG. 1 is a schematic diagram of the method for calculating the frequency of alternating current in the present invention after the arc cosine calculation result is truncated. Figure 4 As shown, in this embodiment, step S4 specifically includes:
[0091] calculate .
[0092] Step S5, searching the value Dn after the top and bottom are clipped for two intervals with the same direction of change between the preset minimum value and the preset maximum value, namely Di~Di+k, Dj~Dj+k.
[0093] In this embodiment, step S5 specifically includes:
[0094] S51, setting specific values of the preset minimum value and the preset maximum value.
[0095] Figure 5 Schematic diagram of two intervals used in the AC frequency calculation method of the present invention. Figure 5 As shown, in a specific implementation, the preset minimum value can be 0.4-0.6, and the preset maximum value can be 2.34-2.94. In this embodiment, the preset minimum value is 0.5, and the preset maximum value can be 2.64.
[0096] S52, traverse the value Dn after clipping, search for two intervals with the same direction of change between the preset minimum value and the preset maximum value, and obtain Di~Di+k, Dj~Dj+k.
[0097] Step S6: perform least squares linear fitting on the two intervals to obtain two straight lines and , and .
[0098] In this embodiment, step S6 specifically includes:
[0099] S61, determine the fitting interval and .
[0100] Select two representative time periods and The two intervals should be able to fully reflect the frequency characteristics of AC power while avoiding excessive noise or abnormal data.
[0101] Selecting an appropriate fitting interval can ensure that the fitting results are more accurate and reflect the actual frequency characteristics of the alternating current.
[0102] S62, Setting the linear model .
[0103] In the selected interval, a linear model is set to describe the relationship between voltage or current and time. The linear model is expressed as ,in Represents the instantaneous value of voltage or current, Represents time, and are the slope and intercept of the model respectively.
[0104] The linear model provides a mathematical basis for the subsequent fitting process, making it possible to use mathematical methods to solve the parameter values that best reflect the characteristics of the data.
[0105] S63, within the fitting interval, according to the set linear model, determine , , and The value of is obtained by least squares linear fitting to obtain two straight lines and , and .
[0106] In order to find the best , , and The objective function is usually defined as the sum of squares of the difference between the observed value and the model predicted value, that is, the residual sum of squares (RSS).
[0107] The objective function is used to quantify the difference between the model prediction value and the true observation value. By minimizing this objective function, the optimal model parameters can be found.
[0108] Using the least squares method, the objective function is solved to find the values of (k) and (b) that minimize the sum of squared residuals. This involves taking the derivative of the objective function and setting it to zero, then solving for (k) and (b) analytically or numerically.
[0109] Solving the model parameters is the core step of linear fitting, which determines the shape and position of the fitting line, and thus determines the estimation of the frequency characteristics of the AC power.
[0110] After obtaining the fitted line, you can also evaluate its fit. This can be achieved by calculating statistics such as the residual sum of squares and the coefficient of determination (R²).
[0111] Evaluating the fitting effect helps to understand the accuracy and reliability of the fitting line, and thus determine whether its estimation of the frequency characteristics of the AC power is accurate.
[0112] After confirming that the fitting straight line can better reflect the frequency characteristics of the alternating current, the frequency information of the alternating current can also be extracted through the slope of the fitting straight line or other related parameters.
[0113] The steps of using the least squares method to linearly fit an interval to obtain a straight line include determining the fitting interval, setting the linear model, building the objective function, solving the model parameters, evaluating the fitting effect, and extracting the frequency information. These steps together constitute a complete data processing flow, which provides strong support for accurately estimating the frequency of AC power.
[0114] Step S7, calculate two straight lines respectively and The horizontal coordinate when it crosses zero and , calculate the horizontal coordinate and The difference between them is used to calculate the sine wave period according to the sampling period, that is, , and then calculate the frequency based on the sine wave period, .
[0115] In specific implementation, step S7 may further include the following steps:
[0116] S71, order .
[0117] S72, order .
[0118] S73, calculate the sine wave period according to the sampling period, that is, .
[0119] S74, calculate the frequency based on the sine wave period, .
[0120] For example, when 128 points of 50Hz AC power are sampled, the sampling period is τ=156.25us.
[0121] In specific implementation, it has been verified that when a 50Hz AC signal (without harmonic components) is sampled at 128 points per cycle using a 12-bit ADC, the calculated frequency error is less than 0.02Hz. When a 5% harmonic is applied to the AC signal, the final calculation accuracy can still reach 0.1Hz
[0122] The beneficial effects of implementing this embodiment are as follows: first, an alternating current signal is acquired; periodically samples the alternating current signal to obtain a sampling sequence; arccosine calculation is performed on the sampling sequence to obtain an arccosine value; the arccosine value is clipped to obtain a clipped value; two intervals with the same direction of change between a preset minimum value and a preset maximum value are retrieved from the clipped value; the two intervals are linearly fitted by the least squares method to obtain two straight lines; the horizontal coordinates of the two straight lines when they cross zero points are calculated respectively, the difference between the horizontal coordinates is calculated, and then the sine wave period is calculated according to the sampling period, and then the frequency is calculated according to the sine wave period; even when the alternating current waveform has a certain distortion (high noise or harmonic content), the zero-crossing point measurement is still not affected, the accuracy of measuring the zero-crossing point is not affected by the initial phase and the number of samples, and the frequency calculation accuracy is high.
[0123] The present invention can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present invention can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present invention can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0124] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0125] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0126] Embodiment 2
[0127] Further references Figure 6 , as a response to the above Figure 1 The present invention provides an embodiment of an alternating current frequency calculation device, and the device embodiment is Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0128] like Figure 6 As shown, the AC frequency calculation device 80 of this embodiment includes: an acquisition module 81, a sampling module 82, an arc cosine calculation module 83, a clipping module 84, a retrieval module 85, a linear fitting module 86 and a frequency calculation module 87. Among them:
[0129] An acquisition module 81, used for acquiring an alternating current signal;
[0130] The sampling module 82 is used to periodically sample the AC signal to obtain a sampling sequence S1, S2, S3, ..., Sn, where n is the number of sampling points;
[0131] An arccosine calculation module 83 is used to perform arccosine calculation on the sampling sequences S1, S2, S3, ..., Sn to obtain an arccosine value Cn;
[0132] A clipping module 84 is used to clip the arc cosine value Cn to obtain a clipped value Dn;
[0133] A search module 85 is used to search for two intervals with the same change direction between a preset minimum value and a preset maximum value in the value Dn after being clipped, namely Di to Di+k and Dj to Dj+k;
[0134] Linear fitting module 86 is used to perform least squares linear fitting on two intervals to obtain two straight lines. and , and ;
[0135] Frequency calculation module 87, used to calculate the frequency of two straight lines and The horizontal coordinate when it crosses zero and , calculate the horizontal coordinate and The difference between them is used to calculate the sine wave period according to the sampling period, that is, , and then calculate the frequency based on the sine wave period, .
[0136] The beneficial effects of implementing this embodiment are as follows: first, an alternating current signal is acquired; periodically samples the alternating current signal to obtain a sampling sequence; arccosine calculation is performed on the sampling sequence to obtain an arccosine value; the arccosine value is clipped to obtain a clipped value; two intervals with the same direction of change between a preset minimum value and a preset maximum value are retrieved from the clipped value; the two intervals are linearly fitted by the least squares method to obtain two straight lines; the horizontal coordinates of the two straight lines when they cross zero points are calculated respectively, the difference between the horizontal coordinates is calculated, and then the sine wave period is calculated according to the sampling period, and then the frequency is calculated according to the sine wave period; even when the alternating current waveform has a certain distortion (high noise or harmonic content), the zero-crossing point measurement is still not affected, the accuracy of measuring the zero-crossing point is not affected by the initial phase and the number of samples, and the frequency calculation accuracy is high.
[0137] Embodiment 3
[0138] To solve the above technical problems, the embodiment of the present invention also provides a computer device. Figure 7 , Figure 7 This is a basic structural block diagram of the computer device in this embodiment.
[0139] The computer device 9 includes a memory 91, a processor 92, and a network interface 93 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 9 having components of a memory 91, a processor 92, and a network interface 93, but it should be understood that it is not required to implement all the components shown, and more or fewer components may be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to a microprocessor, an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a digital processor (DSP), an embedded device, etc.
[0140] The computer device may be a desktop computer, a notebook computer, a PDA, a cloud server, etc. The computer device may interact with the user through a keyboard, a mouse, a remote control, a touch pad, or a voice control device.
[0141] The memory 91 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 91 may be an internal storage unit of the computer device 9, such as a hard disk or memory of the computer device 9. In other embodiments, the memory 91 may also be an external storage device of the computer device 9, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. equipped on the computer device 9. Of course, the memory 91 may also include both the internal storage unit of the computer device 9 and its external storage device. In this embodiment, the memory 91 is generally used to store the operating system and various application software installed on the computer device 9, such as computer-readable instructions of the method for calculating the frequency of alternating current, etc. In addition, the memory 91 can also be used to temporarily store various types of data that have been output or are to be output.
[0142] In some embodiments, the processor 92 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 92 is generally used to control the overall operation of the computer device 9. In this embodiment, the processor 92 is used to run the computer-readable instructions stored in the memory 91 or process data, such as running the computer-readable instructions of the AC frequency calculation method.
[0143] The network interface 93 may include a wireless network interface or a wired network interface. The network interface 93 is generally used to establish a communication connection between the computer device 9 and other electronic devices.
[0144] The beneficial effects of implementing this embodiment are as follows: first, an alternating current signal is acquired; periodically samples the alternating current signal to obtain a sampling sequence; arccosine calculation is performed on the sampling sequence to obtain an arccosine value; the arccosine value is clipped to obtain a clipped value; two intervals with the same direction of change between a preset minimum value and a preset maximum value are retrieved from the clipped value; the two intervals are linearly fitted by the least squares method to obtain two straight lines; the horizontal coordinates of the two straight lines when they cross zero points are calculated respectively, the difference between the horizontal coordinates is calculated, and then the sine wave period is calculated according to the sampling period, and then the frequency is calculated according to the sine wave period; even when the alternating current waveform has a certain distortion (high noise or harmonic content), the zero-crossing point measurement is still not affected, the accuracy of measuring the zero-crossing point is not affected by the initial phase and the number of samples, and the frequency calculation accuracy is high.
[0145] Embodiment 4
[0146] The present invention also provides another embodiment, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the AC frequency calculation method as described above.
[0147] The beneficial effects of implementing this embodiment are as follows: first, an alternating current signal is acquired; periodically samples the alternating current signal to obtain a sampling sequence; arccosine calculation is performed on the sampling sequence to obtain an arccosine value; the arccosine value is clipped to obtain a clipped value; two intervals with the same direction of change between a preset minimum value and a preset maximum value are retrieved from the clipped value; the two intervals are linearly fitted by the least squares method to obtain two straight lines; the horizontal coordinates of the two straight lines when they cross zero points are calculated respectively, the difference between the horizontal coordinates is calculated, and then the sine wave period is calculated according to the sampling period, and then the frequency is calculated according to the sine wave period; even when the alternating current waveform has a certain distortion (high noise or harmonic content), the zero-crossing point measurement is still not affected, the accuracy of measuring the zero-crossing point is not affected by the initial phase and the number of samples, and the frequency calculation accuracy is high.
[0148] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the various embodiment methods of the present invention.
[0149] Obviously, the embodiments described above are only some embodiments of the present invention, rather than all embodiments. The preferred embodiments of the present invention are given in the accompanying drawings, but they do not limit the patent scope of the present invention. The present invention can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present invention more thorough and comprehensive. Although the present invention has been described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific embodiments, or to perform equivalent replacements for some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of the present invention, directly or indirectly used in other related technical fields, is also within the scope of patent protection of the present invention.
Claims
1. A method for calculating the frequency of alternating current, characterized in that: The steps include: Acquire AC power signal; The alternating current signal is periodically sampled to obtain a sampling sequence S1, S2, S3, ..., Sn, where n is the number of sampling points; Performing arccosine calculation on the sampling sequences S1, S2, S3, ..., Sn to obtain arccosine values Cn; The arccosine value Cn is clipped to obtain a clipped value Dn; Searching for two intervals with the same direction of change between the preset minimum value and the preset maximum value in the value Dn after the top and bottom are cut, namely Di~Di+kk, Dj~Dj+k; Perform the least squares linear fitting on the two intervals to obtain two straight lines and , and ; Calculate two straight lines separately and The horizontal coordinate when it crosses zero and , calculate the horizontal coordinate and The difference between them is used to calculate the sine wave period according to the sampling period, that is, , and then calculate the frequency based on the sine wave period, .
2. The method for calculating the frequency of alternating current according to claim 1, characterized in that: The step of periodically sampling the AC signal to obtain a sampling sequence S1, S2, S3, ..., Sn specifically includes: Select the sampling frequency; Determine the sampling period; Synchronous trigger sampling; Select sampling points to obtain a sampling sequence S1, S2, S3, ..., Sn; Store sampling sequence S1, S2, S3, ..., Sn.
3. The method for calculating the frequency of alternating current according to claim 1, characterized in that: The step of performing arccosine calculation on the sampling sequences S1, S2, S3, ..., Sn to obtain the arccosine value Cn specifically includes: calculate , where A is the AC signal amplitude, that is .
4. The method for calculating the frequency of alternating current according to claim 1, characterized in that: The step of clipping the arccosine value Cn to obtain the clipped value Dn specifically includes: calculate .
5. The method for calculating the frequency of alternating current according to claim 1, characterized in that: The step of searching for two intervals with the same direction of change between the preset minimum value and the preset maximum value in the value Dn after the top and bottom are cut, namely Di~Di+k, Dj~Dj+k, specifically includes: Set specific values for the preset minimum value and the preset maximum value; Traverse the clipped value Dn, search for two intervals with the same direction of change between the preset minimum value and the preset maximum value, and obtain Di~Di+k, Dj~Dj+k.
6. The method for calculating the frequency of alternating current according to claim 1, characterized in that: The least squares linear fitting is performed on the two intervals to obtain two straight lines. and , and The steps specifically include: Determine the fitting interval and ; Setting up the linear model ; In the fitting interval, according to the set linear model, determine , , and The value of is obtained by least squares linear fitting to obtain two straight lines and and .
7. The method for calculating the frequency of alternating current according to claim 1, characterized in that: The two straight lines are calculated separately and The horizontal coordinate when it crosses zero and , calculate the horizontal coordinate and The difference between them is used to calculate the sine wave period according to the sampling period, that is, Then calculate the frequency based on the sine wave period, The steps specifically include: make ; make ; The sine wave period is calculated according to the sampling period, that is, ; Calculate the frequency based on the sine wave period, .
8. An alternating current frequency calculation device, characterized in that: include: An acquisition module, used for acquiring an alternating current signal; A sampling module, used for periodically sampling the AC signal to obtain a sampling sequence S1, S2, S3, ..., Sn, where n is the number of sampling points; An arccosine calculation module, used for performing arccosine calculation on the sampling sequences S1, S2, S3, ..., Sn to obtain an arccosine value Cn; A clipping module, used for clipping the arccosine value Cn to obtain a clipped value Dn; A search module is used to search for two intervals with the same direction of change between a preset minimum value and a preset maximum value in the value Dn after being clipped, namely Di~Di+k, Dj~Dj+k; The linear fitting module is used to perform the least squares linear fitting on two intervals to obtain two straight lines. and , and ; Frequency calculation module, used to calculate two straight lines separately and The horizontal coordinate when it crosses zero and , calculate the horizontal coordinate and The difference between them is used to calculate the sine wave period according to the sampling period, that is, , and then calculate the frequency based on the sine wave period, .
9. A computer device, comprising a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the method for calculating the frequency of alternating current according to any one of claims 1 to 7 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the method for calculating the frequency of alternating current according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Three-phase alternating current frequency sampling method realized by software algorithm
CN103235177A
Current voltage frequency tracking method of secondary side in isolated grid frequency conversion system
CN106018958A
Time domain measuring method of linear frequency modulation signal frequency characteristic parameters
CN108519511A
Grid frequency estimation method
CN109374966A
Unitary regression frequency measurement method, electronic equipment and storage medium
CN110069984A
Cited By
Signal frequency measurement method and device, equipment and storage medium
CN119619623A
