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

📄 decimationtest.c

📁 CHP 4 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
// 
//  Project: Experiment 4.5.5 Decimation using FIR filter - Chapter 4
//  File name: decimationTest.c   
//
//  Description: This is the test file for the decimation FIR 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 <stdlib.h>
#include <stdio.h>

#include "decimation.h"

// Define DSP system memory map  
#pragma DATA_SECTION(deciFilt48to24, "expdata0:fir");
#pragma DATA_SECTION(deciFilt24to8, "expdata0:fir");
#pragma DATA_SECTION(temp, "expdata0:fir");
#pragma DATA_SECTION(x1, "expdata1:fir");
#pragma DATA_SECTION(x2, "expdata1:fir");
#pragma DATA_SECTION(y, "expdata1:fir");
#pragma DATA_SECTION(w1, ".bss:fir");
#pragma DATA_SECTION(w2, ".bss:fir");
#pragma DATA_ALIGN(w1, 2);       // Use dual MAC, align to 32 bits
#pragma DATA_ALIGN(w2, 2);       // Use dual MAC, align to 32 bits

short deciFilt48to24[TAPS48to24]={
  #include "coef48to24.h"
};
short deciFilt24to8[TAPS24to8]={
  #include "coef24to8.h"
};

short w1[TAPS48to24+1];          // Use dual MAC, add one space
short w2[TAPS24to8+1];           // Use dual MAC, add one space
short x1[DEC_NUM_DATA_IN],       // Input data
      x2[DEC_NUM_DATA2],         // Intermediate data
      y[DEC_NUM_DATA_OUT];       // Output data
char  temp[DEC_NUM_DATA_IN*2];   // Temp buffer for file IO

void main()
{
  FILE  *fpIn,*fpOut;
  short i,k,
        index1,                 // Delay line w1 index
        index2;                 // Delay line w2 index

  fpIn = fopen("..\\data\\tone1k_48000.pcm", "rb");
  fpOut = fopen("..\\data\\output1kHz8kHz.pcm", "wb");

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

  index1 = 0;
  index2 = 0;

  // Begin filtering the data
  while (fread(temp, sizeof(char), DEC_NUM_DATA_IN*2, fpIn) 
         == (DEC_NUM_DATA_IN*2))
  {
    for (k=0, i=0; i<DEC_NUM_DATA_IN; i++)
    {
      x1[i] = (temp[k]&0xFF)|(temp[k+1]<<8);
      k += 2;
    }
    // Decimate the input data x and save the output data y
    decimator(x1, DEC_NUM_DATA2, 
              deciFilt48to24, TAPS48to24, 
              x2, 
              w1, &index1,
              2);

    decimator(x2, DEC_NUM_DATA_OUT, 
              deciFilt24to8, TAPS24to8, 
              y, 
              w2, &index2,
              3);

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

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

  fclose(fpIn);
  fclose(fpOut);
}

⌨️ 快捷键说明

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