📄 fir_filters.c
字号:
/*****************************************************************************/
/* FILENAME */
/* FIR_filters.c */
/* */
/* DESCRIPTION */
/* Finite Impulse Response Filters using the TMS320C5416 DSK. */
/* */
/* Rev 1.00 Richard Sikora */
/* */
/*---------------------------------------------------------------------------*/
/* HISTORY */
/* Rev 1.00 */
/* 31st October 2002. Created by Richard Sikora from TMS320C5402 code. */
/* */
/* */
/*****************************************************************************/
#include <stdio.h>
#define FIR_FILTER_SIZE 51
/*****************************************************************************/
/* FIR_filter() */
/*---------------------------------------------------------------------------*/
/* */
/* INPUTS: 1st parameter. Address of array of filter constants. */
/* 2nd parameter. Latest input to filter */
/* */
/* RETURNS: Output of FIR filter */
/* */
/*****************************************************************************/
short int FIR_filter(signed int * filter_constants, signed int input)
{
static int value[FIR_FILTER_SIZE]; /* Retain value between calls */
signed int return_value;
signed int i; /* Index into filter constants */
long product;
static signed int j = 0; /* Index into input array */
product = 0;
for ( i = 0 ; i < FIR_FILTER_SIZE ; i++)
{
/* Generate sum of products. Shift right to prevent overflow */
/* This is first part of divide by 32767 */
product += ( (long)(value[j] * filter_constants[i]) >> 5);
if ( j < FIR_FILTER_SIZE-1) /* Next item in circular buffer */
{
j++;
}
else
{
j = 0; /* Go back to beginning of buffer */
}
}
if ( j < FIR_FILTER_SIZE -1) /* Loop done. Last filter element */
{
j++;
}
else
{
j = 0; /* Point to new value */
}
product >>= 10; /* Second part of divide by 32768 */
value[j] = input; /* Read in new value for next time. */
return_value = (signed int) product;
return(return_value);
}
/***************************************************************************/
/* Dual FIR Filter. Produces both bass and treble outputs */
/*-------------------------------------------------------------------------*/
/* */
/* INPUTS: 1st parameter. Address of filter constants */
/* 2nd parameter. Latest input to filter */
/* */
/* RETURNS: 32-bit int containing both bass and treble outputs */
/* High word contains treble */
/* Low word contains bass */
/* */
/***************************************************************************/
signed long FIR_dual_filter( const int * filter_constants, signed int input)
{
static int value[FIR_FILTER_SIZE]; /* Retain value between calls */
signed long output1;
signed long output2;
signed int i; /* Index into filter constants */
signed long product;
static signed int j = 0; /* Index into input array */
signed long mid_point;
product = 0;
for ( i = 0 ; i < FIR_FILTER_SIZE ; i++)
{
/* Multiply input by corresponding coefficient. Divide by 32 */
/* to prevent overflow. */
product += ( (long)(value[j] * filter_constants[i]) >> 5);
if ( i == ((FIR_FILTER_SIZE-1)/2) )
{
mid_point = value[j]; /* Not value[i] */
}
if ( j < FIR_FILTER_SIZE-1) /* Next item in circular buffer */
{
j++;
}
else
{
j = 0; /* Go back to beginning of buffer */
}
}
/* One more increment of pointer is required */
if ( j < FIR_FILTER_SIZE -1)
{
j++;
}
else
{
j = 0; /* Point to new value */
}
product >>= 10; /* Remove remains of fractional part */
value[j] = input; /* Read in new value */
output1 = (mid_point- product); /* First output to high word */
output1 <<= 16;
output2 = (product & 0xFFFF); /* Second output to low word */
/* Combine two outputs into a single return value */
return( output1 | output2 );
}
/***************************************************************************/
/* End of FIR_filters.c */
/***************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -