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

Subversion Repositories iqcorrection

[/] [iqcorrection/] [branches/] [implemented with real variables/] [IQGainPhaseCorrection_arch_integer.vhd] - Blame information for rev 30

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 Abraxas3d
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
use ieee.std_logic_unsigned.all;
5
use ieee.math_real.all;
6
 
7
 
8
architecture IQGainPhaseCorrection_integer of IQGainPhaseCorrection is
9
 
10
 
11
begin
12
 
13
    correction : process (clk) is
14
 
15
        variable x1_real : real := 0.0;
16
        variable y1_real : real := 0.0;
17
        variable reg_1x1 : real := 0.0;
18
        variable y2      : real := 0.0;
19
        variable mu_1    : real := 0.000244;
20
        variable mu_2    : real := 0.000122;
21
        variable x1y2    : real := 0.0;
22
        variable reg_1   : real := 0.0;
23
        variable reg_2   : real := 1.0;
24
        variable y3      : real := 0.0;
25
 
26
        variable lock_counter : integer range 0 to 100 := 0;
27
        variable trail_reg_1 : real := 0.0;
28
        variable trail_reg_2 : real := 1.0;
29
 
30
                begin
31
 
32
                if clk'event and clk = '1' then
33
                           --get the signed I and Q values. Convert them to real values. 
34
                           x1_real := real(to_integer(x1));
35
                           x1_real := x1_real / ((2.0**31.0)-1.0);
36
                           y1_real := real(to_integer(y1));
37
                           y1_real := y1_real / ((2.0**31.0)-1.0);
38
 
39
 
40
                           --phase error estimate, step size set to 0.000244
41
                           y2 := y1_real - reg_1 * x1_real;
42
                           reg_1 := reg_1 + mu_1*x1_real*y2;
43
 
44
                           --convert to signed.                    
45
                           phase_error <= to_signed(integer(trunc(reg_1*((2.0**31.0)-1.0))), 32);
46
 
47
 
48
                           --gain error estimate, step size set to 0.000122
49
                           y3 := y2 * reg_2;
50
                           reg_2 := reg_2 + mu_2 * ((x1_real*x1_real) - (y3*y3));
51
 
52
 
53
 
54
 
55
                           if (lock_counter = 100) then
56
 
57
                                   --if (abs(trail_reg_2 - reg_2) < 0.0005) then --early lock   
58
                                   if (abs(trail_reg_2 - reg_2) < 0.00025) then  --locks later
59
                                           gain_lock <= '1';  --gain error is settling
60
                                   else
61
                                           gain_lock <= '0';  --gain error is not settled yet
62
                                   end if;
63
 
64
                                   --if (abs(trail_reg_1 - reg_1) < 0.001) then  --early lock
65
                                   if (abs(trail_reg_1 - reg_1) < 0.00025) then  --locks later
66
                                           phase_lock <= '1';  --gain error is settling
67
                                   else
68
                                           phase_lock <= '0';  --gain error is not settled yet
69
                                   end if;
70
 
71
                                   trail_reg_2 := reg_2;
72
                                   trail_reg_1 := reg_1;
73
 
74
                           end if;
75
 
76
 
77
                           --convert to signed.
78
                           gain_error <= to_signed(integer(trunc(reg_2*((2.0**31.0)-1.0))), 32);
79
 
80
 
81
 
82
 
83
                           corrected_x1 <= x1;  --I is passed along unchanged. No filter delay in this implementation.
84
                           corrected_y1 <= to_signed(integer(trunc((y1_real*reg_2*(cos(reg_1)))*((2.0**31.0)-1.0))), 32); --Q is corrected and then passed along.
85
 
86
                           lock_counter := (lock_counter + 1) mod 101; --update counter that picks out values to test for phase and gain lock.
87
 
88
                end if;
89
 
90
        end process;
91
 
92
end IQGainPhaseCorrection_integer;
93
 
94
 
95
 
96
 

powered by: WebSVN 2.1.0

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