⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fixpoint_directiirtest.c

📁 CHP 5 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
// 
//  Project: Experiment 5.7.2: implementation of fixed-point IIR filter in direct form I - Chapter 5
//  File name: fixPoint_directIIRTest.c   
//
//  Description: This is the test file for the fixed-point IIR filter in direct form I
//
//  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 "fixPointIIR.h"

// Coefficient length
#define NL  13
#define DL  13
#define Q11 2047

// Filter coefficients obtained from example 5.12 MATLAB script
short num[NL] = {(short)(0.0039*Q11+0.5), (short)(0.0000*Q11+0.5), 
	             (short)(0.0028*Q11+0.5), (short)(0.0000*Q11+0.5), 
				 (short)(0.0074*Q11+0.5), (short)(0.0000*Q11+0.5),
                 (short)(0.0025*Q11+0.5), (short)(0.0000*Q11+0.5), 
				 (short)(0.0074*Q11+0.5), (short)(0.0000*Q11+0.5), 
				 (short)(0.0028*Q11+0.5), (short)(0.0000*Q11+0.5), 
				 (short)(0.0039*Q11+0.5)};

short den[DL] = {(short)(1.0000*Q11+0.5), (short)(0.0000*Q11+0.5), 
                 (short)(4.2912*Q11+0.5), (short)(0.0000*Q11+0.5), 
				 (short)(8.2629*Q11+0.5), (short)(0.0000*Q11+0.5),
                 (short)(8.9932*Q11+0.5), (short)(0.0000*Q11+0.5), 
				 (short)(5.7991*Q11+0.5), (short)(0.0000*Q11+0.5), 
				 (short)(2.0930*Q11+0.5), (short)(0.0000*Q11+0.5), 
				 (short)(0.3300*Q11+0.5)};

// Filter delay lines
short x[NL],y[DL];

void main()
{
  short  in,i;
  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;
  }
  for(i=0; i<DL; i++)
  {
    y[i] = 0;
  }

  // Filter test
  while (fread(temp, sizeof(char), 2, fpIn) == 2)
  {
    in = (temp[0]&0xFF)|(temp[1]<<8);

    // Filter the data
    fixPoint_IIR(in, x, y, num, NL, den, DL);

    temp[0] = (y[0]&0xFF);
    temp[1] = (y[0]>>8)&0xFF;
    fwrite(temp, sizeof(char), 2, fpOut);
  }
  
  fclose(fpIn);
  fclose(fpOut);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -