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

📄 fixedpointblockfirtest.c

📁 CHP 4 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
// 
//  Project: Example 4.20: fixed-point implementation of block FIR filter - Chapter 4
//  File name: fixedPointFirTest.c   
//
//  Description: This is the test file for the example of fixed-point block FIR filter
//               The input data consistsof 3 tones (800, 1800, and 3300 Hz).
//               The output data is the bandpass filtered input tones.
//               The output data shows only the 1800 Hz tone left.
//
//  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
//

#include <stdlib.h>
#include <stdio.h>

#include "fixedPointFir.h"

short firCoefFixedPoint[NUM_TAPS]={
  #include "firCoef.h"
};

short w[NUM_TAPS];

void main()
{
  FILE  *fpIn,*fpOut;
  short i,k,
        index;        // delay line index
  short x[NUM_DATA],  // input data
        y[NUM_DATA];  // output data
  char  temp[NUM_DATA*2];

  fpIn = fopen("..\\data\\input.pcm", "rb");
  fpOut = fopen("..\\data\\output.pcm", "wb");

  if (fpIn == NULL)
  {
    printf("Can't open input file\n");
    exit(0);
  }
	
  // Initialize for filtering process
  for (i=0; i<NUM_TAPS; i++)
  {
    w[i] = 0;
  }
  index = 0;

  // Begin filtering the data
  while (fread(temp, sizeof(char), NUM_DATA*2, fpIn) == (NUM_DATA*2))
  {
    for (k=0, i=0; i<NUM_DATA; i++)
    {
      x[i] = (temp[k]&0xFF)|(temp[k+1]<<8);
      k += 2;
    }
    // Filter the data x and save output y
    fixedPointBlockFir(x, NUM_DATA, 
                       firCoefFixedPoint, NUM_TAPS, 
                       y, 
                       w, &index);

    for (k=0, i=0; i<NUM_DATA; i++)
    {
      temp[k++] = (y[i]&0xFF);
      temp[k++] = (y[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 + -