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

📄 tsfft_adi.c

📁 TS201 FFT程序
💻 C
字号:
//*********************************************************************
//  File Name: tsfft_adi.c  
// Example to demonstrate how to generate two complex FFTs using
//   a single twiddle table 
//  Author  : YangLi
//  E-mail  : yl@water.ac.cn                                            
//  Version : 1.0                                                               
//  BeiJing ZHONGKEHAIXUN Science & Technology Co. Ltd.           
//  Copyright 2005
//*********************************************************************


#include <defts201.h>
#include <sysreg.h>
#include <signal.h>
#include <stdio.h>
#include <filter.h> 
#include <math.h>
asm("#include <cache_macros.h>");asm("#include <defts201.h>");#include "utils.h"
#include "testdef.h"

#define NDATA 1024 
#define FS 20000
#define FC 200
#define PI 3.14159

#define CLOCK_RATE 600

section("data2") complex_float data[NDATA];   /* data for a 256-point FFT */ 
section("data2") complex_float output[NDATA]; 


section("data2") static complex_float twidtab[(3*NDATA)/4]; 


/* note that the temporary buffer should be as large as 
   the largest FFT generated */ 
complex_float temp[NDATA]; 
section("data2") float real[NDATA];

section("handshake") int HandShakeBuffer[HANDSHAKE_BUFFER_LENGTH];

unsigned int ledcount,cnt;
void main(void)
{
	int i, count=8;
	unsigned int MaxIndex=0,id;
	float MaxData;
	unsigned int Start_time,End_time;
	float time;
	
    asm("cache_enable(450);");		
	init_Tiger();			
	
	__builtin_sysreg_write(__FLAGREGST, FLAGREG_FLAG2_EN);
				
	for(i = 0; i < NDATA; i++) {
		data[i].re=sin(2*PI*i*FC/FS);
		data[i].im=sin(2*PI*i*FC/FS);;
	}
	
	/* Generate a twiddle table for a 1024-point FFT */ 
	twidfft (twidtab,NDATA); 
	init_timer(0,0,0xffffffff);
	Start_time = start_timer(0);
	
	/* Generate a 1024-point complex FFT */ 
	cfft (data, temp, output, twidtab, 1, NDATA); 
	End_time = stop_timer(0);	
	time = (Start_time - End_time) / (float)CLOCK_RATE;
			
	for(i = 0; i < NDATA; i++)
	{
		real[i] = output[i].re * output[i].re + output[i].im * output[i].im;
	}
	
	MaxData= 0;
	MaxIndex=0;
	for(i = 0; i < NDATA / 2; i++)
	{
		if(real[i] > MaxData)
		{
			MaxIndex = i;
			MaxData = real[i];
		}
	}
	
	if(MaxIndex == 0x0a)
		HandShakeBuffer[HS_RESULT] = 0;
	else
		HandShakeBuffer[HS_RESULT] = -1;
			
	HandShakeBuffer[HS_RESULTDATA1] = *((int*)&time);
	HandShakeBuffer[HS_FINISHED] = 1;
			
	while(1)
	{
		ledcount++;


		for (cnt = 0 ; cnt < 5000000 ; cnt++);   // delay

		if(ledcount % 2)
	        __builtin_sysreg_write(__FLAGREGST, FLAGREG_FLAG2_OUT); // set the flag bits
		else
	        __builtin_sysreg_write(__FLAGREGCL, ~FLAGREG_FLAG2_OUT); //clear the flag bits
	}	
	
}

⌨️ 快捷键说明

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