📄 floatpoint_directiirtest.c
字号:
//
// Project: Experiment 5.7.1: implementation of floating-point IIR filter in direct form I - Chapter 5
// File name: floatPoint_directIIRTest.c
//
// Description: This is the test file for the floating-point direct form I IIR filter
//
// For the book "Real Time Digital Signal Processing:
// Implementation and Application, 2nd Ed"
// By Sen M. Kuo, Bob H. Lee, and Wenshun Tian
// Publisher: John Wiley and Sons, Ltd
//
// Tools used: CCS v.2.12.07
// TMS320VC5510 DSK Rev-C
//
#include <stdio.h>
#include <stdlib.h>
#include "floatPointIIR.h"
// Coefficient length
#define NL 13
#define DL 13
// Filter coefficients obtained from example 5.12 MATLAB script
double num[NL] = {0.0039, 0.0000, 0.0028, 0.0000, 0.0074, 0.0000,
0.0025, 0.0000, 0.0074, 0.0000, 0.0028, 0.0000, 0.0039};
double den[DL] = {1.0000, 0.0000, 4.2912, 0.0000, 8.2629, 0.0000,
8.9932, 0.0000, 5.7991, 0.0000, 2.0930, 0.0000, 0.3300};
// Filter delay lines
double x[NL],y[DL];
void main()
{
double in;
short i,z;
FILE *fpIn,*fpOut;
char temp[2];
// Open file for read input data
if ((fpIn = fopen("..\\data\\input.pcm", "rb"))== NULL)
{
printf("Can't open input data file\n");
exit(0);
}
// Open file for write output data
fpOut = fopen("..\\data\\output.pcm", "wb");
// Clear delay lines
for(i=0; i<NL; i++)
{
x[i] = 0.0;
}
for(i=0; i<DL; i++)
{
y[i] = 0.0;
}
// Filter test
while (fread(temp, sizeof(char), 2, fpIn) == 2)
{
// Convert 16-bit PCM data to floating-point format
z = (temp[0]&0xFF)|(temp[1]<<8);
in = (double)z/32767.0;
// Filter the data
floatPoint_IIR(in, x, y, num, NL, den, DL);
// Convert the floating-point data back to 16-bit PCM data format
z = (short)(y[0]*32767.0 + 0.5);
temp[0] = (z&0xFF);
temp[1] = (z>>8)&0xFF;
fwrite(temp, sizeof(char), 2, fpOut);
}
fclose(fpIn);
fclose(fpOut);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -