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

📄 chebfunc.cpp

📁 Digital filter designer s handbook C++ code source
💻 CPP
字号:
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//  File = chebfunc.cpp
//
//  Chebyshev Filter Function
//

#include <math.h>
#include "misdefs.h"
#include "chebfunc.h"
#include "d_cmplx.h"

//======================================================
//  constructor

ChebyshevTransFunc::ChebyshevTransFunc( int order,
                                        double ripple,
                                        int ripple_bw_norm )
                   :FilterTransFunc(order)
{
 double x;
 int k;
 double epsilon, gamma;
 double big_r, big_a;
 double sigma_mult, omega_mult;
 double_complex work;
 
 Prototype_Pole_Locs = (double_complex*)new double[2*(order+1)];
 Num_Prototype_Poles = order;
 Prototype_Zero_Locs = (double_complex*)new double[2];
 Num_Prototype_Zeros = 0;
 
 epsilon = sqrt(pow(10.0, (double)(ripple/10.0)) -1.0);
 gamma = pow( (1+sqrt(1.0 + epsilon*epsilon))/epsilon,
              1.0/(double)order); 
 if(ripple_bw_norm)
   {
    big_r = 1.0;
   }
 else
   {
    big_a = log((1.0+sqrt(1.0-epsilon*epsilon))/epsilon)/order;
    big_r = (exp(big_a)+exp(-big_a))/2.0;
    cout << "big_r = " << big_r << endl; 
   }
              
 //sigma_mult = ( (1.0/gamma) - gamma) / 2.0;
 sigma_mult = ( (1.0/gamma) - gamma) / (2.0 * big_r);
 
 omega_mult = ( (1.0/gamma) + gamma) / (2.0 * big_r);
 
 for(k=1; k<=order; k++)
   {
    x = PI * ((2*k)-1) / (2*order);
    
    Prototype_Pole_Locs[k] = double_complex( sigma_mult * sin(x),
                                             omega_mult * cos(x) );
   }
 //------------------------------------------------
 //  compute gain factor Ho
 
 work = double_complex(1.0, 0.0);
 for(k=1; k<=order; k++)
   {
    work *= (-Prototype_Pole_Locs[k]);
   }
 
 H_Sub_Zero = real(work);
 
 if(order%2 == 0)  // if order is even
   {
    //H_Sub_Zero *= pow(10.0, (double)ripple/20.0); 
    H_Sub_Zero /= sqrt(1.0 + epsilon*epsilon);
   }
  
 return;
};

⌨️ 快捷键说明

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