📄 iir_fixpt_intr.c
字号:
/*****************************************************************
* iir_fixpt_intr.c- Fixed-point C program for IIR filtering using
* direct-form II biquads and C5000 intrinsics
* in Section 7.7.5
******************************************************************
* System configuration:
*
* in(n) |----------------| out(n)
* ---->| Bandpass filter|----->
* |----------------|
*
* in(n) is the input data from data file "in_int_ccs.dat"
*
*****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "iircoeff_ccs_16.h" // coefficient header file
#include <intrindefs.h> // including intrinsics
int in_buffer[300];
int out_buffer[300];
#define TRUE 1
/*Function */
static int iirproc(int *input, int *output);
static void dataIO(void);
void main()
{
/***************************************************************
* Declare file pointers
***************************************************************/
int *input = &in_buffer[0];
int *output= &out_buffer[0];
/***************************************************************
* Start of main program
***************************************************************/
while(TRUE)
{
/* read in x(n) from data file and processing it */
dataIO();
iirproc(input, output);
}
}
/* Function for IIR filtering */
static int iirproc(int *input, int *output)
{
/***************************************************************
* Define variable arrays, define and clear variables
***************************************************************/
const int section = 3;
long out = 0; /* y(n), output from IIR filter */
int delay[9] = {0,0,0,0,0,0,0,0,0};
int gain = 17;
int j;
int size = 300;
long temp;
while(size--){
out = _lsmpy(*input++,gain)>>16;
/*************************************************************
* IIR filtering: feedback follow by feedforward and repeat
* for three sections.
*************************************************************/
for (j=0; j<section; j++)
{
/* feedback section */
temp = _lsmpy(delay[1+(j*section)],(int16_T)DEN[j][1])>>16;
out = _lssub(out,temp);
temp = _lsmpy(delay[2+(j*section)],(int16_T)DEN[j][2])>>16;
delay[(j*section)] =(int)(_lssub(out,temp));
/* feedback section */
temp = _lsmpy(delay[1+(j*section)],(int16_T)NUM[j][1])>>16;
out = _lsadd((long)delay[(j*section)],temp);
temp = _lsmpy(delay[2+(j*section)],(int16_T)NUM[j][2])>>16;
out = _lsadd(out,temp);
/* updates signal buffer */
delay[2+(j* section)] = delay[1+(j* section)];
delay[1+(j* section)] = delay[(j* section)];
}
*output++ = (int)(out*8);
}
return(TRUE);
}
/* Function for dataIO */
static void dataIO()
{
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -