diff --git a/libraries/base/common/src/vhdl/common_math_pkg.vhd b/libraries/base/common/src/vhdl/common_math_pkg.vhd index 24270d4fd4ad82f1e6883693ab816e557dee5d66..0cbb134183563d9fc256e750614fca2a017625a0 100644 --- a/libraries/base/common/src/vhdl/common_math_pkg.vhd +++ b/libraries/base/common/src/vhdl/common_math_pkg.vhd @@ -45,9 +45,7 @@ PACKAGE common_math_pkg IS -- . +round(ampl) is the maximum integer value and -round(ampl) the minimum integer value -- . freq is the number of periods in N samples -- . phi is phase offset in radials - -- Phasor: exp(j*angle) = cos(angle) + j*sin(angle) - -- A complex FFT of N points has N bins or channels: ch = -N/2:0:N/2-1. - -- To create an FFT input phasor with frequency in the middle of a channel use FREQ = ch. + -- . use common_math_create_look_up_table_phasor() to create a complex phasor look up table FUNCTION common_math_create_look_up_table_cos(N : POSITIVE; AMPL, FREQ, PHI : REAL) RETURN t_nat_integer_arr; FUNCTION common_math_create_look_up_table_sin(N : POSITIVE; AMPL, FREQ, PHI : REAL) RETURN t_nat_integer_arr; @@ -67,6 +65,20 @@ PACKAGE common_math_pkg IS -- Function to concat Im & Re values in the lookup table, output = (hi << W) + lo FUNCTION common_math_concat_look_up_table(table_hi, table_lo : t_nat_integer_arr; W : POSITIVE) RETURN t_nat_integer_arr; + + -- Function to concat Im & Re values of phasor in the lookup table, output = (imag << W) + real + -- . N is number of samples in the lookup table, [0:N-1] = [0:N> = [0:2pi*FREQ> + -- . +round(ampl) is the maximum integer value and -round(ampl) the minimum integer value + -- full scale = 2**(W-1) + -- max = full_scale - 1 = 2**(W-1)-1 + -- use AMPL <= max to avoid wrapping + -- . freq is the number of periods in N samples + -- . phi is phase offset in radials + -- Phasor: exp(j*angle) = cos(angle) + j*sin(angle) + -- A complex FFT of N points has N bins or channels: ch = -N/2:0:N/2-1. + -- To create an FFT input phasor with frequency in the middle of a channel use FREQ = ch. + FUNCTION common_math_create_look_up_table_phasor(N, W : POSITIVE; AMPL, FREQ, PHI : REAL) RETURN t_nat_integer_arr; + FUNCTION common_math_create_look_up_table_phasor(N, W : POSITIVE; AMPL, FREQ, PHI : REAL) RETURN t_slv_32_arr; -- range 0 TO N-1 END common_math_pkg; @@ -148,6 +160,24 @@ PACKAGE BODY common_math_pkg IS END LOOP; RETURN v_table; END; + + FUNCTION common_math_create_look_up_table_phasor(N, W : POSITIVE; AMPL, FREQ, PHI : REAL) RETURN t_nat_integer_arr IS + CONSTANT c_cos_arr : t_nat_integer_arr := common_math_create_look_up_table_cos(N, AMPL, FREQ, PHI); + CONSTANT c_sin_arr : t_nat_integer_arr := common_math_create_look_up_table_sin(N, AMPL, FREQ, PHI); + CONSTANT c_exp_arr : t_nat_integer_arr := common_math_concat_look_up_table(c_sin_arr, c_cos_arr, W); + BEGIN + RETURN c_exp_arr; -- Concatenated W bit sin imag part & W bit cos real part + END; + FUNCTION common_math_create_look_up_table_phasor(N, W : POSITIVE; AMPL, FREQ, PHI : REAL) RETURN t_slv_32_arr IS + CONSTANT c_exp_arr : t_nat_integer_arr := common_math_create_look_up_table_phasor(N, W, AMPL, FREQ, PHI); + VARIABLE v_exp_arr : t_slv_32_arr(0 TO N-1); + BEGIN + FOR I IN 0 TO N-1 LOOP + v_exp_arr(I) := TO_SVEC(c_exp_arr(I), 32); + END LOOP; + RETURN v_exp_arr; + END; + END common_math_pkg;