Arbitrarily distributed noise real-time synthesis method based on ROM resources in FPGA
By using the Gaussian mixture model and EM algorithm to fit the distribution function on the FPGA side to generate noise with a specified distribution, it solves the problems of unstable random number generation rate, large ROM resource overhead and large low-probability output errors in the existing technology, and achieves Stable and flexible random number generation.
Patent Information
- Application Number
- CN202410784424.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-09-24
AI Technical Summary
When the existing technology generates random numbers of any specified distribution, there are problems such as unstable random number generation rate, large ROM resource overhead, large low-probability random number output errors, and numerous and inflexible configuration parameters.
Using FPGA-based ROM resources, the Gaussian mixture model and EM algorithm are used on the host computer to fit the distribution function to be fitted, and the mean and variance of the Gaussian distribution synthetic model are obtained, and ROM and RAM are used on the FPGA side to store the required function values. and model parameters, and generate noise obeying the specified distribution through Box-Muller transformation and chaos model.
It achieves stable generation of any specified distribution noise, improves randomness while reducing low-probability random number output errors, reduces configuration parameters, and enhances configuration flexibility.
Smart Images

Figure CN118689449A
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of random number generation, and more specifically, relates to a real-time synthesis method of arbitrarily distributed noise based on ROM resources in FPGA. Background Art
[0002] Arbitrary specified distribution noise is usually obtained by random numbers of arbitrary specified distribution, such as binomial distribution, Poisson distribution, exponential distribution and normal distribution, through digital-to-analog conversion (DAC). Therefore, how to generate random numbers of various specified distributions has become a problem that must be solved in the application of computer technology in simulation and other fields. When generating "random numbers of arbitrary specified distributions", the existing "uniformly distributed random numbers" are usually used. With uniformly distributed pseudo-random numbers, random numbers of arbitrary specified distributions can be obtained through various transformations and mapping relationships. The existing methods mainly include inverse function method, table lookup method and rejection method.
[0003] 1. Inverse function method
[0004] The inverse function method is based on the inverse transform sampling theory. First, the inverse function of the random number function of the required probability distribution is obtained. Secondly, such an inverse function operation module is constructed on the hardware. Then, the uniformly distributed random numbers are input into the inverse function operation module for real-time calculation. Finally, the calculation results are output through DAC. In this way, random numbers that meet the specified distribution can be generated in theory.
[0005] The process is as follows:
[0006] (1) A random number r uniformly distributed in the interval [0, 1] is known;
[0007] (2) Perform an inverse transformation on the random number function F(x) of the required probability distribution and solve the inverse function F of the random number function F(x) -1 (z);
[0008] (3) Let Z = F -1 (r), then Z is a random number that obeys the probability distribution function F(x);
[0009] Therefore, as long as we know the inverse function F of the required probability distribution function F(x) -1 (z), we can generate random numbers that obey the required specified distribution from random numbers uniformly distributed in [0, 1].
[0010] However, some probability distribution functions are not elementary functions, and it is difficult to obtain their inverse functions. In addition, it is extremely complex to construct the inverse functions on hardware, and even an inverse function operation module cannot be constructed to transform and output uniformly distributed random numbers. Therefore, only some mathematical methods can be used to approximate and obtain the inverse function, or a large-capacity memory is used to store the mapping relationship between the domain and range of the probability distribution function. Since real-time mathematical operations need to be performed on the input, the output speed is slow.
[0011] 2. Rejection Sampling Method
[0012] The basic principle of the rejection sampling method is as follows: Let the probability distribution function of the given random number be f(x), and U1 and U2 be random numbers uniformly distributed in the ranges (0, a) and (0, b) respectively. If U2 < f(U1), then U1 is output; otherwise, U1 is rejected, that is, not output. In this way, the distribution of the output random numbers satisfies the probability distribution function f(x).
[0013] As Figure 1 shown, the area of the shaded part is S, then the output efficiency is η = S / (ab). Assuming that the generation rate of uniformly distributed random numbers is W(in), then the average rate of outputting random numbers with a given probability distribution is: W(out) = ηW(in).
[0014] In the FPGA implementation process of the rejection sampling method, a corresponding function operation module is constructed according to the given probability distribution function f(x) for real-time calculation and output. For a relatively complex probability distribution function f(x), it can be directly discretized and stored in the ROM (the ROM stores the probability distribution function f(x), rather than the calculated random number samples). Subsequently, the uniformly distributed random number (i.e., U1) is used to address, read the value (i.e., f(U1)) of the probability distribution function f(x) stored in the ROM, and determine whether U2 < f(U1) is satisfied. If the judgment is satisfied, then U1 is output. If not, no random number is output at the current clock.
[0015] The implementation of the rejection sampling method is relatively simple, and the ROM resource overhead is small. Only the discretized probability distribution function needs to be stored, but the random number generation rate is unstable, and it cannot be guaranteed that there is a random number that meets the requirements at each clock. Experiments show that the acceptance rate of the triangular distribution is 50%, and the acceptance rate of the standard normal distribution (4σ) is 31.33%.
[0016] 1.3 Lookup Table Method
[0017] The lookup table method is one of the most commonly used methods for generating random numbers with any specified distribution. As Figure 2As shown in the figure, the table lookup method is to calculate a group of random numbers that conform to the probability distribution according to the probability distribution function (Probability Distribution Function) f(x) of the random number through the host computer (PC) software in advance and store them in the memory ROM of the FPGA, map the uniformly distributed random number x1 as input to the actual physical address, and then address and output the random number x2. The probability distribution of the random number x2 conforms to the probability distribution function f(x).
[0018] The table lookup method is the simplest and most intuitive to implement. It does not require complex calculations and has fast and stable output. However, the output depends on pre-stored random numbers that conform to the probability distribution, and has poor randomness. In addition, due to the limitation of ROM storage depth, the output error of low-probability random numbers is large.
[0019] Use the table lookup method to generate Figure 3 Taking the random number of the probability distribution function (pdf) of (a) as an example, the bit width of the generated random number is set to 10 bits, and the sampling error of the low probability sample is less than 5%. The statistical results of the generated random number sample set (pdfint rom) are as follows Figure 3 As shown in the figure (b), the total number of samples in the random number sample set is 96301. When implemented in FPGA, a ROM space with a depth of 96301 bits and a width of 10 bits (a total of 963010 bits of ROM space) is required to store the random number table and wait for the subsequent use of uniformly distributed random numbers for addressing and output.
[0020] If you want to set the generated random number width to 14 bits, the required ROM depth is 1540265 and the width is 14, which consumes a lot of ROM resources. In addition, the configuration parameters are numerous and inflexible. Summary of the invention
[0021] The purpose of the present invention is to overcome the shortcomings of the prior art and provide a real-time synthesis method of arbitrarily distributed noise based on ROM resources in FPGA, so as to achieve stable generation of arbitrarily specified distributed noise and improve its randomness. At the same time, it reduces the output error of low-probability random numbers and reduces configuration parameters, thereby enhancing configuration flexibility.
[0022] To achieve the above-mentioned object of the invention, the present invention provides a real-time synthesis method of arbitrarily distributed noise based on ROM resources in FPGA, which is characterized by comprising the following steps:
[0023] (1) Obtain the mean and variance of K pairs of H groups on the host computer
[0024] 1.1) Take the distribution function of any specified random number distribution as the distribution function to be fitted f(x), and obtain N observation data y according to the distribution function f(x) j =f(xj ), j = 1, 2, ..., N, x j is the number of uniform values within the range of values of the distribution function f(x);
[0025] 1.2) Initialize the mean of K groups and variance k=1,2,...,K,initialize the number of iterations i=0;let the amplitude interval of the noise to be fitted be [A min , A max ], then the initial value distribution of K groups of Gaussian models is set as follows:
[0026]
[0027] 1.3) Calculate the jth observation data y under the i-th iteration j The probability of the k-th arbitrary Gaussian distribution synthesis model
[0028]
[0029] in, is the mean variance Gaussian distribution density function At y=y j Gaussian distribution density value when For the kth arbitrary Gaussian distribution synthesis model, the jth observation data y j responsiveness;
[0030] 1.4) Calculate the mean of the i+1th iteration variance
[0031]
[0032]
[0033] 1.5), judgment Is it smaller than the threshold ε1 set by Is it less than the set threshold ε2? If it is less than, or the number of iterations reaches the set upper limit, the iteration is terminated and the average value is variance k=1,2,...,K are respectively the mean μ of K for any Gaussian distribution synthesis model k and variance σ k , k = 1, 2, ..., K;
[0034] Replace the distribution function of any specified random number distribution, repeat steps 1.1) to 1.5), and obtain the mean μ of each group K of H groups for any Gaussian distribution synthesis model k and variance σ k , for the kth pair of the hth group, denoted as the mean and variance Among them, h=1, 2, ..., H, k=1, 2, ..., K, and sent to the FPGA end;
[0035] (2) Output any specified distributed noise on the FPGA side
[0036] 2.1) On the FPGA side, first use ROM1 and ROM2 to store the function values required for calculating the box-muller transform: ROM1 is used to store the function values corresponding to cos(2πu1) or sin(2πu1), the address width of ROM1 is N1 bits, the data width is 64 bits, and the data type is a double-precision floating point number, where u1 is:
[0037]
[0038] Where b1 is the address;
[0039] ROM2 is used to store The corresponding function value, ROM2 address width is N2 bits, data width is 64 bits, data type is double-precision floating point number, where u2 is:
[0040]
[0041] Among them, b2 is the address;
[0042] Then, use RAM to store the mean of H groups K of arbitrary Gaussian distribution synthesis models obtained from the host computer. and variance h=1,2,...,H,k=1,2,...,K,, the RAM storage depth is H×K, and H groups of different mixed Gaussian model parameters are cached at the same time, that is, the mean μ of any Gaussian distribution synthesis model k and variance σ k , k = 1, 2, ..., K, used for generating different arbitrarily specified distribution noises, the data width of the RAM is 128 bits, and each data consists of a mean and variance Composition, each occupies 64 bits;
[0043] 2.2) Synthesis of k-th Gaussian noise
[0044] First, the chaotic model is used as the digital entropy source to output N1+N2 bits of uniformly distributed random sequences, and the nth random number is rn , where n represents the data point number, the high N1 bits are used as address b1 to address ROM1, and the function value of cos(2πu1) or sin(2πu1) is obtained, and the low N1 bits are used as address b2 to address ROM2, and the result is The function value of , the bit width N1 of address b1 of ROM1 and the bit width N2 of address b2 of ROM2 should satisfy the constraints:
[0045]
[0046] The function value of cos(2πu1) or sin(2πu1) is obtained by Multiply the function value by , and get a random sequence that obeys the standard Gaussian distribution, denoted as x n ;
[0047] Then, the parameters of the Gaussian mixture model corresponding to the hth group in the RAM that needs to generate the specified distribution noise, that is, the mean, are read in sequence. and variance k=1, 2, ..., K, digital synthesis is performed, where the k-th Gaussian noise is:
[0048]
[0049] Among them, multiplication and addition operations are implemented using Floating-point IP core;
[0050] 2.3) Amplitude Limitation
[0051] For the k-th Gaussian noise To limit the amplitude:
[0052]
[0053] in,
[0054] 2.4) Normalization
[0055] For the k-th Gaussian noise Normalize and get the k-th Gaussian noise
[0056]
[0057] Among them, the parameters are:
[0058]
[0059] The parameters are sent online by the host computer in the form of double-precision floating point numbers;
[0060] According to the number of DAC bits N, the k-th channel Gaussian noise Convert to fixed point number;
[0061] (3) Noise output
[0062] DAC has 1 input, 1 output, K-way Gaussian noise k=1, 2, ..., K are input into DAC in sequence, and the analog signal obtained is amplified A max -A min times, and then set the bias voltage to A min , the output analog signal amplitude range is [A min , A max ] noise;
[0063] When the digital entropy source outputs the next random number r n+1 , repeat steps 2.2) to (3) to obtain noise that obeys the specified distribution.
[0064] The object of the present invention is achieved in this way.
[0065] In the prior art, the rejection method has low ROM resource overhead, and only the discretized probability distribution function needs to be stored in the ROM, but the random number generation rate is unstable. The table lookup method is simple and intuitive, does not require complex calculations, and has fast and stable output speed. However, the random numbers generated by the probability distribution function need to be stored in the ROM, which has high ROM resource overhead, and the output depends on the pre-stored data, which has poor randomness. At the same time, limited by the ROM storage depth, the output error of low-probability samples is large.
[0066] The present invention is based on the real-time synthesis method of arbitrary distributed noise in ROM resources in FPGA, which includes two parts: host computer end and FPGA end. The host computer end is based on the weakened GMM, using the EM algorithm to fit the given distribution function to be fitted, and the mean of each group K of H groups of arbitrary Gaussian distribution synthesis models is obtained. and variance Among them, h = 1, 2, ..., H, k = 1, 2, ..., K is sent to the FPGA end and stored in RAM. On the FPGA end, ROM1 and ROM2 are used to store the function values required for calculating the box-muller transformation, and then the chaotic model is used as a digital entropy source to output a uniformly distributed random sequence r n , divide it into two parts as addresses to address ROM1 and ROM2 respectively, multiply the obtained function values, and get a random sequence x that obeys the standard Gaussian distribution n , read the mean corresponding to the specified distribution and variance Synthesize k-th Gaussian noise After amplitude limiting and normalization, it is sent to DAC for digital-to-analog conversion, and the analog signal obtained is amplified. max-A min times, and then set the bias voltage to A min , the output analog signal amplitude range is [A min , A max ] and the noise obeys the specified distribution.
[0067] The present invention directly transforms the random sequence, and any specified distribution random number can be stably randomly generated without affecting the randomness. At the same time, when the distribution noise needs to be re-specified, a corresponding set of K pairs in RAM is selected to obtain the mean of any Gaussian distribution synthesis model. and variance The configuration is flexible and requires few configuration parameters. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] Figure 1 It is a diagrammatic illustration of the method of discarding and selecting;
[0069] Figure 2 It is a schematic diagram of the table lookup process;
[0070] Figure 3 is a specific example of a probability distribution function before and after discretization, wherein (a) is a probability distribution function curve before discretization, and (b) is a probability distribution function curve after discretization;
[0071] Figure 4 It is a schematic diagram of a specific example of Gaussian mixture model;
[0072] Figure 5 It is a schematic diagram of a specific example of a weakened Gaussian mixture model;
[0073] Figure 6 It is a flowchart of a specific implementation method of the real-time synthesis method of arbitrary distributed noise based on ROM resources in FPGA of the present invention;
[0074] Figure 7 It is a schematic diagram of a specific implementation method of the method for real-time synthesis of arbitrarily distributed noise based on ROM resources in FPGA of the present invention;
[0075] Figure 8 It is the phase trajectory diagram of the uniformly distributed random sequence output by the modulo 6-dimensional chaos model;
[0076] Fig. 9 is the distribution function to be fitted. f(x) is a specific example curve graph;
[0077] Fig.10 This is a diagram of the fitting using the EM algorithm based on the weakened Gaussian mixture model;
[0078] Fig.11 It is an example diagram of the final output of any specified distributed noise. DETAILED DESCRIPTION
[0079] 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.
[0080] The present invention uses Gaussian mixture model and EM algorithm to fit any specified distribution on the host computer side to obtain the fitting parameter, that is, the mean μ of K arbitrary Gaussian distribution synthesis models. k and variance σ k A Gaussian mixture model with corresponding fitting parameters is constructed on the FPGA side, and finally the generation of random numbers that obey any specified distribution is realized.
[0081] 1. Basic Theory
[0082] 1. Gaussian Mixture Model (GMM)
[0083] like Figure 4 As shown, the Gaussian mixture model (curve old) can be regarded as a model composed of K single Gaussian models (curve new), and these K single Gaussian models are the hidden variables of the mixture model. The Gaussian mixture model has the following probability distribution model:
[0084]
[0085] Among them, α k is the proportionality coefficient of each single Gaussian model, α k ≥0, and:
[0086]
[0087] φ(y|(θ k ) is the Gaussian distribution density, μ k , σ k are the mean and variance of the kth single Gaussian model.
[0088]
[0089] φ(y|(θ k ) also becomes the kth single Gaussian model.
[0090] The Gaussian mixture model is an extension of the single-Gaussian probability density function, which can smoothly approximate the density distribution of any shape. Based on this characteristic of the Gaussian mixture model, the present invention constructs a mixed Gaussian model with adjustable parameters on the FPGA side to achieve the output of any specified distribution random number sequence.
[0091] In FPGA, the Box-Muller algorithm can be used to generate multiple Gaussian models, which together form a Gaussian mixture model to achieve random number generation with any specified distribution.
[0092] However, the Gaussian mixture model:
[0093]
[0094] Parameter a k It reflects the contribution ratio of any single Gaussian model to the overall probability distribution function. This ratio is relatively complex to implement in FPGA. The FPGA side requires relatively complex logic to achieve the proportional output of the single Gaussian model. To facilitate the implementation on the FPGA side, the present invention fixes the proportional coefficient, i.e., the parameter α k =1 / K, that is, setting the contribution ratio of each sub-Gaussian model to the mixed model to be the same, then the following probability distribution model is obtained:
[0095]
[0096] It is referred to as the weakened Gaussian mixture model below, such as Figure 5 shown.
[0097] When using the weakened Gaussian mixture model to fit the density distribution of arbitrary shapes, due to the lack of a set of adjustable parameters (parameter α k is fixed to 1 / K), so compared with the standard Gaussian mixture model, the weakened Gaussian mixture model requires more sub-Gaussian models (that is, a larger value of K) to achieve a similar fitting effect. However, this design avoids the proportionality coefficient, i.e., parameter α k , only the number of sub-Gaussian models is simply increased, which is very easy to implement on the FPGA side (it can be achieved by increasing the parallel number of sub-Gaussian models or polling the output of a single Gaussian model).
[0098] 2. EM algorithm
[0099] After determining the basic idea of using a weakened Gaussian mixture model to fit any distribution, the next question is how to determine the relevant parameters of the mixture model, that is, how to determine the mean and variance of each sub-Gaussian distribution. This requires the use of the EM algorithm.
[0100] The EM algorithm is an iteration algorithm, which was proposed by Dempster et al. in 1977. It is used for the maximum likelihood estimation of the parameters of a probability model containing hidden variables, or the maximum a posteriori probability estimation. Each iteration of the EM algorithm consists of two steps: the E step to find the expectation; the M step to find the maximum. Therefore, this algorithm is called the expectation maximization algorithm, or EM algorithm for short.
[0101] The core idea of the EM algorithm is very simple and is divided into two steps: Expectation-Step and Maximization-Step. The E-Step mainly estimates parameters by observing data and existing models, and then uses the estimated parameter values to calculate the expected value of the likelihood function; while the M-Step is to find the corresponding parameters when the likelihood function is maximized. Since the algorithm ensures that the likelihood function increases after each iteration, the function will eventually converge.
[0102] The specific steps of the EM algorithm are:
[0103] Input: observed variable data Y, latent variable data Z, joint distribution P(Y, Z|θ), conditional distribution P(Y|Z, θ);
[0104] Output: Model parameters θ.
[0105] (1) Select the initial value of the parameter θ (0) , start iteration;
[0106] (2) Step E: denoted as θ (i) is the estimated value of the parameter θ for the i-th iteration. In the E step of the i+1-th iteration, calculate:
[0107]
[0108] Here, P(Z|Y,θ (i) ) is given the observed data Y and the current parameter estimate θ (i) Conditional probability distribution of latent variable data;
[0109] (3) Step M: Find the value that makes Q(θ, θ (i) ) maximizes θ and determines the parameter estimate θ for the i+1th iteration (i+1) :
[0110]
[0111] (4) Repeat steps E and M until convergence.
[0112] 3. Use the EM algorithm to estimate parameters for the weakened Gaussian mixture model
[0113] The weakened Gaussian mixture model expression used in the present invention is:
[0114]
[0115] Among them, φ(y|(θ k )) is the Gaussian distribution density,
[0116]
[0117] It is called the kth single Gaussian model.
[0118] Specifically for the weakened Gaussian mixture model parameter estimation used in the present invention, the steps of the EM algorithm are:
[0119] (1) Clarify hidden variables
[0120] It can be imagined that the observed data y j , j = 1, 2, ..., N. Reflects the observed data y j The data from the kth single Gaussian model is unknown, k = 1, 2, ..., K, with latent variables γ jk It is defined as follows:
[0121]
[0122] j=1,2,...,N;k=1,2,...,K
[0123] Hidden variable γ jk is a random variable between 0 and 1.
[0124] With the observed data y j and unobserved data, i.e., latent variables γ jk , then the complete data is:
[0125] (y j , γ j1 , γ j2 ,,...,γ jK ,),j=1,2,...,N
[0126] Thus, the log-likelihood function of the complete data can be written as:
[0127]
[0128] (2) Step E of the EM algorithm: Determine the Q function
[0129]
[0130]
[0131] Here we need to calculate E(γ jk |y,θ), denoted as
[0132]
[0133] Note that it is the jth observation data y under the current model parameters j The probability from the k-th sub-Gaussian model is called the k-th sub-Gaussian model for the observed data y j The above expression can be expressed iteratively as follows:
[0134]
[0135] in, is the mean variance Gaussian distribution density function At y=y j Gaussian distribution density value when For the kth arbitrary Gaussian distribution synthesis model, the jth observation data y j responsiveness.
[0136] Will as well as Substituting into the determined Q function, we get
[0137]
[0138] (3) M step of EM algorithm
[0139] The M-step of the iteration is to find the function Q(θ,θ (i) ) for the maximum value of θ, that is, to find the model parameters for the new round of iteration:
[0140]
[0141] use Represents θ (i+1) ,beg We only need to transform the Q function to Taking the partial derivative and setting it to 0, we get:
[0142]
[0143]
[0144] Repeat the above calculation until the value of the log-likelihood function no longer changes significantly.
[0145] Re-expressing the above in iterative form, we have:
[0146] The mean of the i+1th iteration variance
[0147]
[0148]
[0149] 2. Implementation steps
[0150] Based on the above theory, the present invention proposes a real-time synthesis method of arbitrarily distributed noise based on ROM resources in FPGA. Figure 6 , 7 As shown, the real-time synthesis method of any distributed noise based on ROM resources in FPGA of the present invention comprises the following steps:
[0151] Step S1: Obtain the mean and variance of K pairs of H groups on the host computer
[0152] Step S1.1: Take the distribution function of any specified random number distribution as the distribution function to be fitted f(x), and obtain N observation data y according to the distribution function f(x) j =f(x j ), j = 1, 2, ..., N, x j is the number of values that are uniformly distributed over the range of values of the distribution function f(x).
[0153] Step S1.2: Initialize K group means and variance k=1,2,...,K,initialize the number of iterations i=0;let the amplitude interval of the noise to be fitted be [A min , A max ], then the initial value distribution of K groups of Gaussian models is set as follows:
[0154]
[0155] In this embodiment, K=16.
[0156] Step S1.3: Calculate the jth observation data y in the i-th iteration j The probability of the k-th arbitrary Gaussian distribution synthesis model
[0157]
[0158] in, is the mean variance Gaussian distribution density function At y=y j Gaussian distribution density value when For the kth arbitrary Gaussian distribution synthesis model, the jth observation data y j responsiveness.
[0159] Step S1.4: Calculate the mean of the i+1th iteration variance
[0160]
[0161]
[0162] Step S1.5: Determination Is it smaller than the threshold ε1 set by Is it less than the set threshold ε2? If it is less than, or the number of iterations reaches the set upper limit, the iteration is terminated and the average value is variance k=1,2,…,K are respectively the mean μ of K for any Gaussian distribution synthesis model k and variance σ k , k=1,2,…,K.
[0163] Replace the distribution function of any specified random number distribution, repeat steps S1.1 to S1.5, and obtain the mean μ of each group K of H groups for any Gaussian distribution synthesis model k and variance σ k , for the kth pair of the hth group, denoted as the mean and variance Among them, h=1,2,…,H, k=1,2,…,K, and it is sent to the FPGA end.
[0164] Step S2: Output any specified distributed noise at the FPGA end
[0165] The standard high-speed noise synthesis follows the Box-Muller formula, which is expressed as
[0166]
[0167] Where u1 and u2 are two independent random sequences that obey a uniform distribution on the interval (0, 1). In the present invention, sin(2πu1) and The calculation is completed by table lookup, and its values are pre-stored in ROM1 and ROM2 respectively. During the calculation, a uniformly distributed random number sequence is used as the ROM read address, and sin(2πu1) and 2πu1 are read from ROM1 and ROM2 respectively. The corresponding values are then multiplied to obtain a random sequence x that obeys the standard Gaussian distribution. Specifically:
[0168] Step S2.1: On the FPGA side, first use ROM1 and ROM2 to store the function values required for calculating the box-muller transform: ROM1 is used to store the function values corresponding to cos(2πu1) or sin(2πu1), the address width of ROM1 is N1 bits, the data width is 64 bits, and the data type is a double-precision floating point number, where u1 is:
[0169]
[0170] Among them, b1 is the address.
[0171] ROM2 is used to store The corresponding function value, ROM2 address width is N2 bits, data width is 64 bits, data type is double-precision floating point number, where u2 is:
[0172]
[0173] Among them, b2 is the address.
[0174] Then, use RAM to store the mean of H groups K of arbitrary Gaussian distribution synthesis models obtained from the host computer. and variance h=1,2,...,H,k=1,2,...,K,, the RAM storage depth is H×K, and H groups of different mixed Gaussian model parameters are cached at the same time, that is, the mean μ of any Gaussian distribution synthesis model k and variance σ k , k = 1, 2, ..., K, used for generating different arbitrarily specified distribution noises, the data width of the RAM is 128 bits, and each data consists of a mean and variance Each occupies 64 bits.
[0175] Step S2.2: Synthesis of k-th Gaussian noise
[0176] First, the chaotic model is used as the digital entropy source to output N1+N2 bits of uniformly distributed random sequences, and the nth random number is r n , where n represents the data point number, the high N1 bits are used as address b1 to address ROM1, and the function value of cos(2πu1) or sin(2πu1) is obtained, and the low N1 bits are used as address b2 to address ROM2, and the result is The function value of , the bit width N1 of address b1 of ROM1 and the bit width N2 of address b2 of ROM2 should satisfy the constraints:
[0177]
[0178] When ROM1 and ROM2 resources are sufficient, in order to reduce fitting errors, the values of N1 and N2 should be as large as possible.
[0179] The function value of cos(2πu1) or sin(2πu1) is obtained by Multiply the function value by , and get a random sequence that obeys the standard Gaussian distribution, denoted as x n In this embodiment, x n N bits;
[0180] Then, the parameters of the Gaussian mixture model corresponding to the hth group in the RAM that needs to generate the specified distribution noise, that is, the mean, are read in sequence. and variance k=1, 2, ..., K, digital synthesis is performed, where the k-th Gaussian noise is:
[0181]
[0182] Among them, multiplication and addition operations are implemented using the Floating-point IP core.
[0183] In this embodiment, the read address of the RAM is generated by the FPGA end logic. When a specified distribution needs to be generated and the hth group of Gaussian mixture model parameters in the corresponding RAM need to be read, the read address of the RAM is cyclically incremented between hK-K+1 and hK, and the parameters except the hth group of Gaussian mixture model parameters, i.e., the mean, are continuously read. and variance k=1, 2, ..., K.
[0184] Step S2.3: Amplitude Limitation
[0185] The random Gaussian distribution random sequence output by the K arbitrary Gaussian distribution synthesis model constitutes the random number of any specified distribution, which obeys the arbitrary specified distribution. However, if the DAC is directly connected for output, the DAC may intercept the input data due to the amplitude exceeding the limit, resulting in the DAC outputting the wrong value, so it is also necessary to go through the output limit.
[0186] The host computer will set the upper limit A max and the lower bound A min The data y is converted into double-precision floating-point numbers and sent to the FPGA. The Compare function of the two Floating-point IPs inside the FPGA is used to compare the data in When both IP core outputs are "1", y in Remain unchanged, otherwise y in Equal to y i(n-1). It should be noted that the Compare operation requires 1 clock, so the y being compared in Hit once, then you can receive y correctly later in The value is:
[0187] For the k-th Gaussian noise To limit the amplitude:
[0188]
[0189] in,
[0190] Step S2.4: Normalization
[0191] For the k-th Gaussian noise Normalize and get the k-th Gaussian noise
[0192]
[0193] Among them, the parameters are:
[0194]
[0195] The parameters are sent online by the host computer in the form of double-precision floating point numbers.
[0196] According to the number of DAC bits N, the k-th channel Gaussian noise Convert to fixed-point number. In this embodiment, the Float-to-fxed of the Floating-point IP is used to convert to a fixed-point number. For example, if N=14, the output fixed-point number format is fix150 (1 sign, 14 integers, 0 decimals), thereby adjusting it to within the input range of the DAC.
[0197] Step S3: Noise output
[0198] DAC has 1 input, 1 output, K-way Gaussian noise k=1, 2, ..., K is input into DAC, and the analog signal obtained is amplified A max -A min times, and then set the bias voltage to A min , the output analog signal amplitude range is [A min , A max ]. When the digital entropy source outputs the next random number r n+1 , repeat steps S2.2 to S3, so as to obtain noise that obeys the specified distribution.
[0199] In this embodiment, the chaos model is a modulo 6-dimensional chaos model, and the 6-dimensional chaos model used is:
[0200]
[0201] x 2,k+1 =mod(x 1,k x 2,k +fx 2,k +3x 3,k -3x 4,k -x 2,k x 5,k , 4)
[0202] x 3,k+1 =mod(x 1,k +x 1,k x 6,k +5x 2,k +Cx 3,k +x 3,k x 6,k +(dcx 6,k )x 4,k -x 5,k -x 5,k x 6,k , 4)
[0203] x 4,k+1 =mod(x 1,k x 6,k +5x 3,k +x 3,k x 6,k +dx 4,k -x 4k x 6,k +x 5,k x 6,k , 4)
[0204]
[0205]
[0206] Here k represents the number of iterations. The model has chaotic characteristics in a large range. At the same time, due to the addition of modulo operation, the iterative output of the model has the characteristics of uniform distribution. The model is simulated in matlab, and the iterative phase trajectory diagram of the x1 and x2 dimensions is plotted as follows Figure 8 As shown. Obviously, each dimension of the model has good uniform distribution characteristics.
[0207] Examples
[0208] Fig. 9 is the distribution function f(x) to be fitted, Fig.10 This is the case where the EM algorithm is used for fitting based on the weakened Gaussian mixture model, and K = 16. Fig. 9 , 10It can be seen that the weakened Gaussian mixture model in the present invention well achieves the fitting of the distribution function of any specified distribution random number. The means and variances of the 16 groups are:
[0209]
[0210]
[0211] Table 1
[0212] It should be noted that the EM algorithm itself is sensitive to initial values. At the same time, in order to ensure the fitting effect of the FPGA side under limited precision. In the process of executing the EM algorithm for fitting here, we evenly spread the means of the 16 groups of sub-Gaussian models according to the range of the number axis. Avoid the means of the 16 groups of Gaussian distributions after fitting to be too concentrated, so that under the calculation of the effective precision of the FPGA side, a good fitting accuracy can be achieved.
[0213] The random numbers of any specified distribution are output limited, normalized and amplified at the analog end to obtain the final output of any specified distribution noise and draw a statistical graph. The results are as follows: Fig.11 shown.
[0214] from Fig.11 ,We can see that the obtained noise conforms to any specified distribution, and ,the experimental results illustrate the effectiveness of the present ,invention.
[0215] 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 real-time synthesis method of arbitrarily distributed noise based on ROM resources in FPGA, characterized in that: The following steps are involved: (1) Obtain the mean and variance of K pairs of H groups on the host computer 1.1) Take the distribution function of any specified random number distribution as the distribution function to be fitted f(x), and obtain N observation data y according to the distribution function f(x) j =f(x j ), j = 1, 2, ..., N, x j is the number of uniform values within the range of values of the distribution function f(x); 1.2) Initialize the mean of K groups and variance Initialize the number of iterations i = 0; let the amplitude range of the noise to be fitted be [A min , A max ], then the initial value distribution of K groups of Gaussian models is set as follows: 1.3) Calculate the jth observation data y under the i-th iteration j The probability of the k-th arbitrary Gaussian distribution synthesis model in, is the mean variance Gaussian distribution density function At y=y j Gaussian distribution density value when For the kth arbitrary Gaussian distribution synthesis model, the jth observation data y j responsiveness; 1.4) Calculate the mean of the i+1th iteration variance 1.5), judgment Is it smaller than the threshold ε1 set? Is it less than the set threshold ε2? If it is less than, or the number of iterations reaches the set upper limit, the iteration is terminated and the average value is variance As K respectively, the mean μ of the synthetic model of arbitrary Gaussian distribution k and variance σ k , k=1,2,…,K; Replace the distribution function of any specified random number distribution, repeat steps 1.1) to 1.5), and obtain the mean μ of each group K of H groups for any Gaussian distribution synthesis model k and variance σ k , for the kth pair of the hth group, denoted as the mean and variance Among them, h=1,2,…,H, k=1,2,…,K, and sent to the FPGA end; (2) Output any specified distributed noise on the FPGA side 2.1) On the FPGA side, ROM1 and ROM2 are first used to store the function values required for calculating the box-muller transform: ROM1 is used to store the function values corresponding to cos(2πu1) or sin(2πu1), the address width of ROM1 is N1 bits, the data width is 64 bits, and the data type is a double-precision floating point number, where u1 is: Where b1 is the address; ROM2 is used to store The corresponding function value is that the address width of ROM2 is N2 bits, the data width is 64 bits, and the data type is a double-precision floating point number, where u2 is: Among them, b2 is the address; Then, use RAM to store the mean of H groups K of arbitrary Gaussian distribution synthesis models obtained from the host computer. and variance The RAM storage depth is H×K, and H groups of different mixed Gaussian model parameters are cached at the same time, that is, the mean μ of any Gaussian distribution synthesis model k and variance σ k , k=1,2,…,K, used for generating different arbitrarily specified distribution noises, the data width of RAM is 128 bits, and each data consists of a mean and variance Composition, each occupies 64 bits; 2.2) Synthesis of k-th Gaussian noise First, the chaotic model is used as the digital entropy source to output N1+N2 bits of uniformly distributed random sequences, and the nth random number is r n , where n represents the data point number, the high N1 bits are used as address b1 to address ROM1, and the function value of cos(2πu1) or sin(2πu1) is obtained, and the low N1 bits are used as address b2 to address ROM2, and the result is The function value of , the bit width N1 of address b1 of ROM1 and the bit width N2 of address b2 of ROM2 should satisfy the constraints: The function value of cos(2πu1) or sin(2πu1) is obtained by The function value of is multiplied to obtain a random sequence that obeys the standard Gaussian distribution, denoted as x n ; Then, the parameters of the Gaussian mixture model corresponding to the hth group in the RAM that needs to generate the specified distribution noise, i.e., the mean, are read in sequence. and variance Perform digital synthesis, where the k-th Gaussian noise is: Among them, multiplication and addition operations are implemented using Floating-point IP core; 2.3) Amplitude Limitation For the k-th Gaussian noise To limit the amplitude: in, 2.4) Normalization For the k-th Gaussian noise Normalize and get the k-th Gaussian noise Among them, the parameters are: The parameters are sent online by the host computer in the form of double-precision floating point numbers; According to the number of DAC bits N, the k-th channel Gaussian noise Convert to fixed point number; (3) Noise output DAC has 1 input, 1 output, K-way Gaussian noise Input DAC in sequence, and the analog signal obtained is amplified A max -A min times, and then set the bias voltage to A min , the output analog signal amplitude range is [A min , A max ] noise; When the digital entropy source outputs the next random number r n+1 , repeat steps 2.2) to (3) to obtain noise that obeys the specified distribution.
