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

📄 fcos.c

📁 CHP 3 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
// 
//  Project: Experiment 3.6.5.1 Function Approximaiton - Chapter 3 
//  File name: fcos.c   
//
//  Description: This experiment program uses floating-point C
//               to calculate cosine function in the range of [0, PI/2]
//               by approcimation: cos(x)=1-(1/2!)x^2+(1/4!)x^4-(1/6!)x^6
//
//  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
//
//


#define PI (double)3.1415926

// Function approximation coefficients for cosine
double fcosCoef[4]={
  1.0, 
 -(1.0/2.0), 
  (1.0/(2.0*3.0*4.0)),
 -(1.0/(2.0*3.0*4.0*5.0*6.0))
};

// Direct implementation of function approximation
double fCos1(double x)
{
  double cosine;

  cosine  = fcosCoef[0];
  cosine += fcosCoef[1]*x*x;
  cosine += fcosCoef[2]*x*x*x*x;
  cosine += fcosCoef[3]*x*x*x*x*x*x;
  return(cosine);
}

// More efficient implementation of function approximation
double fCos2(double x)
{
  double cosine,x2;

  x2 = x * x;               
  cosine = fcosCoef[3] * x2;
  cosine = (cosine+fcosCoef[2]) * x2;
  cosine = (cosine+fcosCoef[1]) * x2;
  cosine = cosine + fcosCoef[0]; 
  return(cosine);
}


void main(void)
{
  static double y[5];

  y[0] = fCos1(0.0);                     // Floating-point calculation
  y[1] = fCos1(PI/6.0);                  // Floating-point calculation
  y[2] = fCos1(PI/4.0);                  // Floating-point calculation
  y[3] = fCos1(PI/3.0);                  // Floating-point calculation
  y[4] = fCos1(PI/2.0);                  // Floating-point calculation

  y[0] = fCos2(0.0);                     // Floating-point calculation
  y[1] = fCos2(PI/6.0);                  // Floating-point calculation
  y[2] = fCos2(PI/4.0);                  // Floating-point calculation
  y[3] = fCos2(PI/3.0);                  // Floating-point calculation
  y[4] = fCos2(PI/2.0);                  // Floating-point calculation     
}


⌨️ 快捷键说明

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