📄 iir_fixpt_ccs.c
字号:
/*****************************************************************
* iir_fixpt_ccs.c- Fixed-point C program for IIR filtering using
* direct-form II biquads for CCS of C5000
* in Section 7.7.4
******************************************************************
* 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
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;
while(size--){
out=(long)((int)(((long)*input++ * (long)gain)>>15));
/*************************************************************
* IIR filtering: feedback follow by feedforward and repeat
* for three sections.
*************************************************************/
for (j=0; j<section; j++)
{
/* feedback section */
out=out-(long)((int)(((long)delay[1+(j*section)]*(long)(int)DEN[j][1] )>>15));
delay[(j* section)]=(int)(out-(long)((int)(((long)delay[2+(j* section)]*(long)(int)DEN[j][2])>>15)));
/* feedforward section */
out=(long)(delay[(j*section)]+(int)(((long)delay[1+(j* section)]*(long)(int)NUM[j][1])>>15));
out=out+ (long)((int)(((long)delay[2+(j*section)]*(long)(int)NUM[j][2])>>15));
/* refresh 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 + -