home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / tech / design2 / mxfilter.pas < prev    next >
Pascal/Delphi Source File  |  1986-06-11  |  21KB  |  593 lines

  1. program maxfilter;    { Program Maximizes Possible Ripple Frequencies }
  2.                       { While Maintaining Required Attenuation Values }
  3.                       { Specified in Stop Band                        }
  4.  
  5. {        Jeff Crawford                   TRW          February 14, 1985 }
  6.  
  7. { StopBand Requirements Are Specified by Operator. This Program Calculates   }
  8. { if The Difference Between That Obtainable [ Using Chebycheff Approx.] and  }
  9. { That Required is > 0 At All Specified StopBand Frequencies.  If This       }
  10. { Margin is Not > 0 Then a Higher Order Filter is Required.  If the Margin is}
  11. { > 0 the StopBand Frequency at Which the Smallest Margin Exists is          }
  12. { Determined by a Simple Search.  First, Using the Previously Given Upper    }
  13. { Ripple Frequency, Linear Interpolation of the [Loss Function - Required Att}
  14. { is Used to Move Out the Lower Ripple Frequency to a Point Where the        }
  15. { Equation Above is Identically Zero.  A New Geometric Center Frequency is   }
  16. { Calculated.  Another Determination of Which Upper StopBand Frequency Has   }
  17. { the Least Margin With the Newly Calculated Lower wp is Made. Linear        }
  18. { Interpolation of the Upper StopBand Frequency is Done With the Previously  }
  19. { Calculated New Lower Ripple Frequency, wp_lo.  This Entire Procedure is    }
  20. { Continued Until Convergence.                                               }
  21.  
  22. {                              REFERENCES                                    }
  23.  
  24. {   [1] "Dissipation Loss of Chebyshev BandPass Filters", Harold Schumacher, }
  25. {       Microwave Journal, pp 41-43, August, 1977.                           }
  26. {   [2] " Microwave Filters, Impedance Matching Networks, and Coupling       }
  27. {       Structures", G.L. Matthaei, Leo Young, E. M. T. Jones, McGraw Hill   }
  28. {       Book Company, 1964.                                                  }
  29. {   [3] "Principles of Active Network Synthesis and Design", Gobind Daryanani}
  30. {       John Wiley & Sons, 1976.                                             }
  31.  
  32.  
  33. type     matrix_a = array[1..16] of real;
  34.  
  35. var      wp_lo_max,wp_hi_min      : real; { Lower, Upper Ripple Freqs; Begin }
  36.          wp_lo,wp_hi              : real; { Iterated New Ripple Freqs        }
  37.          eta,L_db                 : real; { dB Ripple in                     }
  38.          N_lo,N_hi                : integer; { # Requirements in Stop-Bands  }
  39.          i,j,ii                   : integer; { Loop Counters                 }
  40.          Freq                     : matrix_a; { Frequencies in Stop-Bands    }
  41.          Att                      : matrix_a; { Attenuations in Stop-Bands   }
  42.          delta_Db                 : matrix_a; { Differences in Attenuation   }
  43.                                               { & That Specified as Needed   }
  44.          del                      : real;
  45.          order                    : integer; { Filter Order                  }
  46.          wp                       : real; { Ripple Frequency in Iterration   }
  47.          wp_new                   : real; { Newly Solved for Ripple Freq     }
  48.          Flag1                    : boolean; { Determines if Delta-dB < 0    }
  49.          ord_lo,ord_hi            : integer; { Lower, Up                     }
  50.          No,Num_lo,Num_hi         : integer; { Freq of Minimum Attenuation   }
  51.          min                      : real; { Minimum Attenuation in StopBand  }
  52.          wp_new_1,wp_new_2        : real; { New wp Frequencies               }
  53.          wo_geom                  : real; { Geometric Center Frequency       }
  54.          temp                     : real; { Temporary Holding Variable       }
  55.          stat                     : real; { Aborts Loop Upon Convergence     }
  56.          wp_lo_save,wp_hi_save    : real; { wp's From Previous Iteration     }
  57.          freq_margin              : real; { Percentage Error Allowed in Calc }
  58.                                           { When Exceeded, Leaves Loop       }
  59.          stat_ptr                 : string[1]; { Printer Status              }
  60.          IL                       : real; { Center of Band Insertion Loss }
  61.          Qu                       : real; { Unloaded Resonator Q }
  62.          inkey                    :char;
  63.  
  64.  
  65. Function Log10( X:Real ):Real;
  66. begin
  67.      Log10:=0.434294482*Ln( X );
  68. end;
  69. {///////////////////////////////////////////////}
  70.  
  71. Function Cosh( X:Real ):Real;
  72. var temp : Real;
  73. begin
  74.      temp:=exp( X );
  75.      Cosh:= 0.5 * ( temp  + 1/temp  );
  76. end;
  77. {///////////////////////////////////////////////}
  78.  
  79. Function Sinh( X: real): real;
  80. var  temp: real;
  81. begin
  82.     temp:= exp(X);
  83.     Sinh:= 0.5*(temp - 1/temp );
  84. end;
  85. { ////////////////////////////////////////////// }
  86.  
  87. Function Tanh( X: real): real;
  88. begin
  89.     Tanh:= Sinh(X)/Cosh(X);
  90. end;
  91. { ////////////////////////////////////////////// }
  92.  
  93. Function XtoY( X,Y:Real ):Real;
  94. begin
  95.      XtoY:= exp( Y * Ln( X )  );
  96. end;
  97. {///////////////////////////////////////////////}
  98.  
  99. Function ArcCosh( X:Real ):Real;
  100. begin
  101. ArcCosh:= Ln( X + sqrt( sqr(X) - 1 )  );
  102. end;
  103. {////////////////////////////////////////////////}
  104.  
  105. Procedure Iterate_Freq_1( wp:real;  No: integer); { Calculation of Iterated }
  106.     { wp_lo for the Lower StopBand; Next Iterate High StopBand with Next R  }
  107.  
  108.     var  wp_1,wp_2,wp_3      : real; { Frequency Variables in Linear Interpol }
  109.          L1,L2,L3            : real; { Losses at Frequency Variables Above    }
  110.          error               : real; { Differences in Frequencies }
  111.          del                 : real; { Attenuation in Loss Function }
  112.          Timer               : integer; { Aborts if No Convergence  }
  113.  
  114.     Label 10;
  115.  
  116.     Function Loss(  wp: real;  No: integer ): real;
  117.  
  118.                 { wp is Ripple Freq in Use }
  119.  
  120.          var  temp: real;
  121.  
  122.          begin
  123.          temp:= abs(wo_geom/(wp_hi-wp)*(wo_geom/Freq[No] - Freq[No]/wo_geom));
  124.          del:= 10.0*Log10(1+sqr(eta*Cosh(order*ArcCosh(temp)))) - Att[No];
  125.          Loss:= del;
  126.          end;
  127.  
  128.     begin
  129.     del:= 1;
  130.     wo_geom:= sqrt(wp*wp_hi);    { Calculate Geometric Center Frequency }
  131.     L1:= Loss(wp,No);       { Loss at wp_lo = dB Ripple }
  132.     wp_1:= wp;
  133.     wp_2:=  0.5*(wp + Freq[No]);{ Select Another Frequency Which Contains Zero }
  134.     wo_geom:= sqrt(wp_2*wp_hi); { Recalculate Geometric Center                 }
  135.     L2:= Loss(wp_2,No);
  136.     Timer:= 1;
  137.     while abs(del) > 0.01 do
  138.          begin
  139.          if Timer >= 10 then goto 10;
  140.          wp_3:= (L1*wp_2 - L2*wp_1)/(L1-L2);
  141.          wo_geom:= sqrt(wp_3*wp_hi);   { Must Recalculate Geometric Center }
  142.          L3:= Loss(wp_3,No);
  143.          if L1*L3 > 0.0 then
  144.               begin
  145.               L1:= L3;
  146.               wp_1:= wp_3;
  147.               if wp_1 > wp_lo_max then wp_1:= wp_lo_max;
  148.               end;
  149.          if L1*L3 <= 0.0 then
  150.               begin
  151.               L2:= L3;
  152.               wp_2:= wp_3;
  153.               if wp_2 > wp_lo_max then wp_2:= wp_lo_max;
  154.               end;
  155.          Timer:= Timer + 1;
  156.          end;
  157. 10: wp_new:= wp_3;     { New Lower Ripple Frequency }
  158.     if (del < 0.01) and ( Timer = 1 ) then wp_new:= wp_2; { In Case wp_2 is }
  159. end;                                                      { Right On        }
  160.  
  161. { ================================================================== }
  162.  
  163. Procedure Iterate_Freq_2( wp: real;  No: integer);  { For Upper StopBand }
  164.     var  wp_1,wp_2,wp_3      : real; { Frequency Variables in Linear Interpol }
  165.          L1,L2,L3            : real; { Losses at Frequency Variables Above    }
  166.          error               : real; { Differences in Frequencies }
  167.          del                 : real; { Attenuation in Loss Function }
  168.          Timer               : integer; { Aborts if No Convergence  }
  169.  
  170.     label 10;
  171.  
  172.     Function Loss( wp: real;  No: integer ): real;
  173.          var  temp: real;
  174.  
  175.          begin
  176.          temp:= abs(wo_geom/(wp-wp_lo)*(wo_geom/Freq[No]-Freq[No]/wo_geom));
  177.          del:= 10.0*Log10(1+sqr(eta*Cosh(order*ArcCosh(temp)))) - Att[No];
  178.          Loss:= del;
  179.          end;
  180.  
  181.     begin
  182.     del:= 1;
  183.     wo_geom:= sqrt(wp_lo*wp);
  184.     L1:= Loss(wp,No);       { Loss at wp_hi = dB Ripple }
  185.     wp_1:= wp;
  186.     wp_2:=  0.5*(wp + Freq[No]);
  187.     wo_geom:= sqrt(wp_2*wp_lo);
  188.     L2:= Loss(wp_2,No);
  189.     Timer:= 1;
  190.     while abs(del) > 0.01 do
  191.          begin
  192.          if Timer >= 10 then goto 10;
  193.          wp_3:= (L1*wp_2 - L2*wp_1)/(L1-L2);
  194.          wo_geom:= sqrt(wp_3*wp_lo);
  195.          L3:= Loss(wp_3,No);
  196.          if L1*L3 > 0.0 then
  197.               begin
  198.               L1:= L3;
  199.               wp_1:= wp_3;
  200.               if wp_1 < wp_hi_min then wp_1:= wp_hi_min;
  201.               end;
  202.          if L1*L3 <= 0.0 then
  203.               begin
  204.               L2:= L3;
  205.               wp_2:= wp_3;
  206.               if wp_2 < wp_hi_min then wp_2:= wp_hi_min;
  207.               end;
  208.          Timer:= Timer + 1;
  209.          end;
  210. 10: wp_new:= wp_3;
  211.     if ( del < 0.01) and ( Timer = 1 ) then wp_new:= wp_2;
  212.     end;
  213.  
  214. { ================================================================== }
  215.  
  216. procedure Inser_Loss( var order:integer; Am_dB:real);
  217.  
  218. type matrix        = array[0..20] of real;
  219.  
  220. var  W             : real; { Fractional Bandwidth }
  221.      wo            : real; { Geometric Center Frequency }
  222.      a,b           : matrix; { Array Holding Values - Matthaei 4.05-02 }
  223.      g             : matrix; { Elemental Values }
  224.      Beta          : real;
  225.      gamma         : real;
  226.      gamma2        : real;
  227.      k             : integer; { Loop Counter }
  228.      Sum           : real;
  229.  
  230. begin
  231. W:= (wp_hi-wp_lo)/wo_geom;
  232. Beta:= Ln(1/Tanh( Am_dB/17.37));
  233. gamma:= sinh(beta/(2*order));    { Eq 4.05-02 Matthaei }
  234. gamma2:= sqr(gamma);
  235. for k:= 1 to order do
  236.     begin
  237.          a[k]:= sin((2*k-1)*Pi/(2*order));
  238.          b[k]:= gamma2 + sqr(sin(k*Pi/order));
  239.     end;
  240. g[0]:= 1.0;
  241. g[1]:= 2*a[1]/gamma;
  242. for k:= 2 to order do
  243.     begin
  244.          g[k]:= 4*a[k-1]*a[k]/(b[k-1]*g[k-1]);
  245.     end;
  246. if ( order mod 2 = 1 ) then
  247.     g[order + 1]:= 1.0
  248.     else
  249.     g[order + 1]:= sqr(1.0/tanh(0.25*Beta));
  250. sum:= 0.0;
  251. for k:= 1 to order + 1 do
  252.     begin
  253.     sum:= sum + g[k];
  254.     end;
  255. IL:= 4.343*sum*4*g[0]*g[order+1]/(W*Qu*sqr(g[0]+g[order+1]));
  256. end;
  257.  
  258. { ================================================================== }
  259.  
  260.  
  261.  
  262. procedure maxi;
  263. var IO_Error : integer;
  264.  
  265. begin
  266. clrscr;
  267. gotoXY(1,8);
  268. writeln;
  269. writeln('                 P A S S     B A N D     M A X I M I Z E R');
  270. writeln('                               Version 2.0.2              ');
  271. writeln('                           Jeff Crawford    TRW  ');
  272. delay(1000);
  273. clrscr;
  274. gotoXY(10,10);
  275. write('Enter Minimum  f-low  and  Maximum  f-high in MHz ');
  276. {$I-}
  277. repeat
  278. IO_Error:=0;
  279. readln(wp_lo_max,wp_hi_min);
  280. IO_Error:=IOResult;
  281. if IO_Error <>0 then writeln ('Error; please re-enter data correctly.');
  282. until IO_Error=0;
  283. {$I+}
  284. wp_lo:= wp_lo_max;
  285. wp_hi:= wp_hi_min;
  286. write('         ');
  287. write('Enter dB Ripple in Passband  &  % Freq Error  ');
  288. {$I-}
  289. repeat
  290. IO_Error:=0;
  291. readln(L_db,Freq_margin);
  292. IO_Error:=IOResult;
  293. if IO_Error <>0 then writeln ('Error; please re-enter data correctly.');
  294. until IO_Error=0;
  295. {$I+}
  296. write('         ');
  297. write('Enter Approx Resonator Unloaded  Q  ');
  298. {$I-}
  299. repeat
  300. IO_Error:=0;
  301. readln(Qu);
  302. IO_Error:=IOResult;
  303. if IO_Error <>0 then writeln ('Error; please re-enter data correctly.');
  304. until IO_Error=0;
  305. {$I+}
  306. freq_margin:= freq_margin*0.01;
  307. eta:= sqrt(XtoY(10.0,0.1*L_db)-1.0);
  308. write('         ');
  309. write('Enter Number of Lower Stop-Band Freq Requirements  ');
  310. {$I-}
  311. repeat
  312. IO_Error:=0;
  313. readln(N_lo);
  314. IO_Error:=IOResult;
  315. if IO_Error <>0 then writeln ('Error; please re-enter data correctly.');
  316. until IO_Error=0;
  317. {$I+}
  318. write('         ');
  319. write('Enter Number of Upper Stop-Band Freq Requirements  ');
  320. {$I-}
  321. repeat
  322. IO_Error:=0;
  323. readln(N_hi);
  324. IO_Error:=IOResult;
  325. if IO_Error <>0 then writeln ('Error; please re-enter data correctly.');
  326. until IO_Error=0;
  327. {$I+}
  328. write('         ');
  329. write('Enter Lower,  Upper  Bounds  on  Filter  Order ');
  330. {$I-}
  331. repeat
  332. IO_Error:=0;
  333. readln(ord_lo,ord_hi);
  334. IO_Error:=IOResult;
  335. if IO_Error <>0 then writeln ('Error; please re-enter data correctly.');
  336. until IO_Error=0;
  337. {$I+}
  338. order:= ord_lo;
  339. writeln;
  340. write('         ');
  341. write('Is a Hard Copy of Results Desired  Y/N  ?  ');
  342. readln(stat_ptr);
  343. stat_ptr:= upcase(stat_ptr);
  344. clrscr;
  345. writeln;
  346. writeln('          Enter Lower Stop-Band Freqs & Respective Attenuations  ');
  347. writeln;
  348. for i:= 1 to N_lo  do    { Input Stop-Band Attenuation Requirements }
  349.     begin
  350.     gotoXY(25,i+5);
  351.     write('[',i,'] = ');
  352.     {$I-}
  353.     repeat
  354.     IO_Error:=0;
  355.     readln(Freq[i],Att[i]);
  356.     IO_Error:=IOResult;
  357.     if IO_Error <>0 then writeln ('Error; please re-enter data correctly.');
  358.     until IO_Error=0;
  359.     {$I+}
  360.     end;
  361. clrscr;
  362. writeln;
  363. writeln('         Enter Upper Stop-Band Freqs & Respective Attenuations  ');
  364. writeln;
  365. for i:= 1 to N_hi do
  366.     begin
  367.     gotoXY(25,i+5);
  368.     write('[',i,'] = ');
  369.     {$I-}
  370.     repeat
  371.     IO_Error:=0;
  372.     readln(Freq[i+N_lo],Att[i+N_lo]);
  373.     IO_Error:=IOResult;
  374.     if IO_Error <>0 then writeln ('Error; please re-enter data correctly.');
  375.     until IO_Error=0;
  376.     {$I+}
  377.     end;
  378. clrscr;
  379. writeln;
  380. write('            Min wp = ',wp_lo_max:8:3,'   Max wp = ',wp_hi_min:8:3);
  381. writeln('   dB Ripple  = ',L_db:5:2);
  382. writeln('                              Resonator Qu = ',Qu:6:2);
  383. writeln;
  384. writeln('                      Stop-Band Attenuation Requirements ');
  385. writeln;
  386. write('               Frequency                         Attenuation ');
  387. writeln;
  388. for i:= 1 to N_lo + N_hi do
  389.     begin
  390.     write('           F',i,' ');
  391.     writeln(Freq[i]:10:3,' MHz . . . . . . . .. . . . ',Att[i]:5:2,' dB');
  392.     end;
  393. for i:= 1 to 2 do
  394.     begin
  395.     write('=============================================================');
  396.     writeln('=================');
  397.     end;
  398. writeln;
  399. write('Order     Low Fp     Up Fp     Loss dB ');
  400. for i:= 1 to N_lo+N_hi do
  401.     begin
  402.     write('    F',i,'    ');
  403.     end;
  404. writeln;
  405. writeln;
  406. if stat_ptr = 'Y' then
  407. begin
  408. writeln(LST);
  409. write(LST,'           Min wp = ',wp_lo_max:8:3,'   Max wp = ',wp_hi_min:8:3);
  410. writeln(LST,'   dB Ripple  = ',L_db:5:2);
  411. writeln(LST,'                              Resonator Qu = ',Qu:6:2);
  412. writeln(LST);
  413. writeln(LST,'                      Stop-Band Attenuation Requirements ');
  414. writeln(LST);
  415. write(LST,'               Frequency                         Attenuation ');
  416. writeln(LST);
  417. for i:= 1 to N_lo + N_hi do
  418.     begin
  419.     write(LST,'           F',i,' ');
  420.     writeln(LST,Freq[i]:10:3,' MHz . . . . . . . .. . . . ',Att[i]:5:2,' dB');
  421.     end;
  422. for i:= 1 to 2 do
  423.     begin
  424.     write(LST,'=============================================================');
  425.     writeln(LST,'=================');
  426.     end;
  427. writeln(LST);
  428. write(LST,'Order     Low Fp     Up Fp     Loss dB ');
  429. for i:= 1 to N_lo+N_hi do
  430.     begin
  431.     write(LST,'    F',i,'     ');
  432.     end;
  433. writeln(LST);
  434. writeln(LST);
  435. end;
  436. order:= ord_lo;
  437. while order <= ord_hi do   { For Order Selected }
  438.     begin
  439.     Flag1:= False;
  440.     del:= 1.0;
  441.     min:= 1.0E10;
  442.     wo_geom:= sqrt(wp_lo_max*wp_hi_min);
  443.     for i:= 1 to N_lo do     { If Margins First Time Through Are Negative }
  444.         begin                { Need A Higher Order Filter                 }
  445.         wp:= wo_geom/(wp_hi_min-wp_lo_max);
  446.         wp:= abs(wp*(wo_geom/Freq[i] - Freq[i]/wo_geom));
  447.         del:= 10.0*Log10( 1 + sqr(eta*Cosh(Order*Arccosh(wp))));
  448.         delta_dB[i]:= del - Att[i];
  449.         if delta_dB[i] < 0.0 then Flag1:= True;
  450.         if delta_dB[i] < min then
  451.               begin
  452.               min:= delta_dB[i];
  453.               Num_lo:= i;
  454.               end;
  455.         end;                { Flag1 Is Set if Any Negative Margins Appear }
  456.     del:= 1.0;
  457.     min:= 1.0E10;
  458.     for i:= 1 to N_hi do
  459.         begin
  460.         wp:= wo_geom/(wp_hi_min-wp_lo_max);
  461.         wp:= abs(wp*(wo_geom/Freq[i+N_lo]-Freq[i+N_lo]/wo_geom));
  462.         del:= 10.0*Log10( 1 + sqr(eta*Cosh(Order*Arccosh(wp))));
  463.         delta_dB[i+N_lo]:= del - Att[i+N_lo];
  464.         if delta_dB[i+N_lo] < 0.0 then Flag1:= True;
  465.         if delta_db[i+N_lo] < min then
  466.               begin
  467.               min:= delta_dB[i+N_lo];
  468.               Num_hi:= i+N_lo;
  469.               end;
  470.         end;
  471.     if Flag1 = True then  { Output Best Possible Performance For Neg Margin }
  472.         begin
  473.         write('',order:2,'                                    ');
  474.         for i:= 1 to N_lo+N_hi do
  475.              begin
  476.              write(Delta_dB[i]+Att[i]:8:3,'   ');
  477.              end;
  478.         writeln;
  479.         if stat_ptr = 'Y' then
  480.         begin
  481.         write(LST,'',order:2,'                                    ');
  482.         for i:= 1 to N_lo+N_hi do
  483.              begin
  484.              write(LST,Delta_dB[i]+Att[i]:8:3,'   ');
  485.              end;
  486.         writeln(LST);
  487.         end;
  488.         end;
  489.     if (Flag1 = False) then    { When Filter Order is High Enough, Optimize }
  490.          begin                 { Ripple BandWidths for Best Passband Width  }
  491.          wo_geom:= sqrt(wp_lo*wp_hi);
  492.          stat:= 1.0E10;
  493.          while stat > freq_margin do
  494.               begin
  495.               wp_lo_save:= wp_lo;
  496.               wp_hi_save:= wp_hi;
  497.               Iterate_Freq_1(wp_lo,Num_lo);     { Find New Lower wp }
  498.               wp_lo:= wp_new;
  499.               del:= 1.0;
  500.               min:= 1.0E10;
  501.               wo_geom:= sqrt(wp_lo*wp_hi);
  502.               for i:= 1 to N_hi do { Find Upper StopBand Freq With Least Margin}
  503.                    begin
  504.                    wp:= wo_geom/(wp_hi-wp_lo);
  505.                    wp:= abs(wp*(wo_geom/Freq[i+N_lo] - Freq[i+N_lo]/wo_geom));
  506.                    del:= 10.0*Log10( 1 + sqr(eta*Cosh(Order*Arccosh(wp))));
  507.                    delta_dB[i+N_lo]:= del - Att[i+N_lo];
  508.                    if delta_dB[i+N_lo] < min then
  509.                         begin
  510.                         min:= delta_dB[i+N_lo];
  511.                         Num_hi:= i+N_lo;
  512.                         end;
  513.                    end;
  514.               Iterate_Freq_2(wp_hi,Num_hi);        { Calculate New Upper wp }
  515.               wp_hi:= wp_new;
  516.               del:= 1.0;
  517.               min:= 1.0E10;
  518.               wo_geom:= sqrt(wp_lo*wp_hi);
  519.               for i:= 1 to N_lo do { Evaluate Which Lower Freq Has Min Margin }
  520.                    begin
  521.                    wp:= wo_geom/(wp_hi-wp_lo);
  522.                    wp:= abs(wp*(wo_geom/Freq[i]-Freq[i]/wo_geom));
  523.                    del:= 10.0*Log10( 1 + sqr(eta*Cosh(Order*Arccosh(wp))));
  524.                    delta_dB[i]:= del - Att[i];
  525.                    if delta_db[i] < min then
  526.                         begin
  527.                         min:= delta_dB[i];
  528.                         Num_lo:= i;
  529.                         end;
  530.                    end;
  531.               stat:=(abs(wp_lo-wp_lo_save)+abs(wp_hi-wp_hi_save))/wo_geom;
  532.               wp_new_1:= wp_lo;
  533.               wp_new_2:= wp_hi;
  534.          end;
  535.          Inser_Loss(order,L_dB);
  536.          for i:= 1 to N_lo+N_hi do
  537.              begin
  538.              temp:= wo_geom/(wp_hi-wp_lo);
  539.              temp:= abs(temp*(wo_geom/Freq[i]-Freq[i]/wo_geom));
  540.              del:= 10.0*Log10( 1 + sqr(eta*Cosh(Order*Arccosh(temp))));
  541.              delta_dB[i]:= del - Att[i];
  542.              end;
  543.          write('',order:2,'      ',wp_new_1:8:3,'    ',wp_new_2:8:3,'');
  544.          write(IL:8:3,'  ');
  545.          for i:= 1 to N_lo+N_hi do
  546.              begin
  547.              write(Delta_dB[i]+Att[i]:8:3,'   ');
  548.              end;
  549.          writeln;
  550.          if stat_ptr = 'Y' then
  551.               begin
  552.               write(LST,'',order:2,'      ',wp_new_1:8:3,'    ',wp_new_2:8:3,'');
  553.               write(LST,IL:8:3,'  ');
  554.               for i:= 1 to N_lo+N_hi do
  555.                   begin
  556.                   write(LST,Delta_dB[i]+Att[i]:8:3,'   ');
  557.              end;
  558.              writeln(LST);
  559.              end;
  560.          end;
  561.     wp_lo:= wp_lo_max;
  562.     wp_hi:= wp_hi_min;
  563.     Flag1:= False;
  564.     order:= order + 1;
  565.     end;
  566.     write('                                                  ');
  567.     writeln('       CR to Continue');
  568.     readln(wp_lo);
  569. end;{end maxi}
  570.  
  571.  
  572. var ink : boolean;
  573.  
  574. begin  {main}
  575.        repeat
  576.           ink:=false;
  577.           maxi;
  578.           writeln(' To rerun the program, type R ');
  579.           read (inkey);
  580.           if inkey='r' then ink:=true;
  581.           if inkey='R' then ink:=true;
  582.        until not ink;
  583. end.
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.