OpenCores
URL https://opencores.org/ocsvn/iqcorrection/iqcorrection/trunk

Subversion Repositories iqcorrection

[/] [iqcorrection/] [trunk/] [Generate_Normal_Distribution_Random_Noise.vhd] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 40 Abraxas3d
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.math_real.all;
4
use ieee.numeric_std.all;
5
use work.random_int.all;
6
 
7
--by MEP 22 February 2011
8
--usage:
9
--this is a function, which means it can be on the right-hand side
10
--of an assignment. It returns a mean-zero random number from a
11
--normal distribution. The argument is a real number that indicates
12
--the standard deviation desired. 
13
--
14
--random_noise(sigma);
15
--
16
 
17
package normal_distribution_random_noise is
18
 
19
        function random_noise (
20
        sigma : real)
21
        return real;
22
 
23
end package normal_distribution_random_noise;
24
 
25
 
26
package body normal_distribution_random_noise is
27
 
28
        function random_noise (
29
        sigma : real
30
        )
31
        return real is
32
 
33
                --variables
34
                variable u_noise: real; --uniform distribution noise
35
                variable n_noise: real := 0.0; --normal distribution noise
36
                variable seed1 : positive;
37
                variable seed2 : positive;
38
 
39
        begin
40
 
41
                --obtain a uniformly distributed random number
42
                uniform(seed1, seed2, u_noise);
43
                --report "Random uniform noise is " & real'image(u_noise) & ".";
44
 
45
                for normal_count in 0 to 12 loop
46
                --Turn the uniform distributed number 
47
                --into a normally distributed number
48
                --by using the central limit theorem.
49
                --Make it mean zero and make it have
50
                --the range of the uniform numbers
51
                --that it is composed from. 
52
                n_noise := n_noise + u_noise;
53
                end loop;
54
 
55
                n_noise := n_noise - (0.5)*(real(12)); --normal distribution with a mean of zero
56
                --report "Random normal noise is " & real'image(n_noise) & ".";
57
                n_noise := n_noise/(real(12));
58
                --report "Random normal noise using range of uniform is " & real'image(n_noise) & ".";
59
                n_noise := sigma*n_noise;
60
 
61
                return n_noise;
62
        end function random_noise;
63
end package body normal_distribution_random_noise;
64
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.