Fixed-point non-integer multiple downsampling method and device for high-precision harmonic analysis

Through the non-integer multiple down-sampling method based on linear interpolation, counters and comparators are used to calculate sampling points, which solves the problem of large harmonic errors in high-precision harmonic analysis and achieves higher analysis accuracy and lower resource consumption. .

CN118624982AActive Publication Date: 2024-09-10UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410822698.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-24
Publication Date
2024-09-10
Estimated Expiration
2044-06-24

AI Technical Summary

Technical Problem

Existing technology is difficult to effectively reduce harmonic errors in high-precision harmonic analysis, especially in the non-integer multiple downsampling process, especially when the input waveform frequency is unknown, resulting in spectrum leakage and low harmonic analysis accuracy.

Method used

A non-integer multiple down-sampling method based on linear interpolation is used. By initializing two counters and comparators, accumulating according to the sampling point coefficient, and calculating the sampling point value, non-integer multiple down-sampling is achieved and harmonic errors are reduced.

Benefits of technology

It significantly reduces harmonic errors and improves the accuracy of high-precision harmonic analysis. It is suitable for FPGA implementation, has low resource consumption, low hardware cost, and small frequency offset.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118624982A
    Figure CN118624982A
Patent Text Reader

Abstract

The invention discloses a non-integer multiple downsampling method and device for high-precision harmonic analysis, and the method comprises the steps: setting two counters for storing a time ordinal number count value CNT1 and a pumping point coefficient count value CNT2 respectively, enabling the time ordinal number count value CNT1 to be equal to CNT1 + 1 when a data effective signal valid of input data x [n] is detected, enabling the time ordinal number count value CNT2 to be equal to CNT1 + 1 when CNT1 is greater than or equal to CNT2, and enabling the pumping point coefficient count value CNT2 to be equal to CNT1 + 1 when CNT1 is greater than or equal to CNT2; if not, linear interpolation calculation is carried out according to the numerical value of the previous sampling point and the numerical value of the current sampling point to obtain a point extraction numerical value, and then the point extraction coefficient counting value is accumulated with a non-integral multiple point extraction coefficient M, namely CNT2 = CNT2 + M, so that non-integral multiple downsampling is realized. According to the method, non-integer multiple downsampling is realized based on linear interpolation, so that the harmonic error is reduced, and the method is better suitable for high-precision harmonic analysis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of digital signal processing, and more specifically, relates to a fixed-point non-integer multiple downsampling method and device for high-precision harmonic analysis. Background Art

[0002] Reducing the interference of harmonic components is an important issue in industrial production, and harmonic analysis plays a vital role in power quality analysis. Accurate harmonic analysis and prevention of spectrum leakage in Fast Fourier Transform (FFT) largely rely on the application of synchronous sampling.

[0003] In engineering, ADC generally uses fixed-frequency sampling mode, and the frequency of the external input waveform is unknown. In order to prevent spectrum leakage, it is necessary to extract the full-cycle data of the input waveform for FFT; and for the convenience of design, the number of FFT points is generally fixed, so after extracting the full-cycle data of this waveform, in order to downsample this data to the number of points specified by the FFT in the device, a sampling operation is required. Since the frequency of the external input waveform is unknown, before sampling, the number of points in one cycle of this waveform is also unknown, and it is likely that it is not an integer multiple of the number of points required for one cycle of FFT. Therefore, after completing the frequency measurement, it is necessary to calculate the sampling coefficient based on the frequency, and then perform non-integer multiple downsampling on the extracted full-cycle waveform data.

[0004] Currently, data sampling mainly includes integer multiple sampling and decimal multiple sampling:

[0005] Integer multiple sampling is the most commonly used sampling method when sampling data. For example, 2x sampling means sampling 1 point for every two sampling points (sampling coefficient is 2), 3x sampling means sampling 1 point for every 3 sampling points (sampling coefficient is 3), and Nx sampling means sampling 1 point for every N sampling points (sampling coefficient is N). For a sine wave, if the signal obtained after synchronous sampling originally has 4096 points in one cycle, and now it needs to be extracted into 512 points in one cycle before FFT transformation, then the sampling coefficient is 4096 / 512=8, that is, 1 point is extracted for every 8 points.

[0006] Fractional sampling is more complicated than integer sampling. For example, when performing synchronous sampling in a power analyzer, if the ADC always works at a fixed frequency and the input signal frequency is unknown, the number of sampling points for one cycle of the waveform needs to be determined after frequency measurement. For sine waves of different frequencies, the number of sampling points in one cycle may be 5634, 7813, 6838, and other irregular numbers. If they need to be extracted into 512 points in one cycle and then perform FFT, the sampling coefficient will become (taking 5634 as an example): 5634 / 512=11.00390625. This increases the difficulty of FPGA data sampling.

[0007] At present, some researchers (Yang Yunpeng, Mao Weicong, etc.) have adopted the method of "non-equally spaced sampling" to approximate the decimal sampling. However, studies have shown that this method may cause unacceptable harmonic errors and is not suitable for situations where high accuracy requirements are placed on harmonic analysis. Summary of the invention

[0008] The purpose of the present invention is to overcome the shortcomings of the prior art and provide a non-integer downsampling method and device for high-precision harmonic analysis, which implements non-integer downsampling based on linear interpolation, thereby reducing harmonic errors and making it better suitable for high-precision harmonic analysis.

[0009] In order to achieve the above-mentioned object of the invention, the fixed-point non-integer multiple downsampling method for high-precision harmonic analysis of the present invention comprises the following steps:

[0010] S1: Determine the non-integer multiple sampling coefficient M according to actual needs;

[0011] S2: Initialize two counters to store the time sequence count value CNT1 and the sampling coefficient count value CNT2 respectively, where:

[0012] The time sequence count value CNT1 is used to count the valid signal of the input data x[n], and its initial value is -1;

[0013] The sampling coefficient count value CNT2 is used to record the sampling accumulation coefficient, and its initial value is 0;

[0014] S3: When the valid signal of the input data x[n] is detected, the time sequence count value CNT1=CNT1+1;

[0015] S4: Determine whether CNT1 ≥ CNT2, if yes, go to step S5, otherwise return to step S3;

[0016] S5: Calculate the sampling point value [CNT2] using the following formula:

[0017] [CNT2]=(1-frac(CNT2))×[CNT1-1]+frac(CNT2)×[CNT1]

[0018] Wherein, [z] represents the value of the sampling point data at the time sequence number z, and frac(CNT2) represents the decimal of the sampling coefficient CNT2;

[0019] S6: Determine whether the sampling point end condition is met, if yes, end the sampling point, otherwise go to step S7;

[0020] S7: Set the sampling coefficient count value CNT2 = CNT2 + M, and return to step S3.

[0021] In addition, the present invention also provides a fixed-point non-integer multiple downsampling device for high-precision harmonic analysis, characterized in that it includes a first data register, a second data register, a time sequence counter, a sampling coefficient counter, a comparator, a front sampling point register, a rear sampling point register, a sampling coefficient decimal register, a sampling coefficient decimal complement calculator, a sampling coefficient decimal complement register and a sampling value calculator, wherein:

[0022] The first data register is used to receive input data x[n] and a corresponding data valid signal valid, store the current data x[n] when the data valid signal valid is pulled high, and load the existing data x[n-1] into the second data register;

[0023] The second data register is used to store the data x[n-1] sent by the first data register;

[0024] The time ordinal counter is used to count the valid data signal of the input data x[n]. The initial value of the time ordinal count value CNT1 is -1, and the bit width of the count value CNT1 is W. H ; The time sequence counter simultaneously monitors the data valid signal valid and the sampling valid signal draw_valid of the input data x[n], and the counting rule of its count value CNT1 is as follows:

[0025] When both the draw_valid signal and the valid signal are valid, the time sequence counter loads the integer value CNT2 of the draw_valid coefficient count value CNT2 from the draw_valid coefficient counter. H -1:W L ], let the time sequence count value CNT1=CNT1+1–CNT2[W H -1:W L ];

[0026] When the draw_valid signal is valid, but the data valid signal is invalid, the time sequence counter loads the integer value CNT2 of the draw_valid coefficient count value CNT2 from the draw_valid coefficient counter. H -1:W L ], let the time sequence count value CNT1 = CNT1 – CNT2 [W H -1:W L ];

[0027] When the draw_valid signal is invalid, but the data valid signal is valid, the time sequence count value CNT1 is set to CNT1+1;

[0028] When both the draw_valid signal and the valid data signal are invalid, the time sequence count value CNT1 remains unchanged;

[0029] The sampling coefficient counter is used to accumulate the sampling accumulation coefficient according to the sampling valid signal draw_valid received from the comparator. The initial value of the sampling coefficient count value CNT2 is 0, and the bit width of the count value CNT2 is W. H +W L , where W H is the integer bit width, W L is the decimal place width; whenever the draw_valid signal is valid, the draw_valid count value CNT2 = CNT2[W L -1:0]+M, where CNT2[W L -1:0] represents the decimal value of the count value CNT2, and M represents the preset non-integer multiple sampling coefficient;

[0030] The comparator is used to load the count value CNT1 of the time sequence counter and the count value CNT2 of the sampling coefficient counter, and to convert the low bit of the count value CNT1 into a bit width of W. L After adding 0, compare. If CNT1≥CNT2, make the valid signal draw_valid valid for one clock cycle, otherwise make the valid signal draw_valid remain invalid.

[0031] The previous sampling point register is used to load the previous sampling point data [CNT1-1] from the second data register and store it when the sampling point valid signal draw_valid is detected to be valid;

[0032] The post sampling point register is used to load the current sampling point data [CNT1] from the first data register and store it when the sampling point valid signal draw_valid is detected to be valid;

[0033] The sampling coefficient decimal register is used to load the decimal value CNT2[W] of the sampling coefficient from the sampling coefficient counter when the sampling valid signal draw_valid is detected. L -1:0];

[0034] The sampling coefficient decimal complement calculator is used to load the decimal value CNT2[W of the sampling coefficient from the sampling coefficient counter when the sampling valid signal draw_valid is detected to be valid. L -1:0] and calculate its complement 1-CNT2[W L -1:0] and output to the sampling coefficient fractional complement register;

[0035] The sampling coefficient decimal complement register is used to receive the complement 1-CNT2[W when the sampling valid signal draw_valid is effective. L -1:0] and register;

[0036] The sampling value calculator is used to load the previous sampling point data [CNT1-1], the current sampling point data [CNT1], the sampling coefficient decimal value CNT2 [W from the previous sampling point register, the next sampling point register, the sampling coefficient decimal register, and the sampling coefficient decimal complement calculator. L -1:0] and its complement 1-CNT2[W L -1:0], calculate the sampling value DATA and output it:

[0037] DATA=(1-CNT2[W L -1:0])×[CNT1-1]+CNT2[W L -1:0]×[CNT1].

[0038] The present invention is used for a non-integer multiple downsampling method and device for high-precision harmonic analysis. Two counters are set to respectively store a time sequence count value CNT1 and a sampling coefficient count value CNT2. When a valid data signal valid of the input data x[n] is detected, the time sequence count value CNT1=CNT1+1. When CNT1≥CNT2, a linear interpolation calculation is performed based on the previous sampling point value and the current sampling point value to obtain a sampling point value. Then, the sampling coefficient count value is accumulated with a non-integer multiple sampling coefficient M, that is, CNT2=CNT2+M, thereby realizing non-integer multiple downsampling.

[0039] The present invention proposes a non-integer multiple downsampling method based on linear interpolation, and implements it on FPGA based on fixed-point numbers to meet the requirements of low resource consumption, low hardware cost, high precision and small frequency offset during FPGA implementation, and greatly reduces the harmonic error caused by the "nearest neighbor decimal sampling method (non-uniform decimal sampling)" used in previous synchronous sampling. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 This is an example diagram of non-integer multiple data sampling points;

[0041] Figure 2 It is a flow chart of a specific implementation method of the fixed-point non-integer multiple downsampling method for high-precision harmonic analysis in the present invention;

[0042] Figure 3 : is a specific implementation structure diagram of the fixed-point non-integer multiple downsampling device for high-precision harmonic analysis in this embodiment;

[0043] Figure 4 is a structural diagram of the time sequence counter in this embodiment;

[0044] Figure 5 is a structural diagram of the sampling coefficient counter in this embodiment;

[0045] Figure 6 is a count value variation table when the sampling coefficient is 3.3 in this embodiment;

[0046] Figure 7 3 is a graph showing the change of the mean square error of the waveform after sampling of the present invention and the comparative method with the input frequency in this embodiment. DETAILED DESCRIPTION

[0047] The specific implementation of the present invention is described below in conjunction with the accompanying drawings so that those skilled in the art can better understand the present invention. It should be noted that in the following description, when the detailed description of known functions and designs may dilute the main content of the present invention, these descriptions will be omitted here.

[0048] In order to better illustrate the technical solution of the present invention, the principle derivation of the present invention is briefly described first.

[0049] Assume that the sampling rate of fixed-frequency sampling is f s , the frequency of the signal to be measured is f x , then in this fixed frequency mode, the number of points N1 in one cycle of the signal to be synchronized is:

[0050] N1=f s / f x

[0051] Now, for the measured signal frequency, it is necessary to synchronize the measured signal to a period of N2 (N1 ≥ N2), and take J consecutive periods to send to the FFT module for calculation. Then the original sampled signal must be sampled so that the number of sampling points in a period is downsampled from N1 to N2, and the sampling coefficient M = N1 / N2.

[0052] For ease of description, “[z]” is used to represent the numerical value of the sampling point data at the time sequence number z. Figure 1 This is an example diagram of non-integer multiple data sampling. Assume that after frequency measurement, the sampling coefficient of a certain frame of data is calculated to be 3.3, that is, for a frame of data points obtained by sampling, starting from the starting position 0, 1 point is extracted every 3.3 unit lengths, and the sampling positions are 0, 3.3, 6.6, 9.9, 13.2, 16.5..., and the obtained extracted values ​​are: [0], [3.3], [6.6], [9.9], [13.2], [16.5]... It can be seen that the sampling positions of the above data are obtained by accumulating the sampling coefficients, so the present invention calls it the sampling accumulation coefficient.

[0053] In the traditional decimal sampling method (non-equally spaced sampling), the actual points extracted are: [0], [3], [7],

[10] ,

[13] ,

[17] , etc. The present invention proposes an extraction method based on interpolation to perform more accurate decimal extraction on the sampled data. That is, the present invention will use the data of points [3] and [4] to calculate [3.3], use the data of points [6] and [7] to calculate [6.6], use the data of points [9] and

[10] to calculate [9.9], etc. (the point at [0] can directly use the first data in a frame of original data to be extracted).

[0054] The following uses the value [6.6] as an example to explain how to use the values ​​[6] and [7] to calculate the value [6.6]. Assuming that linear interpolation is used, the calculation method for the value [6.6] is as follows:

[0055] [6.6] = [6] + ([7] - [6]) × mod (6.6, 1)

[0056] Among them, mod(6.6,1) is 6.6 modulo 1, which is the decimal part of 6.6, that is, 0.6, so we have:

[0057] [6.6] = [6] + ([7] - [6]) × 0.6

[0058] More generally, assume that for two adjacent sampling points, their position numbers in a frame of data to be sampled are A and B, and now a decimal extraction calculation needs to be performed between them. The sampling accumulation coefficient obtained by frequency measurement, calculation, and accumulation of this frame of data is C, and the decimal part value of C is D, then:

[0059] [C]=[A]+([B]-[A])×D

[0060] Therefore, the numerical calculation formula of the sampling point can be obtained:

[0061] [C] = (1-D) × [A] + D × [B]

[0062] Based on the above principles, the present invention proposes a fixed-point non-integer multiple downsampling method for high-precision harmonic analysis. Figure 2 This is a flow chart of a specific implementation of the fixed-point non-integer multiple downsampling method for high-precision harmonic analysis in the present invention. Figure 2 As shown, the specific steps of the fixed-point non-integer multiple downsampling method for high-precision harmonic analysis in the present invention include:

[0063] S201: Determine the extraction coefficient:

[0064] Determine the non-integer multiple sampling coefficient M according to actual needs.

[0065] S202: Initialize counter:

[0066] In order to record the position ordinal of each data in a group of data frames to be processed, and record the cumulative value of the sampling coefficient, that is, the sampling cumulative coefficient, the present invention sets two counters to respectively store the time ordinal count value CNT1 and the sampling coefficient count value CNT2.

[0067] The time sequence count value CNT1 is used to count the data valid signal of the input data x[n] (each data valid signal corresponds to a valid data point). Since the first data in the input data x[n] is directly output and the sampling position is 0, the initial value of the count value CNT1 is set to -1, so that the count value of the first data is 0, and the output of the first data is realized. It can be seen that the count value CNT1 is used to record the position sequence of each data in the input data frame to be processed, that is, 0, 1, 2, 3, 4, 5, 6... and so on as mentioned above.

[0068] The sampling coefficient count value CNT2 is used to record the sampling accumulation coefficient, that is, after each data sampling, the count value CNT2 accumulates the sampling coefficient M, that is, CNT2 = CNT2 + M, and the initial value of the count value CNT2 is 0. In other words, the count value CNT2 will load the sampling coefficient calculated for the current data frame before each frame sampling begins, such as 3.3 in the previous example. In the future, when performing decimal sampling, each time a data point is extracted, CNT2 will accumulate the sampling coefficient once to obtain the current sampling accumulation coefficient, that is, the above-mentioned 0, 3.3, 6.6, 9.9, 13.2... and so on.

[0069] S203: Count value CNT1 is accumulated:

[0070] When the data valid signal in the input data frame is detected, the time sequence count value CNT1=CNT1+1.

[0071] S204: Determine whether CNT1 ≥ CNT2, if yes, go to step S205, otherwise return to step S203.

[0072] S205: Calculate the sampling point value:

[0073] Let the previous sampling point number of the sampling value A = CNT1-1, the next sampling point number B = CNT1, the accumulated sampling coefficient C = CNT2, D = frac(CNT2), frac(CNT2) represents the decimal of the sampling coefficient CNT2. For fixed-point numbers, the modulus operation of powers of 2 is essentially to truncate the low bits of the fixed-point number, because 1 = 2 0 , so mod(CNT2,1) actually takes the low-order decimal part of CNT2.

[0074] After substituting the calculation formula of the sampling point value, the calculation formula of the sampling point value [CNT2] is:

[0075] [CNT2]=(1-frac(CNT2))×[CNT1-1]+frac(CNT2)×[CNT1]

[0076] According to the previous definition, [z] represents the value of the sampling point data at the time sequence number z, then [CNT1-1] and [CNT1] represent the values ​​of the sampling point data at the time sequence numbers CNT1-1 and CNT1 respectively, and [CNT2] is the value of the sampling point data at the time sequence number CNT2, that is, the required sampling point value.

[0077] S206: Determine whether the sampling end condition is met, if yes, then end the sampling, otherwise go to step S207. The sampling end condition can be determined according to actual needs.

[0078] S207: Counter CNT2 accumulates:

[0079] Set the sampling coefficient counter CNT2=CNT2+M, and return to step S203.

[0080] Based on the above fixed-point non-integer multiple downsampling method, the present invention designs a fixed-point non-integer multiple downsampling device for high-precision harmonic analysis based on FPGA. In FPGA, if counters CNT1 and CNT2 count according to the method set in the decimal sampling method, then since the update time of a frame of data may be very long, it is necessary to set counters CNT1 and CNT2 with huge bit widths to accumulate continuously, which will cause a large waste of register resources. For example, for an ADC with a sampling rate of 5MHz, the update time is set to 1s, then 5×10 6The corresponding binary number occupies a bit width of 23 bits, which is only the bit width of the integer part. Assuming that the fractional part of the sampling coefficient is set to 16 bits to achieve higher precision, the minimum bit width of CNT2 will be 23+16=39 bits. When implementing a counter with a large bit width in FPGA, the timing is poor. The larger the bit width, the worse the timing, and it is even more impossible to run at a higher clock frequency. Therefore, when designing the fractional sampling device, the accumulation method of the counter is modified so that the value of the counter CNT1 and CNT2 is limited to the vicinity of the sampling coefficient.

[0081] Figure 3 It is a structural diagram of a specific implementation of the fixed-point non-integer multiple downsampling device for high-precision harmonic analysis in this embodiment. Figure 3 In order to simplify the structure, the clock signal and the reset signal of each register are omitted. Figure 3 As shown, the fixed-point non-integer downsampling device for high-precision harmonic analysis in this embodiment includes a first data register 1, a second data register 2, a time sequence counter 3, a sampling coefficient counter 4, a comparator 5, a front sampling point register 6, a rear sampling point register 7, a sampling coefficient decimal register 8, a sampling coefficient decimal complement calculator 9, a sampling coefficient decimal complement register 10 and a sampling value calculator 11, and each component is described in detail below.

[0082] The first data register 1 is used to receive input data x[n] and a corresponding data valid signal valid, store the current data x[n] when the data valid signal valid is pulled high, and send the existing data x[n-1] to the second data register 2.

[0083] The second data register 2 is used to store the data x[n-1] sent by the first data register 1. Obviously, the first data register 1 and the second data register 2 are used to record the data values ​​of every two adjacent data in a frame of input data. Once the two points meet the sampling condition at a certain moment, the data in the first data register 1 and the second data register 2 can be used to perform linear interpolation calculation.

[0084] The time sequence counter 3 is used to count the valid data signal of the input data x[n]. The initial value of the time sequence count value CNT1 is -1, and the bit width of the count value CNT1 is W. HObviously, since the count value CNT1 counts the data valid signal valid and is always an integer, it is only necessary to set the integer bit width. In the subsequent comparison process of the comparator 5, the decimal bit width can be padded with 0. This setting is mainly to align the decimal point of the count value CNT1 with the fixed-point number in the count value CNT2. The time ordinal counter 3 simultaneously monitors the data valid signal valid and the draw_valid valid signal of the input data x[n]. The counting rule of the count value CNT1 is as follows:

[0085] When both the draw_valid signal and the valid data signal are valid, that is, the draw_valid condition is met and the next input data is also valid, then when the next system clock is valid, the time sequence counter 3 loads the high-order part of the draw_valid coefficient count value CNT2 from the draw_valid coefficient counter 4, that is, the integer value CNT2[W H -1:W L ], let the time sequence count value CNT1=CNT1+1–CNT2[W H -1:W L ].

[0086] When the draw_valid signal is valid, but the valid signal is invalid, that is, the draw_valid condition is met, but the data input by the next clock is invalid, then when the next system clock is valid, the time sequence counter 3 loads the integer value CNT2[W of the draw_valid value] of the draw_valid coefficient count value CNT2 from the draw_valid coefficient counter 4. H -1:W L ], let the time sequence count value CNT1 = CNT1 – CNT2 [W H -1:W L ].

[0087] When the draw_valid signal is invalid but the data valid signal is valid, the time sequence count value CNT1=CNT1+1.

[0088] When both the draw_valid signal and the data valid signal are invalid, the time sequence count value CNT1 remains unchanged.

[0089] Figure 4 is a structural diagram of the time sequence counter in this embodiment. Figure 4 As shown, in this embodiment, the time sequence counter 3 includes a time sequence count value calculator 31, a multiplexer 32 and a time sequence count value register 33, wherein:

[0090] The time sequence count value calculator 31 is used to calculate three possible result values ​​of the time sequence count value, which are:

[0091] CNT1=CNT1+1–CNT2[W H -1:W L ]

[0092] CNT1=CNT1–CNT2[W H -1:W L ]

[0093] CNT1=CNT1+1

[0094] The multiplexer 32 is used to output the possible result values ​​of the time sequence count value according to the draw_valid signal and the valid signal. The specific rules are as follows:

[0095] When both the draw_valid signal and the valid data signal are valid, CNT1=CNT1+1–CNT2[W H -1:W L ] is output as a time sequence count value to the time sequence count value register 33;

[0096] When the draw_valid signal is valid, but the valid signal is invalid, CNT1 = CNT1–CNT2[W H -1:W L ] is output as a time sequence count value to the time sequence count value register 33;

[0097] When the draw_valid signal is invalid, but the data valid signal is valid, CNT1=CNT1+1 is output as the time sequence count value to the time sequence count value register 33;

[0098] When both the draw_valid signal and the data valid signal are invalid, the current time sequence count value is output to the time sequence count value register 33 .

[0099] The time sequence number count value register 33 is used to store the received time sequence number count value.

[0100] The sampling coefficient counter 4 is used to accumulate the sampling accumulation coefficient according to the sampling valid signal draw_valid received from the comparator 5. The initial value of the sampling coefficient count value CNT2 is 0. Similarly, the bit width of the count value CNT2 is W. H +W L , where W H is the integer bit width, W L is the decimal place width. Whenever the sampling valid signal is pulled high, the sampling sequence count value CNT2 = CNT2[WL -1:0]+M, where CNT2[0:W L -1] represents the decimal value of the count value CNT2, that is, the low-order part, and M represents a preset non-integer multiple sampling coefficient.

[0101] Figure 5 : is a structural diagram of the sampling coefficient counter in this embodiment. Figure 5 As shown, in this embodiment, the sampling coefficient counter 4 includes a sampling coefficient accumulation value calculation module 41, a multiplexer 42 and a sampling coefficient count value register 43, wherein:

[0102] The sampling coefficient accumulated value calculation module 41 is used to calculate the possible result value CNT2 of the sampling coefficient count value = CNT2[W L -1:0]+M.

[0103] The multiplexer 32 is used to select the possible result value of the sampling coefficient count value according to the sampling valid signal draw_valid for output, and the specific rules are as follows:

[0104] When the draw_valid signal is valid, CNT2 = CNT2[W L -1:0]+M is output as the sampling coefficient count value to the sampling coefficient count value register 43;

[0105] When the draw_valid signal is invalid, the current draw coefficient count value is output to the draw coefficient count value register 43.

[0106] The sampling coefficient count value register 43 is used to store the received time sequence count value.

[0107] Table 1 is a table showing the variation rules of the count values ​​in this embodiment.

[0108]

[0109] Table 1

[0110] As shown in Table 1, the values ​​of the data valid signal valid and the draw_valid signal represent the levels of the current clock cycle, and the values ​​of CNT1 and CNT2 represent the values ​​of CNT1 and CNT2 when the next clock rising edge arrives under the current valid and draw_valid conditions. It can be seen that in the present invention, when the draw_valid coefficient counter 4 accumulates the count value CNT2, it only accumulates the decimal part, and at the same time, when the time sequence counter 3 counts the data valid signal valid, it also subtracts the integer part of the count value CNT2. Therefore, after each sampling condition is met, CNT1 and CNT2 do not grow infinitely, but "shift to 0", keeping the relative size of CNT1 and CNT2 unchanged, and only performing a shift operation to reduce the values ​​recorded by CNT1 and CNT2. The integer part of CNT2 is subtracted from both CNT1 and CNT2, so that the values ​​of CNT1 and CNT2 are always maintained at a low level (near the sampling coefficient) and will not accumulate to overflow. In this way, for the decimal sampling processing of ultra-long data frames, the counter can also be set to a smaller bit width, so that its timing is better when implementing FPGA.

[0111] The comparator 5 is used to load the count value CNT1 of the time sequence counter 3 and the count value CNT2 of the sampling coefficient counter 4, and to perform a bit width W on the low bit of the count value CNT1. L After complementing with 0, if CNT1 ≥ CNT2, the draw_valid signal is valid for one clock cycle, otherwise the draw_valid signal remains invalid. It should be noted that the comparator here is a combinational logic rather than a sequential logic.

[0112] The previous sampling point register 6 is used to load the previous sampling point data [CNT1-1] from the second data register 2 and store it when detecting that the draw point valid signal draw_valid is valid.

[0113] The post-sampling point register 7 is used to load the current sampling point data [CNT1] from the first data register 1 and store it when detecting that the draw point valid signal draw_valid is valid.

[0114] The sampling coefficient decimal register 8 is used to load the decimal value CNT2[W of the sampling coefficient from the sampling coefficient counter when the sampling valid signal draw_valid is detected to be valid. L -1:0] and register it.

[0115] The sampling coefficient decimal complement calculator 9 is used to load the decimal value CNT2[W of the sampling coefficient from the sampling coefficient counter when the sampling valid signal draw_valid is detected to be valid. L-1:0] and calculate its complement 1-CNT2[W L -1:0] and output to the sampling coefficient fractional complement register 10. It should be noted that the sampling coefficient fractional complement calculator here is a combinational logic rather than a sequential logic.

[0116] The sampling coefficient decimal complement register 10 is used to receive the complement 1-CNT2[W when the sampling valid signal draw_valid is detected. L -1:0] and register it.

[0117] The sampling value calculator 11 is used to load the previous sampling point data [CNT1-1], the current sampling point data [CNT1], the sampling coefficient decimal value CNT2[W from the previous sampling point register 6, the next sampling point register 7, the sampling coefficient decimal register 8, and the sampling coefficient decimal complement register 10. L -1:0] and its complement 1-CNT2[W L -1:0], calculate the sampling value DATA and output it:

[0118] DATA=(1-CNT2[W L -1:0])×[CNT1-1]+CNT2[W L -1:0]×[CNT1]

[0119] like Figure 3 As shown, in this embodiment, the sampling value calculator 11 includes a first multiplier 111, a second multiplier 112 and an adder 113, wherein:

[0120] The first multiplier 111 is used to calculate the current sampling point data [CNT1] and the fractional value CNT2 [W L The product P1 = CNT2[W L -1:0]×[CNT1] and output to the adder 113.

[0121] The second multiplier 112 is used to calculate the previous sampling point data [CNT1-1] and the decimal value complement 1-CNT2 [W L -1:0] product P2 = (1-CNT2[W L -1:0])×[CNT1-1] and output to the adder 113.

[0122] The adder 113 is used to calculate the sum of the product P1 and the product P2, thereby obtaining the sampling value DATA=P1+P2.

[0123] It can be seen that in this embodiment, the first multiplier 111 and the second multiplier 112 first calculate the corresponding product in parallel, and then add the two to obtain the sampling value output. While calculating, the front-end data is still continuously input, the time sequence counter CNT1 and the sampling coefficient counter CNT2 are still counting and comparing, and the entire system is in a pipeline parallel state, thereby improving the sampling efficiency.

[0124] In order to better illustrate the technical effect of the present invention, a specific example is used to illustrate the timing of the present invention.

[0125] Example 1

[0126] In this embodiment, the sampling factor of 3.3 is taken as an example to illustrate the timing changes of the fixed-point non-integer multiple downsampling device of the present invention. Figure 6 This is a table showing the change of count values ​​when the sampling factor is 3.3 in this embodiment. Figure 6 As shown, each grid represents a clock cycle, the initial value of the time ordinal count value CNT1 is -1, and the initial value of the sampling coefficient count value CNT2 is 0. When the first data valid signal valid arrives, the time ordinal count value CNT1 becomes 0, CNT1=CNT2, and the data of the first data register becomes d0. The values ​​(0 and d0) in the current first data register and the second data register are entered into the front sampling point register and the rear sampling point register at the next clock rising edge, and then interpolation operations are performed (i.e., multiplication of one clock cycle and addition of one clock cycle), and then output after two clock cycles, thereby outputting d0 (green part), and inputting valid data d1 at the same time. At the same time, the sampling coefficient count value CNT2=0+3.3=3.3.

[0127] Then, at the next rising edge of the clock after the input data d1, CNT1+1 becomes 1, and the data in the first data register and the second data register are also recursively deduced to d1 and d0. Data is input until CNT1≥CNT2, and when 4≥3.3 in the table, the values ​​(d3 and d4) in the current first data register and the second data register are entered into the front sampling point register and the rear sampling point register at the next rising edge of the clock, and then interpolation operation is performed (i.e., multiplication of one clock cycle and addition of one clock cycle), and then d3.3 (green part) is output after two clock cycles. At the same time, at the next rising edge of the clock that meets the sampling condition, CNT2=the decimal part of CNT2+the sampling coefficient, which is 0.3+3.3=3.6 in the table; if the input data is still valid, then CNT1=CNT1+1-(the integer part of CNT2), which is 4+1-3=2, and then continue to count, and repeat this process.

[0128] If the external input data is invalid when the snapshot condition is met (i.e. the next data has not arrived yet), then the next clock rising edge CNT1 = CNT1-(the integer part of CNT2), as shown in the red "input invalid" part of the table above. And so on, until the last snapshot output is required.

[0129] Example 2

[0130] Next, the 5MHz / 8192-point synchronous sampling standard of the Yokogawa WT5000 power analyzer is used, and double floating-point numbers are used to simulate and compare the previously used method based on "non-equally spaced sampling" and the non-integer multiple downsampling method of the present invention in MATLAB, and the error size between the sampling method and the standard sinusoidal signal is compared.

[0131] Table 2 is a table of input data parameters when the number of FFT points is 8192 (5 MHz fixed frequency sampling) in this embodiment.

[0132]

[0133] Table 2

[0134] As shown in Table 2, "fundamental frequency" is the frequency of the lowest frequency component of the input sine wave data, "sampling rate" is the equivalent sampling rate after synchronous sampling, the number after f indicates the number of points required to be sampled in one cycle, and the window width indicates the number of cycles required to be sampled. In this embodiment, Table 2 is used as the standard for synchronous sampling to compare the two sampling methods.

[0135] Figure 7 : is a graph showing the mean square error of the waveform after sampling of the present invention and the comparative method in this embodiment as a function of the input frequency. Figure 7 As shown in the figure, compared with the non-equally spaced decimal sampling, the accuracy of the decimal sampling algorithm based on linear interpolation is optimized by orders of magnitude, and the higher the frequency, the more obvious the absolute value of the optimization, and when the frequency is low, the order of magnitude of the optimization is higher.

[0136] Although the above describes the illustrative specific embodiments of the present invention to facilitate those skilled in the art to understand the present invention, it should be clear that the present invention is not limited to the scope of the specific embodiments. For those of ordinary skill in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the attached claims, these changes are obvious, and all inventions and creations using the concept of the present invention are protected.

Claims

1. A fixed-point non-integer downsampling method for high-precision harmonic analysis, characterized in that: The following steps are involved: S1: Determine the non-integer multiple sampling coefficient M according to actual needs; S2: Initialize two counters to store the time sequence count value CNT1 and the sampling coefficient count value CNT2 respectively, where: The time sequence count value CNT1 is used to count the valid signal of the input data x[n], and its initial value is -1; The sampling coefficient count value CNT2 is used to record the sampling accumulation coefficient, and its initial value is 0; S3: When the valid signal of the input data x[n] is detected, the time sequence count value CNT1=CNT1+1; S4: Determine whether CNT1 ≥ CNT2, if yes, go to step S5, otherwise return to step S3; S5: Calculate the sampling point value [CNT2] using the following formula: [CNT2]=(1-frac(CNT2))×[CNT1-1]+frac(CNT2)×[CNT1] Wherein, [z] represents the value of the sampling point data at the time sequence number z, and frac(CNT2) represents the decimal of the sampling coefficient CNT2; S6: Determine whether the sampling point end condition is met, if yes, end the sampling point, otherwise go to step S7; S7: Set the sampling coefficient count value CNT2 = CNT2 + M, and return to step S3.

2. A fixed-point non-integer multiple downsampling device for high-precision harmonic analysis, characterized in that: It includes a first data register, a second data register, a time sequence counter, a sampling coefficient counter, a comparator, a front sampling point register, a rear sampling point register, a sampling coefficient decimal register, a sampling coefficient decimal complement calculator, a sampling coefficient decimal complement register and a sampling value calculator, wherein: The first data register is used to receive input data x[n] and a corresponding data valid signal valid, store the current data x[n] when the data valid signal valid is pulled high, and load the existing data x[n-1] into the second data register; The second data register is used to store the data x[n-1] sent by the first data register; The time sequence counter is used to count the valid data signal of the input data x[n]. The initial value of the time sequence count value CNT1 is -1. The bit width is W H ; The time sequence counter simultaneously monitors the data valid signal valid and the sampling valid signal draw_valid of the input data x[n], and the counting rule of its count value CNT1 is as follows: When both the draw_valid signal and the valid signal are valid, the time sequence counter loads the integer value CNT2 of the draw_valid coefficient count value CNT2 from the draw_valid coefficient counter. H -1:W L ], let the time sequence count value CNT1=CNT1+1–CNT2[W H -1:W L ]; When the draw_valid signal is valid, but the data valid signal is invalid, the time sequence counter loads the integer value CNT2 of the draw_valid coefficient count value CNT2 from the draw_valid coefficient counter. H -1:W L ], let the time sequence count value CNT1 = CNT1 – CNT2 [W H -1:W L ]; When the draw_valid signal is invalid, but the data valid signal is valid, the time sequence count value CNT1 is set to CNT1+1; When both the draw_valid signal and the valid data signal are invalid, the time sequence count value CNT1 remains unchanged; The sampling coefficient counter is used to accumulate the sampling accumulation coefficient according to the sampling valid signal draw_valid received from the comparator. The initial value of the sampling coefficient count value CNT2 is 0, and the bit width of the count value CNT2 is W. H +W L , where W H is the integer bit width, W L is the decimal place width; whenever the draw_valid signal is valid, the draw_valid count value CNT2 = CNT2[W L -1:0]+M, where CNT2[W L -1:0] represents the decimal value of the count value CNT2, and M represents the preset non-integer multiple sampling coefficient; The comparator is used to load the count value CNT1 of the time sequence counter and the count value CNT2 of the sampling coefficient counter, and to convert the low bit of the count value CNT1 into a bit width of W. L After adding 0, compare. If CNT1≥CNT2, make the valid signal draw_valid valid for one clock cycle, otherwise make the valid signal draw_valid remain invalid. The previous sampling point register is used to load the previous sampling point data [CNT1-1] from the second data register and store it when the sampling point valid signal draw_valid is detected to be valid; The post sampling point register is used to load the current sampling point data [CNT1] from the first data register and store it when the sampling point valid signal draw_valid is detected to be valid; The sampling coefficient decimal register is used to load the decimal value CNT2[W] of the sampling coefficient from the sampling coefficient counter when the sampling valid signal draw_valid is detected. L -1:0]; The sampling coefficient decimal complement calculator is used to load the decimal value CNT2[W of the sampling coefficient from the sampling coefficient counter when the sampling valid signal draw_valid is detected to be valid. L -1:0] and calculate its complement 1-CNT2[W L -1:0] and output to the sampling coefficient fractional complement register; The sampling coefficient decimal complement register is used to receive the complement 1-CNT2[W when the sampling valid signal draw_valid is effective. L -1:0] and register; The sampling value calculator is used to load the previous sampling point data [CNT1-1], the current sampling point data [CNT1], the sampling coefficient decimal value CNT2 [W from the previous sampling point register, the next sampling point register, the sampling coefficient decimal register, and the sampling coefficient decimal complement calculator. L -1:0] and its complement 1-CNT2[W L -1:0], calculate the sampling value DATA and output it: DATE=(1-CNT2[W L -1:0])×[CNT1-1]+CNT2[W L -1:0]×[CNT1]。 3. The fixed-point non-integer multiple downsampling device according to claim 2, characterized in that: The time sequence counter comprises a time sequence count value calculator, a multiplexer and a time sequence count value register, wherein: The Time Ordinal Count Value Calculator is used to calculate the three possible result values ​​of the time ordinal count value, which are: CNT1=CNT1+1–CNT2[W H -1:W L ] CNT1=CNT1–CNT2[W H -1:W L ] CNT1=CNT1+1 The multiplexer is used to output the possible result values ​​of the time sequence count value according to the draw_valid signal and the valid signal. The specific rules are as follows: When both the draw_valid signal and the valid data signal are valid, CNT1=CNT1+1–CNT2[W H -1:W L ] is output as the time sequence count value to the time sequence count value register; When the draw_valid signal is valid, but the valid signal is invalid, CNT1 = CNT1–CNT2[W H -1:W L ] is output as the time sequence count value to the time sequence count value register; When the draw_valid signal is invalid, but the data valid signal is valid, CNT1=CNT1+1 is output as the time sequence count value to the time sequence count value register; When both the draw_valid signal and the valid data signal are invalid, the current time sequence count value is output to the time sequence count value register; The time sequence count value register is used to store the received time sequence count value.

4. The fixed-point non-integer multiple downsampling device according to claim 2, characterized in that: The sampling coefficient counter includes a sampling coefficient accumulation value calculation module, a multiplexer and a sampling coefficient counting value register, wherein: The sampling coefficient accumulated value calculation module is used to calculate the possible result value CNT2 of the sampling coefficient count value = CNT2[W L -1:0]+M; The multiplexer is used to select the possible result values ​​of the sampling coefficient count value for output according to the sampling valid signal draw_valid. The specific rules are as follows: When the draw_valid signal is valid, CNT2 = CNT2[W L -1:0]+M is output as the sampling coefficient count value to the sampling coefficient count value register; When the draw_valid signal is invalid, the existing draw coefficient count value is output to the draw coefficient count value register; The sampling coefficient count value register is used to store the received time sequence count value.

5. The fixed-point non-integer multiple downsampling device according to claim 2, characterized in that: The sample value calculator comprises a first multiplier, a second multiplier and an adder, wherein: The first multiplier is used to calculate the current sampling point data [CNT1] and the fractional value CNT2 [W L The product P1 = CNT2[W L -1:0]×[CNT1] and output to the adder; The second multiplier is used to calculate the previous sampling point data [CNT1-1] and the fractional value complement of the sampling coefficient 1-CNT2 [W L -1:0] product P2 = (1-CNT2[W L -1:0])×[CNT1-1] and output to the adder; The adder is used to calculate the sum of the product P1 and the product P2, thereby obtaining the sampling value DATA=P1+P2.

Citation Information

Patent Citations

  • Method for analyzing electric network waveform distortions and automatically monitoring electric power harmonic parameters

    CN102338827A

  • Power quality spectrum calculation method based on non-integer points

    CN115456030A

  • Full-parallel arbitrary multiplying power variable sampling system

    CN120389753A

  • Non-integer decimation using cascaded intergrator-comb filter

    US7196648B1