Studentenversion des ESY6/A Praktikums "signal_processing".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cordic_pkg.vhd 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use ieee.math_real.all;
  5. package cordic_pkg is
  6. type cordic_mode is (cordic_rotate, cordic_vector);
  7. function cordic_gain(Iterations : positive) return real;
  8. procedure adjust_angle(x, y, z : in signed; signal xa, ya, za : out signed);
  9. end package cordic_pkg;
  10. package body cordic_pkg is
  11. function cordic_gain(iterations : positive) return real is
  12. variable g : real := 1.0;
  13. begin
  14. for i in 0 to iterations-1 loop
  15. g := g * sqrt(1.0 + 2.0**(-2*i));
  16. end loop;
  17. return g;
  18. end function;
  19. procedure adjust_angle(x, y, z : in signed; signal xa, ya, za : out signed) is
  20. variable quad : unsigned(1 downto 0);
  21. variable zp : signed(z'length-1 downto 0) := z;
  22. variable yp : signed(y'length-1 downto 0) := y;
  23. variable xp : signed(x'length-1 downto 0) := x;
  24. begin
  25. -- 0-based quadrant number of angle
  26. quad := unsigned(zp(zp'high downto zp'high-1));
  27. if quad = 1 or quad = 2 then -- Rotate into quadrant 0 and 3 (right half of plane)
  28. xp := -xp;
  29. yp := -yp;
  30. -- Add 180 degrees (flip the sign bit)
  31. zp := (not zp(zp'left)) & zp(zp'left-1 downto 0);
  32. end if;
  33. xa <= xp;
  34. ya <= yp;
  35. za <= zp;
  36. end procedure;
  37. end package body cordic_pkg;