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

📄 iir_floatpt.c

📁 用dsp解压mp3程序的算法
💻 C
字号:
/*****************************************************************
*  iir_floatpt.c- C program for IIR filtering, cascade of three
*                 direct-form II sections in floating-point
*                 Section 7.7.2
******************************************************************
*  System configuration:
* 
* in(n) |----------------| out(n)
*  ---->| Bandpass filter|----->
*       |----------------|
*
******************************************************************
*  System simulation configuration:
*
*     in(n) is the input data from data file "in.dat"
*     out(n) is the output data to data file "out.dat"
*
*****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "iircascade_sp.h" 

void main()
{
  /***************************************************************
  *    Define variable arrays, define and clear variables
  ***************************************************************/
  const int section = 3;
  const int tap = 3;
  float out = 0.0;          /* y(n), output from IIR filter     */
  float xn;
  float delay[9] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
  float gain = 0.004204816817972;
  int j;
 
  /***************************************************************
  *    Declare file pointers
  ***************************************************************/

  FILE *xn_in;                    /* file pointer of x(n)       */
  FILE *yn_out;                   /* file pointer of y(n)       */
  xn_in = fopen("in.dat","r");    /* open file for input x(n)   */
  yn_out = fopen("out.dat","w");  /* open file for output y(n)  */

  /***************************************************************
  *    Start of main program
  ***************************************************************/
  
  while ((fscanf(xn_in,"%f",&xn)) != EOF)
  {          /* read in x(n) from data file and processing it   */
	
    out=xn*gain;
        
    /*************************************************************
    *   IIR filtering: (feedback follow by feedforward) and repeat
    *         for three sections.
    *************************************************************/
    
    for (j=0; j< section; j++)	
    {
	  /*   feedback section    */
      out=out-(delay[1+(j*section)]*(real32_T)DEN[j][1]);
      delay[(j*section)]=out-(delay[2+(j* section)]*(real32_T)DEN[j][2]);

	  /*   feedforward section   */
      out=delay[(j* section)]+(delay[1+(j* section)]*(real32_T)NUM[j][1]);
      out=out+(delay[2+(j*section)]*(real32_T)NUM[j][2]);		

	  /*    refreshes signal buffer    */
      delay[2+(j*section)] = delay[1+(j*section)];
      delay[1+(j*section)] = delay[(j*section)];
    }       
    fprintf(yn_out,"%f\n",out);	
  }
  printf("Finish");	      /* complete filtering            */  
  fcloseall();                /* close all opened files        */
}

⌨️ 快捷键说明

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