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

📄 fir_decima.c

📁 该程序是在ADIdsp上,实现fir运算。开发环境用的是VDSP++3.5
💻 C
字号:
/*******************************************************************************
Copyright(c) 2000 - 2002 Analog Devices. All Rights Reserved.
Developed by Joint Development Software Application Team, IPDC, Bangalore, India
for Blackfin DSPs  ( Micro Signal Architecture 1.0 specification).

By using this module you agree to the terms of the Analog Devices License
Agreement for DSP Software. 
********************************************************************************

*************************************************************************/

#define BUFFER_SIZE     256     // No: of inputs
#define PRINT_ON_ERROR
#define TEST_ERROR  0x4000

#include "mds_def.h"
#include"tfir.h"


/**************************************************************************

  Func name   :  tfir_deci

***************************************************************************

  Purpose     :  Test fir_decima() function.
  Description :  Performs the following test for fir_decima() function
                 Low pass Test, filter lenght L % 4 = 0 

************************************************************************/
extern void _fir_decima(const fract16 *in, fract16 *out, int n, fract16 *h, int L, int M, int LBYM, fract16 *d);
segment ("mydata1") short in[257];
segment ("mydata2") short d[16];
segment ("mydata3") short h[16];
segment ("mydata3") short out[512];

            /*{ Test status flag }*/
int tfir_deci(void (*_fir_decima)(const fract16 *in, fract16 *out, int n, fract16 *h, int L, int M, int LBYM, fract16 *d))
           
{
    fract16 outputmag, thresh;
    fract32 accout;

    int i,j,nsamples,bitaccuracy=3,error;
    int error_flag;
       
    /*{ Test function initialization }*/
    error_flag = 0;  /* Clear status flag */
    /*
     *  Test: Low pass Test, filter length燣 % 4 = 0
     *  Type: Correctness   
     *  Description: Input data is read from the header file and 
     *  consists of sinusoidal signal whose normalised frequency
     *  = 0.1,the signal amplitude = 1/4, Stored number of 
     * samples = 260, Filter cutoff = 0.3 (normalised)
     * Number of samples  = 260; 
        
     */
    /*{ Initialization for Test} */
    
    printf("\n Testing property ...\n");

    
    
    h[0] = 0xFFD4;
    h[1] = 0xFF4D;
    h[2] = 0xFE69;
    h[3] = 0xFE9E;
    h[4] = 0x029D;
    h[5] = 0x0B91;
    h[6] = 0x16D6;
    h[7] = 0x1ECC;
    h[8] = 0x1ECC;
    h[9] = 0x16D6;
    h[10] = 0x0B91;
    h[11] = 0x029D;
    h[12] = 0xFE9E;
    h[13] = 0xFE69;
    h[14] = 0xFF4D;
    h[15] = 0xFFD4;
    for(i = 0; i < 16; i++)
        d[i] = 0;
    
     nsamples = BUFFER_SIZE;    // No: of inputs

     thresh= 0x3bca; /* Reference thresh from MATLAB */
     
     /* Read filter input  data from header file */
     /* input is scaled down by 1 bit right to allow */
     /* filter output power not to overflow beyond 32 bits */

     for(i=0;i<nsamples;i++)
     {
       in[i+1] = FIRINPUT1[i]>> 1;  
     }
     
    nsamples=BUFFER_SIZE/2; // No: of outputs
    /*{ Perform Test by calling  fir_decima() }*/
// For stall analysis of 256 inputs, test1 is used and test2a and test 2b are masked    
// For testing purposes test2a and test2b are used and test1 is masked.
// Test2a finds decimated filter output for Ni/2 samples and dslay line gts updated.
// Test2b finds decimated filter output for the next Ni/2 samples with the delay line
    // previously updated by test2a.
    _fir_decima(&in[1], out,nsamples, h, 16, 2, 8, d);                              // Test 1
//  _fir_decima(&in[1], out,nsamples/2, h, 16, 2, 8, d);                                // Test 2a  
//  _fir_decima(&in[nsamples+1], &out[nsamples/2],nsamples/2, h, 16, 2, 8, d);  // Test 2b

    /*{ Verify results for Test.  Output should compare with the precalculated value. }*/
   
    accout = 0;
     for (i = 0; i < nsamples; i++)
     {
       accout += out[i] * out[i];
     }
    outputmag = (fract16)(accout>> NBITS1); 
    error = outputmag - thresh;
    if(error<0) error = -error;    
    if(error > bitaccuracy)  
     {
        error_flag |= TEST_ERROR;
        printf("\n Test failed.\n");
        #ifdef PRINT_ON_ERROR
        printf("\n calculated outputmag - 0x%4.4x\n",outputmag);
        printf("\n expected outputmag   - 0x%4.4x\n",thresh);
        printf("\n bitaccuracy          -  0x%4.4x\n",bitaccuracy);
        #endif
        return error_flag;  
     }
    
     return error_flag;
}

main()
{
 int r;
 r = tfir_deci(_fir_decima);
 if(r) 
 printf("\nfunction failed");
 else printf("\n passed.\n");
}

⌨️ 快捷键说明

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