1 |
41 |
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.normal_distribution_random_noise.all;
|
6 |
|
|
|
7 |
|
|
--by MEP 22 February 2011
|
8 |
|
|
--usage:
|
9 |
|
|
--these are functions, which means they can be on the right-hand side
|
10 |
|
|
--of an assignment. These functions create an I and Q sample.
|
11 |
|
|
--The arguments are
|
12 |
|
|
--a natural number standing for the index of the sample,
|
13 |
|
|
--a real number that provides a way to have many samples per period,
|
14 |
|
|
--a real number standing for the standard deviation of the normally distributed noise added to the sample,
|
15 |
|
|
--a real number standing for the amplitude of the signal,
|
16 |
|
|
--a natural number indicating the width of the vector holding the returned value,
|
17 |
|
|
--a real number indicating the gain error of Q with respect to I,
|
18 |
|
|
--and a real number indicating the phase error of Q with respect to I
|
19 |
|
|
--
|
20 |
|
|
--create_I_sample(n_dat, freq, sgma, amplitude, return_width);
|
21 |
|
|
--create_Q_sample(n_dat, freq, sgma, amplitude, return_width, e1, a1);
|
22 |
|
|
--
|
23 |
|
|
|
24 |
|
|
package create_sample is
|
25 |
|
|
|
26 |
|
|
function create_I_sample(
|
27 |
|
|
n_dat : integer;
|
28 |
|
|
freq : real;
|
29 |
|
|
sgma : real;
|
30 |
|
|
amplitude : real;
|
31 |
|
|
return_width : natural)
|
32 |
|
|
return signed;
|
33 |
|
|
|
34 |
|
|
function create_Q_sample(
|
35 |
|
|
n_dat : integer;
|
36 |
|
|
freq : real;
|
37 |
|
|
sgma : real;
|
38 |
|
|
amplitude : real;
|
39 |
|
|
return_width : natural; --x1_tb'LENGTH
|
40 |
|
|
e1 : real; --gain error
|
41 |
|
|
a1 : real) --phase error
|
42 |
|
|
return signed;
|
43 |
|
|
|
44 |
|
|
end package create_sample;
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
package body create_sample is
|
48 |
|
|
|
49 |
|
|
function create_I_sample(
|
50 |
|
|
n_dat : integer;
|
51 |
|
|
freq : real;
|
52 |
|
|
sgma : real;
|
53 |
|
|
amplitude : real;
|
54 |
|
|
return_width : natural) --x1_tb'LENGTH
|
55 |
|
|
return signed is
|
56 |
|
|
|
57 |
|
|
variable local_x1 : real;
|
58 |
|
|
variable int_x1: integer;
|
59 |
|
|
variable returned_x1 : signed(return_width downto 0);
|
60 |
|
|
|
61 |
|
|
begin
|
62 |
|
|
|
63 |
|
|
local_x1 := amplitude*sin(2.0*math_pi*(real(n_dat))*freq) + random_noise(sgma);
|
64 |
|
|
--report "local_x1 inside CREATE_I_SAMPLE function is " & real'image(local_x1) & ".";
|
65 |
|
|
|
66 |
|
|
--AGC scaling. Scaling factor is maximum value the signal can take.
|
67 |
|
|
local_x1 := local_x1/(1.11);
|
68 |
|
|
--report "local_x1 after AGC inside CREATE_I_SAMPLE function is " & real'image(local_x1) & ".";
|
69 |
|
|
|
70 |
|
|
int_x1 := integer(trunc(local_x1*((2.0**31.0)-1.0))); --scaled
|
71 |
|
|
--report "integer version of x1 inside CREATE_I_SAMPLE function is " & integer'image(int_x1) & ".";
|
72 |
|
|
|
73 |
|
|
returned_x1 := (to_signed(int_x1, return_width+1));
|
74 |
|
|
|
75 |
|
|
return returned_x1;
|
76 |
|
|
end function;
|
77 |
|
|
|
78 |
|
|
function create_Q_sample(
|
79 |
|
|
n_dat : integer;
|
80 |
|
|
freq : real;
|
81 |
|
|
sgma : real;
|
82 |
|
|
amplitude : real;
|
83 |
|
|
return_width : natural; --x1_tb'LENGTH
|
84 |
|
|
e1 : real; --gain error
|
85 |
|
|
a1 : real)
|
86 |
|
|
return signed is
|
87 |
|
|
|
88 |
|
|
variable local_y1 : real;
|
89 |
|
|
variable int_y1: integer;
|
90 |
|
|
variable returned_y1 : signed(return_width downto 0);
|
91 |
|
|
|
92 |
|
|
begin
|
93 |
|
|
local_y1 := amplitude*(1.0 + e1)*cos(2.0*math_pi*(real(n_dat))*freq + a1) + random_noise(sgma);
|
94 |
|
|
--report "local_y1 first created CREATE_Q_SAMPLE function is " & real'image(local_y1) & ".";
|
95 |
|
|
|
96 |
|
|
--AGC scaling. Scaling factor is maximum value the signal can take.
|
97 |
|
|
local_y1 := local_y1/(1.11);
|
98 |
|
|
--report "local_y1 after AGC inside CREATE_Q_SAMPLE function is " & real'image(local_y1) & ".";
|
99 |
|
|
|
100 |
|
|
int_y1 := integer(trunc(local_y1*((2.0**31.0)-1.0))); --scaled
|
101 |
|
|
--report "integer version of y1 inside CREATE_Q_SAMPLE function is " & integer'image(int_y1) & ".";
|
102 |
|
|
|
103 |
|
|
returned_y1 := (to_signed(int_y1, return_width+1));
|
104 |
|
|
|
105 |
|
|
return returned_y1;
|
106 |
|
|
end function;
|
107 |
|
|
end package body create_sample;
|