Skip to content
Snippets Groups Projects
Commit 51928ae8 authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Added function common_math_create_look_up_table_phasor().

parent bb725a4d
No related branches found
No related tags found
No related merge requests found
...@@ -45,9 +45,7 @@ PACKAGE common_math_pkg IS ...@@ -45,9 +45,7 @@ PACKAGE common_math_pkg IS
-- . +round(ampl) is the maximum integer value and -round(ampl) the minimum integer value -- . +round(ampl) is the maximum integer value and -round(ampl) the minimum integer value
-- . freq is the number of periods in N samples -- . freq is the number of periods in N samples
-- . phi is phase offset in radials -- . phi is phase offset in radials
-- Phasor: exp(j*angle) = cos(angle) + j*sin(angle) -- . use common_math_create_look_up_table_phasor() to create a complex phasor look up table
-- 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_cos(N : POSITIVE; AMPL, FREQ, PHI : REAL) RETURN t_nat_integer_arr; 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; FUNCTION common_math_create_look_up_table_sin(N : POSITIVE; AMPL, FREQ, PHI : REAL) RETURN t_nat_integer_arr;
...@@ -68,6 +66,20 @@ PACKAGE common_math_pkg IS ...@@ -68,6 +66,20 @@ PACKAGE common_math_pkg IS
-- Function to concat Im & Re values in the lookup table, output = (hi << W) + lo -- 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 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; END common_math_pkg;
...@@ -149,5 +161,23 @@ PACKAGE BODY common_math_pkg IS ...@@ -149,5 +161,23 @@ PACKAGE BODY common_math_pkg IS
RETURN v_table; RETURN v_table;
END; 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; END common_math_pkg;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment