📄 tiir.c
字号:
/****************************************************************************
Copyright (c) 2000 Analog Devices/Intel. All rights reserved.
Developed by JD(FRIO), IPDC, Bangalore, INDIA.
***************************************************************************
File Name : tiir.c
Module Name : Test IIR
Description : This module tests the iir function.
***************************************************************************/
// Constants
#define BUFFER_SIZE 64
#define BASE_NSAMPLES 64
#define DELAY_SIZE 15
#define TEST_ERROR 0x0620
// Includes
#include "mds_def.h"
#include "filter.h"
#include "tiir.h"
/***************************************************************************
* Func name : tiir
****************************************************************************
Purpose : Test iir() function.
Description : Performs the following test on either function:
1) Low pass attenuation test (Fourth order)
multiple value input test, Order = 4 ((N % 2) = 0)
*************************************************************************/
extern fract16 out[];
extern fract16 in[];
extern fract16 delay[];
extern fract16 c[];
extern void _iir(const fract16 [], fract16 [], int, iir_state_fr16 *);
int // return - Test status flag
tiir(void (*_iir)(const fract16 [], fract16 [], int , iir_state_fr16 *))
{
fract16 energy;
fract32 acc=0;
int i, nsamples, nstages;
int error_flag, error = 0;
int bitaccuracy=4;
iir_state_fr16 s;
error_flag = 0; // Clear status flag
/**************************************************************************
* Test : Multiple Value Test (Fourth Order, N % 2 = 0)
* Type: Correctness
* Description: Coefficients for a fourth order low pass filter generated
* using Matlab will be passed to the iir routine. . The entire array is
* passed to the routine. The energy of the filtered
* output using the iir routine and Matlab are compared.
***************************************************************************/
printf("\n Testing property ...\n");
//{ Initialization for Test : Multiple Value Test, N % 2 = 0}
c[0] = 0x1EFD;
c[1] = 0x2B75;
c[2] = 0x1F04;
c[3] = 0x2776;
c[4] = 0xC6B1;
c[5] = 0x62ED;
c[6] = 0x26DB;
c[7] = 0x62F0;
c[8] = 0x6F10;
c[9] = 0x0108;
nsamples = BUFFER_SIZE;
nstages = 2;
for (i = 0; i < DELAY_SIZE; i++)
delay[i] = 0;
iir_init(s, c, delay, nstages);
// Store the Input samples having a frequency in the pass band
for(i=0;i<nsamples;i++)
in[i] = INPPASS[i];
// Perform Test by calling iir() or _iir() }
// For stall analysis of 64 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 iir biquad filter output for Ni/2 samples and dslay line gets updated.
// Test2b finds iir biquad filter output for the next Ni/2 samples with the delay line
// previously updated by test2a.
_iir(in, out, nsamples, &s); // Test 1
// _iir(in, out, nsamples/2, &s); // Test 2a
// _iir(&in[nsamples/2], &out[nsamples/2], nsamples/2, &s); // Test 2b
// Check the energy of the output
acc = 0;
for(i=0;i < nsamples;i++)
acc += (out[i] * out[i]);
energy = (acc>> NBITS1); // Store accumlated power
//in fract16 format
error = thresh - energy;
if(error < 0)
error = -error;
// bitaccuracy = 4;
if ( error > bitaccuracy )
{
error_flag = TEST_ERROR|i;
printf("\n Test failed \n");
printf("\nExpected Output Energy = %x Computed Output Energy = %x\n", thresh, energy);
printf("\nBit accuracy = %d\n", bitaccuracy);
return error_flag;
}
else
printf("Passed Test (two stage biquad)\n");
return error_flag;
}
main()
{
int r;
r = tiir(_iir);
if(r)
printf("\nfunction failed");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -