📄 ccsfir.c
字号:
/*-------------------------------------------------------------------*
* CCSFIR.C - Target Source code for demo : CCSFIRDEMO
* Implements a simple FIR filter that uses signed integers (16-bit)
* for both data and coefficients.
*
* Unintialized data (must be filled in before execution!)
* int16 din[]; - input data of storage (data to be filtered)
* int32 nbuf - number of valid elements stored in din[] (and dout)
* int16 coeff[]; - FIR filter coefficients
* int32 ncoeff; - number of valid elements stored in coeff[]
*------------------------------------------------------------------*/
/* Copyright 2001-2002 The MathWorks, Inc.
* $Revision: 1.6 $ $Date: 2002/06/12 15:31:04 $ */
#include <stdio.h>
#include <stdlib.h>
#include "tmwtypes.h"
#ifdef DEBUG
#define dbg_puts(STR) puts(STR)
#else
#define dbg_puts(STR)
#endif
void fir_filter(void);
enum etype {
NO_ERROR = 0,
COEFF_OVER,
COEFF_UNDER,
BUF_OVER,
BUF_UNDER,
UNKNOWN
};
enum etype errorcondition = NO_ERROR;
#define MAX_BUFSIZE 2048 /*-- Upper limit on data buffer --*/
#define MAX_COEFF 64 /*-- Upper limit on number of coeff --*/
/*-- define buffers, leave uninitialized, to be supplied by Matlab -*/
int16 din[MAX_BUFSIZE];
int16 dout[MAX_BUFSIZE];
int16 coeff[MAX_COEFF];
/*-- defines actual size, must be less than limit -*/
int32 ncoeff;
int32 nbuf;
/*----------- main ---------------------------------------------*
* This program is used with the Demo for the Code Composer Studio(tm) IDE.
*
* It uses the DSPLIB supplied by Texas Instruments to filter
* blocks of data generated by Matlab.
*
* Note - when main
*--------------------------------------------------------------*/
void main()
{
dbg_puts("Start");
fir_filter();
if(errorcondition == NO_ERROR)
dbg_puts("Completed FIR filter, NO ERRORS!\n");
else
dbg_puts("!!! FIR execution failed\n");
/*exit(0); This routine must cause the program to halt */
}
/*----------- fir_filter ---------------------------------------*
* Implementation of FIR filter
* By default, this subroutine uses a "C" implementation
* of the FIR filter. However, it is possible to substitute
* the default code for the FIR filter routine 'fir-gen' supplied
* in the optimized DSP Library created by Texas Instruments.
*
*--------------------------------------------------------------*/
void fir_filter( )
{
/* This is an alternate version of fir_filter program that
* uses the Texas Instruments library file: dsplib.lib
* To use this version, include this library in the project,
* then substitute this code for the C version of the filter.
* the library version is an optimized Assembly language library
* routine that should run much faster
* fir_gen syntax:
* void fir_gen (short *x, short *h, short *r, int nh, int nr)
* x = input array
* h = coefficient array
* r = output array
* nh = number of coefficients (nh >= 5)
* nr = number of output samples (nr >= 1)
*/
/*
if (nbuf < 1) {
errorcondition = DIN_OVER;
printf("Illegal buffer size\n");
}
if (ncoeff < 5) {
errorcondition = COEFF_OVER;
printf("Illegal buffer size\n");
}
fir_gen(din,coeff,dout,ncoeff,nbuf);
*/
int32 i, j, sum;
if( ncoeff < 1 ) {
errorcondition= COEFF_UNDER;
return;
}
else if( ncoeff > MAX_COEFF) {
errorcondition= COEFF_OVER;
return;
}
else if ( nbuf < 1) {
errorcondition= BUF_UNDER;
return;
}
else if ( nbuf > MAX_BUFSIZE) {
errorcondition= BUF_UNDER;
return;
}
for (j = 0; j < nbuf; j++) {
sum = 0;
for (i = 0; i < ncoeff; i++) {
sum += din[i + j] * coeff[i];
dout[j] = sum >> 15;
}
}
errorcondition = NO_ERROR;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -