⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fftdatatypelib.vhd

📁 基于存储器的基4按频率抽取的fft 的vhdl描述 可以对连续数据流进行256点的fft
💻 VHD
字号:
library ieee;	use ieee.std_logic_1164.all;	use IEEE.std_logic_arith.all;	--   use IEEE.math_real.all;	use IEEE.math_complex.all;	package fftDataType is    --subtype slvDt is std_logic_vector(Aw -1 downto 0);	Constant CoefWidth : natural := 14;	Constant DataWidth : natural := 16;		subtype slvDt is std_logic_vector(2*DataWidth-1 downto 0);	subtype slvDtSub is signed(DataWidth-1 downto 0);	--constant slvDtRstV : slvDt := math_czero;	--constant slvDtRotJ : slvDt := math_cbase_j;	---	subtype slvCoeft is std_logic_vector(2*CoefWidth-1 downto 0);	subtype slvCoeftSub is signed(CoefWidth -1 downto 0);	--constant slvCoeftWn : slvCoeft := exp( -math_cbase_j* math_2_pi / real(2** Addrw));	--	---data type arithmetic	-- + ---	function DtAdd(a, b : in slvDt) return slvDt;--	function DtSub(a, b : in slvDt) return slvDt;	----	function DtScaleAdd(a, b : in slvDt) return slvDt;--	function DtScaleSub(a, b : in slvDt) return slvDt;	-- * 	--function DtMulCoef(a : in slvDt; b : in slvCoeft) return slvDt;	-- * j--	function DtRotJ(a : in slvDt) return slvDt;	--			--	function DtGetRe(d : in slvDt) return slvDtSub;	function DtGetIm(d : in slvDt) return slvDtSub;	--	function CoeftGetRe(d : in slvCoeft) return slvCoeftSub;	function CoeftGetIm(d : in slvCoeft) return slvCoeftSub;	----	function DtMulCoef(d : in slvDtSub; c : slvCoeftSub) return slvDtSub;	--	function CreateDt(r, i: slvDtSub) return slvDt;	function CreateDt(r, i: real) return slvDt;	function DttoComplex(dt : slvDt) return complex;	function CreateCoeft(r, i : slvCoeftSub) return slvCoeft;	function CreateCoeft(r, i: real) return slvCoeft;--	--	function DtSubAdd(a,b : in slvDtSub) return slvDtSub;	function DtSubNeg(a : in slvDtSub) return slvDtSub;		function signedToReal(d : signed; Width : integer) return real ;end package fftDataType;package body fftDataType is    --function CstrCoef--     -- +--		function DtSubAdd(a,b : in slvDtSub) return slvDtSub is--			begin--				return conv_signed(signed(a) + signed(b), DataWidth);--			end function DtSubAdd;		--		function DtSubSub(a,b : in slvDtSub) return slvDtSub is--			begin--				return conv_std_logic_vector(signed(a) - signed(b), DataWidth);--			end function DtSubSub;						function DtSubNeg(a : in slvDtSub) return slvDtSub is			begin				return conv_signed(-signed(a), DataWidth);			end function DtSubNeg;			--		function DtAdd(a, b : in slvDt) return slvDt is--		 begin--			 return conv_std_logic_vector(signed(DtGetRe(a)) + signed(DtGetRe(b)), DataWidth--						)--						&--						conv_std_logic_vector(signed(DtGetIm(a)) + signed(DtGetIm(b)), DataWidth)--						;--		 end function DtAdd;--		-- ---		function DtSub(a, b : in slvDt) return slvDt is--			begin--				return conv_std_logic_vector(signed(DtGetRe(a)) - signed(DtGetRe(b)), DataWidth)--						&--						conv_std_logic_vector(signed(DtGetIm(a)) - signed(DtGetIm(b)), DataWidth)--						;--		 end function DtSub;		 --		function DtScaleAdd(a, b : in slvDt) return slvDt is--				variable sum : slvDt;--				variable r : signed(DataWidth downto 0);--				variable i : signed(DataWidth downto 0);--				constant u1 : unsigned := "1";--			begin--				r := conv_signed(DtGetRe(a),DataWidth +1) + conv_signed(DtGetRe(b),DataWidth +1);--				i := conv_signed(DtGetIm(a),DataWidth +1) + conv_signed(DtGetIm(b),DataWidth +1);--				sum := (conv_std_logic_vector(r(DataWidth downto 1),DataWidth))--						&--						(conv_std_logic_vector(i(DataWidth downto 1),DataWidth));--			 return sum;--		 end function DtScaleAdd;--		-- ---		function DtScaleSub(a, b : in slvDt) return slvDt is--				variable sum : slvDt;--				variable r : signed(DataWidth downto 0);--				variable i : signed(DataWidth downto 0);--				constant u1 : unsigned := "1";--			begin--				r := conv_signed(DtGetRe(a),DataWidth +1) - conv_signed(DtGetRe(b),DataWidth +1);--				i := conv_signed(DtGetIm(a),DataWidth +1) - conv_signed(DtGetIm(b),DataWidth +1);--				sum := (conv_std_logic_vector(r(DataWidth downto 1),DataWidth))--						&--						(conv_std_logic_vector(i(DataWidth downto 1),DataWidth));--			 return sum;--		 end function DtScaleSub;		 		-- *j--		function DtRotJ(a : in slvDt) return slvDt is--		 begin--			  return conv_std_logic_vector(-DtGetIm(a), DataWidth)& std_logic_vector(DtGetRe(a));--		 end function DtRotJ; 		-- *		function signedToReal(d : signed; Width : integer) return real is			begin				if not Is_X(d(d'left)) then					return real(conv_integer(								d						))/real(2 ** (Width -1 ));				else					return 0.0;				end if;			end function signedToReal;			--		function DtMulCoef(d : in slvDtSub; c : slvCoeftSub) return slvDtSub is--				variable r : signed(d'length + c'length -1 downto 0);--				variable cr : signed(DataWidth -1 downto 0);--				variable dd,dc,dr,mul, eps : real;--			begin--				--				r := signed(d)*signed(c);--				r := r(r'left -1 downto 0) & '0';--				--				dd := signedToreal(d,d'length);--				dc := signedToreal(c,c'length);--				mul := dd * dc;--				--				dr := signedToreal(r,r'length);--				--				--				eps := abs(--						dr - dd*dc--					);--				--				--				cr := conv_signed(integer(dr * real(2 ** (DataWidth -1 ))),cr'length);--				--				if eps /= 0.0 then--					assert eps <1.5e-5--						report "DtMul error too large!"--						severity warning;--				end if;--				return slvDtSub(r(r'left downto r'left - DataWidth +1));--			end function DtMulCoef;		--get real		function DtGetRe(d : in slvDt) return slvDtSub is			variable r : slvDtSub;		 begin			r := slvDtSub(d(2*DataWidth-1 downto Datawidth));			  return r;		 end function DtGetRe;				--get real		function DtGetIm(d : in slvDt) return slvDtSub is		 begin				return slvDtSub(d(DataWidth-1 downto 0));		 end function DtGetIm;		 		--get real		function CoeftGetRe(d : in slvCoeft) return slvCoeftSub is			variable r : slvCoeftSub; 		 begin				r := slvCoeftSub(d(2*CoefWidth-1 downto Coefwidth));				return r;		 end function CoeftGetRe;				--get Imagine		function CoeftGetIm(d : in slvCoeft) return slvCoeftSub is		 begin				 return slvCoeftSub(d(CoefWidth-1 downto 0));		 end function CoeftGetIm;		 		function CreateDt(r, i: slvDtSub) return slvDt is			begin				return std_logic_vector(r) & std_logic_vector(i);			end function CreateDt;					function CreateDt(r, i: real) return slvDt is				variable ir, ii : integer;			begin					ir := integer(r * real(2 ** (DataWidth -1 ))) ;					ii := integer(i * real(2 ** (DataWidth -1 )));				return CreateDt(conv_signed(ir,DataWidth),conv_signed(ii,DataWidth) );			end function CreateDt;					function DttoComplex(dt : slvDt) return complex is				--variable cc : slvDt;				variable rr, ri : real;				variable c : complex;			begin					rr := real(conv_integer(						dtGetRe(dt)						))/real(2 ** (DataWidth -1 ));					ri := real(conv_integer(						dtGetIm(dt)						))/real(2 ** (DataWidth -1 ));					c := (rr,ri);					return c;			end function DttoComplex;					function CreateCoeft(r, i : slvCoeftSub) return slvCoeft is			begin				return std_logic_vector(r) & std_logic_vector(i);			end function CreateCoeft;					function CreateCoeft(r, i: real) return slvCoeft is				variable ir, ii : integer;			begin					ir := integer(r * real(2 ** (CoefWidth -1 ))) ;					ii := integer(i * real(2 ** (CoefWidth -1 )));				return CreateCoeft(conv_signed(ir,CoefWidth),conv_signed(ii,CoefWidth) );			end function CreateCoeft;end package body fftDataType;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -