Page 267 - Analog and Digital Filter Design
P. 267

Analog and Digital Filter Design




                        Listing 9.1 is reproduced from Chapter 4, listing 4.1 of Digital Filter Designer's
                        Handbook by C. Britton Rorabaugh, 1993. Reproduced with permission from
                        McGraw-Hill.



                        /*****x******t**********r******t***   /
                        /*                          */
                        /*   Listing 4.1            */
                        /*                          +/
                        / *   ChebyshevFreqResponse )   * /
                                                (
                        /*                          */
                        /**********xtt********fxt***c******/
                        #include (math.h)
                        #define PI  (double) 3.141592653589
                        void chebyshevFreqResponse(  int order,
                                                float ripple,
                                                 char normalizationType.
                                                float frequency,
                                                float  *magnitude,
                                                 float *phase)
                        I
                        double A, gamma, epsilon, work;
                        double rp, ip,  x, i, r, rpt, ipt;
                        double normalizedFrequency, hSubZero;
                        int k, ix;
                        epsilon =  sqrt( -1.0 +  pow(  (double)lO.O, (double) (rippleil0.0) ));
                        gamma =  pow(  (  (  1.0 +  sqrt (  1.0 +  epsilon+epsilon) /epsilon),
                                                  (double) (l.O/(float) order) );
                        if (  nomLalizationType =  '3'  )
                               I
                              work =  l.O/epsilon;
                               A =  (  log(  work +  sqrt( work'work   - 1.0) )   )  /  order;
                               normalizedFrequency  =  frequency *  (  exp(A) +  exp(-A) ) /2.0;
                               1
                        else
                               I
                               normalizedFrequency =  frequency;
                               }
                        rp =  1.0;
                        ip =  0.0;
                        for( k =  4; k<  =  order; k++)
                               1
                               x =  (2*k - 1) *  PI  /  (2.0*order);
                               i =  0.5  *  (gamma +  l.O/gamma) *  cos(x);
                               r =  -0.5  *  (gamma - l.O/gamrr~a) *  sin(x);
                               rpt =  ip *  i - rp  *  I;
                               ipt =  -rp  *  i - r *  ip;
                               ip =  ipt;
                               rp =  rpt;
                               I   .
                        hsubzero =  sqrt( ip*ip +  rp*rp);
                        if( order%2 =  0 I
                               hsubzero =  hSubZero /  sqrt(l.0 +  epsilon*epsilon);
   262   263   264   265   266   267   268   269   270   271   272