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

📄 fft.c

📁 基于LPC2132的FFT处理程序。。 。。 。。
💻 C
📖 第 1 页 / 共 2 页
字号:
    for(i=1;i<=nu;i++)
    {   
        j2=j1/2;
        b=b*2+(j1-2*j2);
        j1=j2;
    }
    return(b);
 }

/***********************************************************************
* 名    称: void FFT_Cal(void)
* 功    能:FFT计算
* 入口参数:AD输入数据缓冲,FFT输出数据缓冲
* 出口参数: 无
* 说    明: 无
***********************************************************************/
/***********************************************/
/*   Funtion: FFT operation                    */
/*   unit n : the operation point Number       */
/*   uint nu: 2^X=n  => X=nu                   */
/***********************************************/
uint32 FFT_Cal(void)
{   

	float treal,timag,arg,c,s,mtr;
    int32   p,n2,nu1,l,i,j,k,kn2;
    uint32 n, nu;
    if(FFT__sbuff.finsh_flage==0) return(0);
    /***********************************************/
	// 				装入AD数据
	/***********************************************/
    for(i=0; i<FFTSIZE; i++)
    {   
        FFT__sbuff.FFT_Xreal[i] = ADC_Buf[i];
        FFT__sbuff.FFT_Ximag[i] = 0;
    } 
    FFT__sbuff.finsh_flage=1;
    /***********************************************/
	// 				开始FFT运算
	/***********************************************/
    n=FFTSIZE;					//FFT计算点数
    nu=FFTNUM;					//FFT位数
    
    n2=n;
    nu1=nu;						//当前计算层数计数器
    
    for (l=0;l<nu;l++)			//通过序号的位数判断FFT的层数
    {   
        nu1=nu1-1;
        n2=n2/2;
        k=0;
        while(k+n2<n)
        {   
            for(i=0;i<n2;i++)
            {   j=k>>nu1;
                p=Ibitr(j,nu);
                arg=6.28315*p/n;
                c=cos(arg);
                s=sin(arg);
                kn2=k+n2;
                treal=FFT__sbuff.FFT_Xreal[kn2]*c-FFT__sbuff.FFT_Ximag[kn2]*s;
                timag=FFT__sbuff.FFT_Ximag[kn2]*c+FFT__sbuff.FFT_Xreal[kn2]*s;
                FFT__sbuff.FFT_Xreal[kn2]=FFT__sbuff.FFT_Xreal[k]-treal;
                FFT__sbuff.FFT_Ximag[kn2]=FFT__sbuff.FFT_Ximag[k]-timag;
                FFT__sbuff.FFT_Xreal[k]=FFT__sbuff.FFT_Xreal[k]+treal;
                FFT__sbuff.FFT_Ximag[k]=FFT__sbuff.FFT_Ximag[k]+timag;
                k=k+1;
            }
            k=k+n2;
        }
    }
    for(k=0;k<n;k++)
    {   
        i=Ibitr(k,nu);
        if(i>k)
        {   
            treal=FFT__sbuff.FFT_Xreal[k];
            timag=FFT__sbuff.FFT_Ximag[k];
            FFT__sbuff.FFT_Xreal[k]=FFT__sbuff.FFT_Xreal[i];
            FFT__sbuff.FFT_Ximag[k]=FFT__sbuff.FFT_Ximag[i];
            FFT__sbuff.FFT_Xreal[i]=treal;
            FFT__sbuff.FFT_Ximag[i]=timag;
        }
    }
    i = FFT_FindMAX(&mtr);
	HostHMI_DisplayIn(7,mtr);
	HostHMI_DisplayIn(5,(fp32)i);
     
 }

/*
uint8 DTMF_Decode(void)
{   uint32 i;
    uint32 DTMF_Nu1, DTMF_Nu2, DTMF_Key;
    float  DTMF_Max1, DTMF_Max2;
    
    for(i=0; i<FFTSIZE; i++)
    {   
        FFT__sbuff.FFT_Xreal[i] = ADC0_Buf[i];
        FFT__sbuff.FFT_Ximag[i] = 0;
    }

    FFT_Cal();

    for(i=0; i<FFTSIZE/2; i++)
    {   
        FFT__sbuff.FFT_Xreal[i] = FFT__sbuff.FFT_Xreal[i]*FFT__sbuff.FFT_Xreal[i] + FFT__sbuff.FFT_Ximag[i]*FFT__sbuff.FFT_Ximag[i];
    }

    
    DTMF_Max1 = 0;
    for(i=1; i<22; i++)
    {   
        if(FFT__sbuff.FFT_Xreal[i] > DTMF_Max1)
        {
            DTMF_Max1 = FFT__sbuff.FFT_Xreal[i];
            DTMF_Nu1  = i;
        }
    }
    
    DTMF_Max2 = 0;
    for(i=23; i<FFTSIZE/2; i++)
    {   
        if(FFT__sbuff.FFT_Xreal[i] > DTMF_Max2)
        {
            DTMF_Max2 = FFT__sbuff.FFT_Xreal[i];
            DTMF_Nu2  = i;
        }
    }
    
    if(DTMF_Nu2 == 24)
    {
        if(DTMF_Nu1 == 14)
            DTMF_Key = '1';
        else if(DTMF_Nu1 == 15)
            DTMF_Key = '4';
        else if(DTMF_Nu1 == 17)
            DTMF_Key = '7';
        else if(DTMF_Nu1 == 19)
            DTMF_Key = '*'; 
    }
    else if(DTMF_Nu2 == 27)
    {
        if(DTMF_Nu1 == 14)
            DTMF_Key = '2';
        else if(DTMF_Nu1 == 15)
            DTMF_Key = '5';
        else if(DTMF_Nu1 == 17)
            DTMF_Key = '8';
        else if(DTMF_Nu1 == 19)
            DTMF_Key = '0';
    }
    else if(DTMF_Nu2 == 30)
    {
        if(DTMF_Nu1 == 14)
            DTMF_Key = '3';
        else if(DTMF_Nu1 == 15)
            DTMF_Key = '6';
        else if(DTMF_Nu1 == 17)
            DTMF_Key = '9';
        else if(DTMF_Nu1 == 19)
            DTMF_Key = '#';
    }
    else
    {
        DTMF_Key = 0xff;
    }

    return DTMF_Key;

}
*/









/*********************************************************************************************************
** 函数名称: Task1
** 功能描述: DTMF识别
** 输   入: 无
** 输   出: 无
** 调用模块: 
**
** 作   者: GD
** 日   期: 2005年12月27日
**-------------------------------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
/*
uint32 DTMF_Nu1, DTMF_Nu2, DTMF_Key, DTMF_St1, DTMF_St2;
float DTMF_Max1, DTMF_Max2;
void Task1	(void *pdata)
{   uint32 i;
    uint8  err;
    
	pdata = pdata;

    OSFlagPend( SYS_Status,                                      // 等待系统初始化完毕
                SYS_INIT, 
                OS_FLAG_WAIT_CLR_ANY, 
                0, 
                &err 
              );
                
	while (1)
	{
 
	    ADC0_Start();
	    
        OSTimeDly(OS_TICKS_PER_SEC/2); 

	    for(i=0; i<FFTSIZE; i++)
	    {   
	        FFT__sbuff.FFT_Xreal[i] = ADC0_Buf[i];
            FFT__sbuff.FFT_Ximag[i] = 0;
	    }

        FFT_Cal();

	    for(i=0; i<FFTSIZE/2; i++)
	    {   
	        FFT__sbuff.FFT_Xreal[i] = FFT__sbuff.FFT_Xreal[i]*FFT__sbuff.FFT_Xreal[i] + FFT__sbuff.FFT_Ximag[i]*FFT__sbuff.FFT_Ximag[i];
	    }


	    DTMF_Max1 = 0;
	    for(i=1; i<22; i++)
	    {   
            if(FFT__sbuff.FFT_Xreal[i] > DTMF_Max1)
            {
                DTMF_Max1 = FFT__sbuff.FFT_Xreal[i];
                DTMF_Nu1  = i;
            }
	    }

        DTMF_Max2 = 0;
	    for(i=23; i<FFTSIZE/2; i++)
	    {   
            if(FFT__sbuff.FFT_Xreal[i] > DTMF_Max2)
            {
                DTMF_Max2 = FFT__sbuff.FFT_Xreal[i];
                DTMF_Nu2  = i;
            }
	    }

	    if(DTMF_Nu2 == 24)
	    {
	        if(DTMF_Nu1 == 14)
	            DTMF_Key = '1';
	        else if(DTMF_Nu1 == 15)
	            DTMF_Key = '4';
	        else if(DTMF_Nu1 == 17)
	            DTMF_Key = '7';
	        else if(DTMF_Nu1 == 19)
	            DTMF_Key = '*'; 
        }
	    else if(DTMF_Nu2 == 27)
	    {
	        if(DTMF_Nu1 == 14)
	            DTMF_Key = '2';
	        else if(DTMF_Nu1 == 15)
	            DTMF_Key = '5';
	        else if(DTMF_Nu1 == 17)
	            DTMF_Key = '8';
	        else if(DTMF_Nu1 == 19)
	            DTMF_Key = '0';
	    }
	    else if(DTMF_Nu2 == 30)
	    {
	        if(DTMF_Nu1 == 14)
	            DTMF_Key = '3';
	        else if(DTMF_Nu1 == 15)
	            DTMF_Key = '6';
	        else if(DTMF_Nu1 == 17)
	            DTMF_Key = '9';
	        else if(DTMF_Nu1 == 19)
	            DTMF_Key = '#';
	    }
	    else
	    {
	        DTMF_Key = 0xff;
	    }


        DTMF_St1 = DTMF_Key;

        if(DTMF_St1 != DTMF_St2)
        {
            if(DTMF_St1 != 0xff)
            {
                OSFlagPost(DTMF_Status, DTMF_NEWKEY, OS_FLAG_SET, &err);
                DTMF_St2 = DTMF_St1;
            }
            else
            {
                DTMF_St2 = 0xff;
            }
        }
	}
}   

*/

⌨️ 快捷键说明

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