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

📄 fft_statemachine.vhd

📁 FFT程序
💻 VHD
📖 第 1 页 / 共 4 页
字号:


LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
ENTITY fft_statemachine IS

	PORT
	(
		data_in_real	: IN	integer range 0 to 1023;
		data_in_real_zhengfu: in std_logic ;
		
		data_in_imag	: IN	integer range 0 to 1023;
		data_in_imag_zhengfu: in std_logic;
		
		clk_tongbu	: IN	STD_LOGIC;
		clk_high:   in   std_logic;---------FFT后高速时钟输出,尽量减少对下一个模块的时延影响,目前是设置用10个clk_tongbu时钟
									--------实现传64个数据
		start	: IN	STD_LOGIC;
		fft_finish: buffer std_logic;--------------标识存储结束,通知下一模块开始工作

		data_out_real	: out	integer range 0 to 1023;
		data_out_real_zhengfu: out std_logic ;
		
		data_out_imag	: out	integer range 0 to 1023;
		data_out_imag_zhengfu: out std_logic

	);
	
END fft_statemachine ;

ARCHITECTURE fft OF fft_statemachine IS

procedure diexingyunsuan(signal data_a_in_real:in integer range 0 to  65535;
						 signal  data_a_in_real_zhengfu:in std_logic;	
						 signal data_a_in_imag:in integer range 0 to  65535;
						 signal  data_a_in_imag_zhengfu:in std_logic;	
						
					     signal data_b_in_real:in integer range 0 to  65535;
						 signal  data_b_in_real_zhengfu:in std_logic;	
						 signal data_b_in_imag:in integer range 0 to  65535;
						 signal  data_b_in_imag_zhengfu:in std_logic;	
									
					     constant data_e_in_real:in integer range 0 to  65535;
						 constant  data_e_in_real_zhengfu:in std_logic;	
						 constant data_e_in_imag:in integer range 0 to  65535;
						 constant  data_e_in_imag_zhengfu:in std_logic;	
						
						 signal data_a_out_real:out integer range 0 to  65535;
						 signal  data_a_out_real_zhengfu:out std_logic;	
						 signal data_a_out_imag:out integer range 0 to  65535;
						 signal  data_a_out_imag_zhengfu:out std_logic;	
						
					     signal data_b_out_real:out integer range 0 to  65535;
						 signal  data_b_out_real_zhengfu:out std_logic;	
						 signal data_b_out_imag:out integer range 0 to  65535;
						 signal  data_b_out_imag_zhengfu:out std_logic	)is 
    variable temp_BC_real : integer range 0 to 65535;---记录计算BC实部
	variable temp_BC_real_zhengfu: bit ;--记录计算BC实部正负
	variable temp_BC_imag : integer range 0 to 65535;---记录计算BC实部
	variable temp_BC_imag_zhengfu: bit ;--记录计算BC实部正负
		
	BEGIN
	-------------------计算BC实部real[(x1+y1j)*(x2+y2j)]=real[(x1*x2-y1*y2)+(x*1y2+x2*y1)j]=x1*x2-y1*y2-----------------------------------
	if  data_b_in_real_zhengfu=data_e_in_real_zhengfu  and 
		data_b_in_imag_zhengfu=data_e_in_imag_zhengfu then
			if    data_b_in_real*data_e_in_real>=data_b_in_imag*data_e_in_imag then---x1*x2 > y1*y2
				temp_BC_real:=(data_b_in_real*data_e_in_real-data_b_in_imag*data_e_in_imag)/1024;
				temp_BC_real_zhengfu:='1';
			else
				temp_BC_real:=(data_b_in_imag*data_e_in_imag-data_b_in_real*data_e_in_real)/1024;
				temp_BC_real_zhengfu:='0';
			end if ;
	elsif data_b_in_real_zhengfu=data_e_in_real_zhengfu  and 
		  data_b_in_imag_zhengfu/=data_e_in_imag_zhengfu then
				temp_BC_real:=(data_b_in_imag*data_e_in_imag+data_b_in_real*data_e_in_real)/1024;
				temp_BC_real_zhengfu:='1';	
	elsif data_b_in_real_zhengfu/=data_e_in_real_zhengfu  and 
		  data_b_in_imag_zhengfu=data_e_in_imag_zhengfu then
				temp_BC_real:=(data_b_in_imag*data_e_in_imag+data_b_in_real*data_e_in_real)/1024;
				temp_BC_real_zhengfu:='0';		
	elsif  data_b_in_real_zhengfu/=data_e_in_real_zhengfu  and 
		   data_b_in_imag_zhengfu/=data_e_in_imag_zhengfu then
				if    data_b_in_real*data_e_in_real>=data_b_in_imag*data_e_in_imag then---x1*x2 > y1*y2
					temp_BC_real:=(data_b_in_real*data_e_in_real-data_b_in_imag*data_e_in_imag)/1024;
					temp_BC_real_zhengfu:='0';
				else
					temp_BC_real:=(data_b_in_imag*data_e_in_imag-data_b_in_real*data_e_in_real)/1024;
					temp_BC_real_zhengfu:='1';
				end if ;
	end if ;
	
	-------------------计算BC虚部imag[(x1+y1j)*(x2+y2j)]=imag[(x1*x2-y1*y2)+(x1*y2+x2*y1)j]=x1*y2+x2*y1-----------------------------------
	if  data_b_in_real_zhengfu=data_e_in_imag_zhengfu  and 
		data_b_in_imag_zhengfu=data_e_in_real_zhengfu then
				temp_BC_imag:=(data_b_in_real*data_e_in_imag + data_b_in_imag*data_e_in_real)/1024;
				temp_BC_imag_zhengfu:='1';	
	elsif data_b_in_real_zhengfu=data_e_in_imag_zhengfu  and 
		  data_b_in_imag_zhengfu/=data_e_in_real_zhengfu then
				if    data_b_in_real*data_e_in_imag>=data_b_in_imag*data_e_in_real then---x1*x2 > y1*y2
					temp_BC_imag:=(data_b_in_real*data_e_in_imag-data_b_in_imag*data_e_in_real)/1024;
					temp_BC_imag_zhengfu:='1';
				else
					temp_BC_imag:=(data_b_in_imag*data_e_in_real-data_b_in_real*data_e_in_imag)/1024;
					temp_BC_imag_zhengfu:='0';
				end if ;
				
	elsif data_b_in_real_zhengfu/=data_e_in_imag_zhengfu  and 
		  data_b_in_imag_zhengfu=data_e_in_real_zhengfu then
				if    data_b_in_real*data_e_in_imag>=data_b_in_imag*data_e_in_real then---x1*x2 > y1*y2
					temp_BC_imag:=(data_b_in_real*data_e_in_imag-data_b_in_imag*data_e_in_real)/1024;
					temp_BC_imag_zhengfu:='0';
				else
					temp_BC_imag:=(data_b_in_imag*data_e_in_real-data_b_in_real*data_e_in_imag)/1024;
					temp_BC_imag_zhengfu:='1';
				end if ;
					
	elsif  data_b_in_real_zhengfu/=data_e_in_imag_zhengfu  and 
		   data_b_in_imag_zhengfu/=data_e_in_real_zhengfu then
				temp_BC_imag:=(data_b_in_real*data_e_in_imag + data_b_in_imag*data_e_in_real)/1024;
				temp_BC_imag_zhengfu:='0';	

	end if ;	
	
	
	-------------------计算A-BC、A+BC实部
	if  data_a_in_real_zhengfu='1' and temp_BC_real_zhengfu='1' then
		data_a_out_real<=data_a_in_real+temp_BC_real;
		data_a_out_real_zhengfu<='1';
		if data_a_in_real>=temp_BC_real then
			data_b_out_real<=data_a_in_real-temp_BC_real;
			data_b_out_real_zhengfu<='1';
		else 
			data_b_out_real<=temp_BC_real-data_a_in_real;
			data_b_out_real_zhengfu<='0';
		end if; 
	elsif data_a_in_real_zhengfu='0' and temp_BC_real_zhengfu='0' then
		data_a_out_real<=data_a_in_real+temp_BC_real;
		data_a_out_real_zhengfu<='0';
		if data_a_in_real>=temp_BC_real then
			data_b_out_real<=data_a_in_real-temp_BC_real;
			data_b_out_real_zhengfu<='0';
		else 
			data_b_out_real<=temp_BC_real-data_a_in_real;
			data_b_out_real_zhengfu<='1';
		end if; 	
	elsif data_a_in_real_zhengfu='0' and temp_BC_real_zhengfu='1' then
		data_b_out_real<=data_a_in_real+temp_BC_real;
		data_b_out_real_zhengfu<='0';
		if data_a_in_real>=temp_BC_real then
			data_a_out_real<=data_a_in_real-temp_BC_real;
			data_a_out_real_zhengfu<='0';
		else 
			data_a_out_real<=temp_BC_real-data_a_in_real;
			data_a_out_real_zhengfu<='1';
		end if;	
	elsif data_a_in_real_zhengfu='1' and temp_BC_real_zhengfu='0' then
		data_b_out_real<=data_a_in_real+temp_BC_real;
		data_b_out_real_zhengfu<='1';
		if data_a_in_real>=temp_BC_real then
			data_a_out_real<=data_a_in_real-temp_BC_real;
			data_a_out_real_zhengfu<='1';
		else 
			data_a_out_real<=temp_BC_real-data_a_in_real;
			data_a_out_real_zhengfu<='0';
		end if;
	end if ;				

-------------------计算A-BC、A+BC xu部
	if  data_a_in_imag_zhengfu='1' and temp_BC_imag_zhengfu='1' then
		data_a_out_imag<=data_a_in_imag+temp_BC_imag;
		data_a_out_imag_zhengfu<='1';
		if data_a_in_imag>=temp_BC_imag then
			data_b_out_imag<=data_a_in_imag-temp_BC_imag;
			data_b_out_imag_zhengfu<='1';
		else 
			data_b_out_imag<=temp_BC_imag-data_a_in_imag;
			data_b_out_imag_zhengfu<='0';
		end if; 
	elsif data_a_in_imag_zhengfu='0' and temp_BC_imag_zhengfu='0' then
		data_a_out_imag<=data_a_in_imag+temp_BC_imag;
		data_a_out_imag_zhengfu<='0';
		if data_a_in_imag>=temp_BC_imag then
			data_b_out_imag<=data_a_in_imag-temp_BC_imag;
			data_b_out_imag_zhengfu<='0';
		else 
			data_b_out_imag<=temp_BC_imag-data_a_in_imag;
			data_b_out_imag_zhengfu<='1';
		end if; 	
	elsif data_a_in_imag_zhengfu='0' and temp_BC_imag_zhengfu='1' then
		data_b_out_imag<=data_a_in_imag+temp_BC_imag;
		data_b_out_imag_zhengfu<='0';
		if data_a_in_imag>=temp_BC_imag then
			data_a_out_imag<=data_a_in_imag-temp_BC_imag;
			data_a_out_imag_zhengfu<='0';
		else 
			data_a_out_imag<=temp_BC_imag-data_a_in_imag;
			data_a_out_imag_zhengfu<='1';
		end if;	
	elsif data_a_in_imag_zhengfu='1' and temp_BC_imag_zhengfu='0' then
		data_b_out_imag<=data_a_in_imag+temp_BC_imag;
		data_b_out_imag_zhengfu<='1';
		if data_a_in_imag>=temp_BC_imag then
			data_a_out_imag<=data_a_in_imag-temp_BC_imag;
			data_a_out_imag_zhengfu<='1';
		else 
			data_a_out_imag<=temp_BC_imag-data_a_in_imag;
			data_a_out_imag_zhengfu<='0';
		end if;
	end if ;			

end diexingyunsuan;


⌨️ 快捷键说明

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