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

📄 intrinsics_iirtest.c

📁 CHP 5 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
// 
//  Project: Experiment 5.7.4: implementation of direct form-II IIR filter in intrinsics - Chapter 5
//  File name: intrinsics_IIRTest.c   
//
//  Description: This is the test program for the intrinsics fixed-point IIR filter in direct form II
//
//  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 "intrinsics_IIR.h"
#include "fdacoefsMATLAB.h"

#define SECTIONS       ((MWSPT_NSEC-1)/2)     // Number of 2nd order sections
short   C[SECTIONS*5]; // Filter coefficients obtained from example 5.14 MATLAB FDATool
                       // C[]=A[i][1], A[i][2], B[i][2], B[i][0], B[i][1]... 
short   w[SECTIONS*2]; // Filter delay line
                       // w[]=w[i][n-1],w[i+1][n-1],...,w[i][n-2],w[i+1][n-2],...

#define NUM_DATA       128                    // Number of samples per block 
short   out[NUM_DATA]; // Filter output data buffer
short   in[NUM_DATA];  // Filter input data buffer

         
void main(void)
{
  short i,k,n;
  short gainNUM,gainDEN;
  long  temp32;
  char  temp[NUM_DATA*2];

  FILE  *fpIn,*fpOut;

  // Open file to read input data and write output data
  if ((fpIn = fopen(".\\..\\data\\in.pcm", "rb"))== NULL)
  {
    printf("Can't open input data file\n");
    exit(0);
  }
  fpOut = fopen(".\\..\\data\\out.pcm", "wb");

  // Initialize IIR filter delay line 
  for (i=0; i<SECTIONS*2;i++)
  {
    w[i] = 0; 
  }

  // Get coefficients from DEN[][] and NUM[][]
  for(k=0, n=0, i=0; i<SECTIONS; i++)
  {
    gainDEN = DEN[k][0];
    gainNUM = NUM[k++][0];

    temp32 = (long)gainDEN * DEN[k][1];
    C[n++] = (short)(temp32>>14);
    temp32 = (long)gainDEN * DEN[k][2];
    C[n++] = (short)(temp32>>14);

    temp32 = (long)gainNUM * NUM[k][2];
    C[n++] = (short)(temp32>>14);
    temp32 = (long)gainNUM * NUM[k][0];
    C[n++] = (short)(temp32>>14);
    temp32 = (long)gainNUM * NUM[k++][1];
    C[n++] = (short)(temp32>>14);
  }

  // IIR filter experiment start 
  while (fread(temp, sizeof(char), NUM_DATA*2, fpIn) == (NUM_DATA*2))
  {
    for (k=0, i=0; i<NUM_DATA; i++)
    {
      in[i] = (temp[k]&0xFF)|(temp[k+1]<<8);
      k += 2;
    }

    intrinsics_IIR(in,NUM_DATA,out,C,SECTIONS,w); // Filter a block of samples  

    for (k=0, i=0; i<NUM_DATA; i++)
    {
      temp[k++] = (out[i]&0xFF);
      temp[k++] = (out[i]>>8)&0xFF;
    }

    fwrite(temp, sizeof(char), NUM_DATA*2, fpOut);
  }

  fclose(fpIn);
  fclose(fpOut);
}

⌨️ 快捷键说明

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