|
发表于 2004-6-19 17:43:56
|
显示全部楼层
谁会?
[这个贴子最后由serene在 2004/06/19 05:47pm 第 1 次编辑]
component butterfly, 其原理与stg1_butterfly一样,只是采用复数乘法。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity butterfly is
generic(
data_width : integer := 16; -- No of Data bits
tw_fact_width : integer := 16); -- No of Twiddle Factor bits
port (
reset : in std_logic; -- Reset
clk : in std_logic; -- Input Clock
data_rd : in std_logic; -- New Sample Read (This is the sampling clk Active High)
data1_r_in : in std_logic_vector(data_width-1 downto 0); -- Input Data1 Real
data1_i_in : in std_logic_vector(data_width-1 downto 0); -- Input Data1 Imag
data2_r_in : in std_logic_vector(data_width-1 downto 0); -- Input Data2 Real
data2_i_in : in std_logic_vector(data_width-1 downto 0); -- Input Data2 Real
tf1_r : in std_logic_vector(tw_fact_width-1 downto 0); -- Twiddle Factor1 Real Data
tf1_i : in std_logic_vector(tw_fact_width-1 downto 0); -- Twiddle Factor1 Imag Data
data1_r_out : out std_logic_vector(data_width-1 downto 0); -- Output Data1 Real
data1_i_out : out std_logic_vector(data_width-1 downto 0); -- Output Data1 Imag
data2_r_out : out std_logic_vector(data_width-1 downto 0); -- Output Data2 Real
data2_i_out : out std_logic_vector(data_width-1 downto 0) -- Output Data2 Imag
);
end butterfly;
architecture rtl of butterfly is
component complex_mult is
generic(
data1_width : integer := 16; -- Size of Data1 (bits)
data2_width : integer := 16); -- Size of Data2 (bits)
port (
data_rd : in std_logic; -- New Sample Read (This is the sampling clk Active High)
data1_real : in std_logic_vector(data1_width-1 downto 0); -- Data1 Real Value
data1_imag : in std_logic_vector(data1_width-1 downto 0); -- Data1 Imag Value
data2_real : in std_logic_vector(data2_width-1 downto 0); -- Data2 Real Value
data2_imag : in std_logic_vector(data2_width-1 downto 0); -- Data2 Imag Value
data_out_real : out std_logic_vector(data1_width-1 downto 0); -- Output Data Real Value
data_out_imag : out std_logic_vector(data1_width-1 downto 0) -- Output Data Imag Value
);
end component;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
signal last_data_rd : std_logic; -- Used to sample new data
signal data1_r_in_div4 : std_logic_vector(data_width-1 downto 0); -- Real part of data1 divided by four
signal data1_i_in_div4 : std_logic_vector(data_width-1 downto 0); -- Imag part of data1 divided by four
signal data2_r_in_div2 : std_logic_vector(data_width-1 downto 0); -- Real part of data2 divided by two
signal data2_i_in_div2 : std_logic_vector(data_width-1 downto 0); -- Imag part of data2 divided by two
signal tf1_r_div2 : std_logic_vector(tw_fact_width-1 downto 0); -- Real part of twiddle factor divided by two
signal tf1_i_div2 : std_logic_vector(tw_fact_width-1 downto 0); -- Imag part of twiddle factor divided by two
signal Mult_TF_Xn2_R_Out : std_logic_vector((data_width-1) downto 0); -- Real value output from complex multiplication
signal Mult_TF_Xn2_I_Out : std_logic_vector((data_width-1) downto 0); -- Imag value output from complex multiplication
signal Butt_Data1_Out_R_signed : signed (data_width-1 downto 0); -- Data1 real result from butterfly
signal Butt_Data1_Out_I_signed : signed (data_width-1 downto 0); -- Data1 imag result from butterfly
signal Butt_Data2_Out_R_signed : signed (data_width-1 downto 0); -- Data2 real result from butterfly
signal Butt_Data2_Out_I_signed : signed (data_width-1 downto 0); -- Data2 imag result from butterfly
begin
butterfly_calcs: process(data1_r_in_div4, data1_i_in_div4, Mult_TF_Xn2_R_Out, Mult_TF_Xn2_I_Out)
-- Update butterfly outputs
begin
Butt_Data1_Out_R_signed <= signed(data1_r_in_div4) + signed(Mult_TF_Xn2_R_Out);
Butt_Data1_Out_I_signed <= signed(data1_i_in_div4) + signed(Mult_TF_Xn2_I_Out);
Butt_Data2_Out_R_signed <= signed(data1_r_in_div4) - signed(Mult_TF_Xn2_R_Out);
Butt_Data2_Out_I_signed <= signed(data1_i_in_div4) - signed(Mult_TF_Xn2_I_Out);
end process butterfly_calcs;
data_scaling: process(reset, clk)
begin
if reset = '0' then
tf1_r_div2 <= (others => '0');
tf1_i_div2 <= (others => '0');
data1_r_in_div4 <= (others => '0');
data1_i_in_div4 <= (others => '0');
data2_r_in_div2 <= (others => '0');
data2_i_in_div2 <= (others => '0');
elsif Rising_Edge(clk) then
if tf1_r(tw_fact_width-1) = '0' then
tf1_r_div2 <= '0' & tf1_r(tw_fact_width-1 downto 1);
else
tf1_r_div2 <= '1' & tf1_r(tw_fact_width-1 downto 1);
end if;
if tf1_i(tw_fact_width-1) = '0' then
tf1_i_div2 <= '0' & tf1_i(tw_fact_width-1 downto 1);
else
tf1_i_div2 <= '1' & tf1_i(tw_fact_width-1 downto 1);
end if;
if data2_r_in(data_width-1) = '0' then
data2_r_in_div2 <= '0' & data2_r_in(data_width-1 downto 1);
else
data2_r_in_div2 <= '1' & data2_r_in(data_width-1 downto 1);
end if;
if data2_i_in(data_width-1) = '0' then
data2_i_in_div2 <= '0' & data2_i_in(data_width-1 downto 1);
else
data2_i_in_div2 <= '1' & data2_i_in(data_width-1 downto 1);
end if;
if data1_r_in(data_width-1) = '0' then
data1_r_in_div4 <= "00" & data1_r_in(data_width-1 downto 2);
else
data1_r_in_div4 <= "11" & data1_r_in(data_width-1 downto 2);
end if;
if data1_i_in(data_width-1) = '0' then
data1_i_in_div4 <= "00" & data1_i_in(data_width-1 downto 2);
else
data1_i_in_div4 <= "11" & data1_i_in(data_width-1 downto 2);
end if;
end if;
end process data_scaling;
-- Output the results which are divided by 2 for scaling
data1_r_out <= std_logic_vector(Butt_Data1_Out_R_signed(data_width-2 downto 0)) & '0';
data1_i_out <= std_logic_vector(Butt_Data1_Out_I_signed(data_width-2 downto 0)) & '0';
data2_r_out <= std_logic_vector(Butt_Data2_Out_R_signed(data_width-2 downto 0)) & '0';
data2_i_out <= std_logic_vector(Butt_Data2_Out_I_signed(data_width-2 downto 0)) & '0';
TF1_X1_Mult: complex_mult
generic map (data1_width => tw_fact_width,
data2_width => data_width
)
port map(
data_rd => data_rd,
data1_real => tf1_r_div2,
data1_imag => tf1_i_div2,
data2_real => data2_r_in_div2,
data2_imag => data2_i_in_div2,
data_out_real => Mult_TF_Xn2_R_Out,
data_out_imag => Mult_TF_Xn2_I_Out
);
end rtl;
|
|