//**************************************************************************
// JavaScript for act_hpfil.html
//**************************************************************************


//**************************************************************************
// Global Variables and Arrays.
//**************************************************************************


var R1_Init, R2_Init, R3_Init, R4_Init, R5_Init, C1_C2;
var R1_Std, R2_Std, R3_Std;
var RA_Std, RB_Std, RC_Prec, R_Delta;
var R1_A, R1_B, R2_A, R2_B, R3_A, R3_B;
var R1_Prec, R2_Prec, R3_Prec, R1_Delta, R2_Delta, R3_Delta;


//**************************************************************************
// Arrays for calculating multiple resistor combinations.
//**************************************************************************


Sel_Array = new Array("LT","GT");
R1_Val = new Array();
R2_Val = new Array();
R3_Val = new Array();
R4_Val = new Array();
R5_Val = new Array();
R1A_Val = new Array();
R2A_Val = new Array();
R3A_Val = new Array();
R4A_Val = new Array();
R5A_Val = new Array();
R1B_Val = new Array();
R2B_Val = new Array();
R3B_Val = new Array();
R4B_Val = new Array();
R5B_Val = new Array();
K_Val  = new Array();
K1_Val  = new Array();
K2_Val  = new Array();
KA_Val  = new Array();
KB_Val  = new Array();
W0_Val = new Array();
WC_Val = new Array();
WCA_Val = new Array();
WCB_Val = new Array();
Q_Val  = new Array();
F0_Val = new Array();
F0A_Val = new Array();
F0B_Val = new Array();
BW_Val = new Array();


//**************************************************************************
// These functions flip the checkbox when deciding which pieces of data
// to use as input. Only one checkbox is allowed to be selected at any time.
//**************************************************************************


function Set_F0_or_Q_Checkbox() {
   document.BP_Fil_Design.F0_or_Q.checked = 1;
   document.BP_Fil_Design.FMin_or_FMax.checked = 0;
   document.BP_Fil_Design.F0_or_BW.checked = 0;
}



function Set_FMin_or_FMax_Checkbox() {
   document.BP_Fil_Design.F0_or_Q.checked = 0;
   document.BP_Fil_Design.FMin_or_FMax.checked = 1;
   document.BP_Fil_Design.F0_or_BW.checked = 0;
}


function Set_F0_or_BW_Checkbox() {
   document.BP_Fil_Design.F0_or_Q.checked = 0;
   document.BP_Fil_Design.FMin_or_FMax.checked = 0;
   document.BP_Fil_Design.F0_or_BW.checked = 1;
}


//**************************************************************************
//  Band Pass Filter Design
//**************************************************************************


function BP_Fil_Calc() {


   Input_Spec = "";


   //***********************************************************************
   // Get the Filter type, Order, and Response Characteristics.

   //***********************************************************************


   if (document.BP_Fil_Design.Fil_Type.options[0].selected) Fil_Type = "MFB";
   else Fil_Type = "VCVS";


   //***********************************************************************
   // Get the Gain value, K, specified.
   //***********************************************************************


   K_Value = parseFloat(document.BP_Fil_Design.K_Value.value);


   //***********************************************************************
   // Decide whether the specified Q and F0 are used to calculate
   // Fmin and Fmax (Bandwidth), or, Fmin and Fmax are used to calculate
   // Q and F0.
   //***********************************************************************



   if ( document.BP_Fil_Design.F0_or_Q.checked ) {


      Input_Spec = "F0_and_Q";


      //********************************************************************
      // Get the Center Frequency and Q and calculate Fmin and Fmax.
      //********************************************************************


      F_0 = parseFloat(document.BP_Fil_Design.F_0A.value);
      Q_Value = parseFloat(document.BP_Fil_Design.Q_Value.value);
      BP_FIL_BW = F_0 / Q_Value;
      F_Min = F_0 - BP_FIL_BW/2;
      F_Max = F_0 + BP_FIL_BW/2;


      document.BP_Fil_Design.F_Max.value = Rnd(F_Max,1);
      document.BP_Fil_Design.F_Min.value = Rnd(F_Min,1);
      document.BP_Fil_Design.F_0B.value = Rnd(F_0,1);
      document.BP_Fil_Design.BW_Value.value = Rnd(BP_FIL_BW,1); }
   else if ( document.BP_Fil_Design.FMin_or_FMax.checked ) {


      Input_Spec = "Fmin_and_Fmax";


      //********************************************************************
      // Get Fmin and Fmax and calculate the Center Frequency and Q.
      //********************************************************************


      F_Min = parseFloat(document.BP_Fil_Design.F_Min.value);
      F_Max = parseFloat(document.BP_Fil_Design.F_Max.value);
      F_0 = F_Min + ((F_Max-F_Min)/2);
      BP_FIL_BW = F_Max - F_Min;
      Q_Value = F_0 / BP_FIL_BW;


      document.BP_Fil_Design.F_0A.value = Rnd(F_0,1);
      document.BP_Fil_Design.F_0B.value = Rnd(F_0,1);
      document.BP_Fil_Design.Q_Value.value = Rnd(Q_Value,3);
      document.BP_Fil_Design.BW_Value.value = Rnd(BP_FIL_BW,1); }
   else {


      Input_Spec = "F0_and_BW";


      //********************************************************************
      // Get Center Frequency and Band Width and calculate Fmax, Fnin, and Q.
      //********************************************************************


      F_0 = parseFloat(document.BP_Fil_Design.F_0B.value);
      BP_FIL_BW = parseFloat(document.BP_Fil_Design.BW_Value.value);
      Q_Value = F_0 / BP_FIL_BW;
      F_Min = F_0 - BP_FIL_BW/2;
      F_Max = F_0 + BP_FIL_BW/2;


      document.BP_Fil_Design.F_0A.value = Rnd(F_0,1);
      document.BP_Fil_Design.Q_Value.value = Rnd(Q_Value,3);
      document.BP_Fil_Design.F_Max.value = Rnd(F_Max,1);
      document.BP_Fil_Design.F_Min.value = Rnd(F_Min,1); }


   //***********************************************************************
   // Set in the estimate for C1 and C2 for a Stage 1 filter. Then get the
   // user entered capacitor values.
   //***********************************************************************


   if ( F_0 >= 20 && F_0 < 80 ) C1_Est = .33;
   else if (  F_0 >= 80 && F_0 < 300 ) C1_Est = .082;
   else if (  F_0 >= 300 && F_0 < 1200 ) C1_Est = .022;
   else if (  F_0 >= 1200 && F_0 < 4800 ) C1_Est = .0056;
   else if (  F_0 >= 4800 && F_0 < 20000 ) C1_Est = .0015;


   document.getElementById("Freq_Center").innerHTML = Rnd(F_0,2) + " Hz";
   document.getElementById("Cap_Estimate").innerHTML = Rnd(C1_Est,3) + " uF";


   if (document.BP_Fil_Design.C1_Unit.options[0].selected) {
      C1_Unit = 1000000; }
   else {
      C1_Unit = 1000000000000; }
   C1_Init = document.BP_Fil_Design.C1_Init.value / C1_Unit;


   C2_Init = C1_Init;


   //***********************************************************************
   // Set the estimated maximum value for C1 and then get the user entered
   // value.
   //***********************************************************************


   BW_Value = F_0/Q_Value;
   BW_2 = BW_Value/2;


   F_Min = F_0 - BW_2;
   F_Max = F_0 + BW_2;


   document.getElementById("F_Type").innerHTML = Fil_Type;


   document.getElementById("F0").innerHTML = "F<sub>0</sub> = " + Rnd(F_0,2) + " Hz";
   document.getElementById("Q").innerHTML = "Q = " + Rnd(Q_Value,2);
   document.getElementById("F_Min").innerHTML = "F<sub>Min</sub> = " + Rnd(F_Min,2) + " Hz";
   document.getElementById("F_Max").innerHTML = "F<sub>Max</sub> = " + Rnd(F_Max,2) + " Hz";
   document.getElementById("BW").innerHTML = "Bandwidth = " + Rnd(BW_Value,2) + " Hz";
   document.getElementById("Gain").innerHTML = "Stage Gain (K) = " + K_Value;


   W_0 = 2 * Math.PI * F_0;


   //***********************************************************************
   // Second-Order MFB Filter.
   //***********************************************************************


   if ( Fil_Type == "MFB" ) {
      //********************************************************************
      // Calculate the component values for a Second-Order MFB Filter.
      //********************************************************************


      X = C1_Init * (Math.pow(Q_Value,2) - K_Value);
      Y = C2_Init * Math.pow(Q_Value,2);


      R1_Init = Q_Value / ( C1_Init * W_0 * K_Value);
      R2_Init = Q_Value / ( W_0 * (X + Y));
      R3_Init = (Q_Value / W_0) * (1/C1_Init + 1/C2_Init);


      document.getElementById("F_C1").innerHTML = "C<sub>1</sub> = " + C_Scale(C1_Init);
      document.getElementById("F_C2").innerHTML = "C<sub>2</sub> = " + C_Scale(C2_Init);
      document.getElementById("F_R1").innerHTML = "R<sub>1</sub> = " + comma_ins(Math.round(R1_Init)) + " Ohms";
      document.getElementById("F_R2").innerHTML = "R<sub>2</sub> = " + comma_ins(Math.round(R2_Init)) + " Ohms";
      document.getElementById("F_R3").innerHTML = "R<sub>3</sub> = " + comma_ins(Math.round(R3_Init)) + " Ohms";
      document.getElementById("F_R4").innerHTML = "";
      document.getElementById("F_R5").innerHTML = "";


      } // End - if ( Fil_Type == "MFB" )
   else {
      //********************************************************************
      // Calculate the component values for a Second-Order VCVS Filter.
      //********************************************************************


      X = 2 * Q_Value;
      Y = Math.pow(K_Value-1,2) + ( 8 * Math.pow(Q_Value,2));
      Z = C1_Init * W_0;


      R1_Init = X / ( Z * K_Value);
      R2_Init = X / ( Z * ( -1 + Math.sqrt(Y) ) );
      R3_Init = (1/Math.pow(Z,2)) * ((1/R1_Init) + (1/R2_Init));
      R4_Init = 2 * R3_Init;
      R5_Init = 2 * R3_Init;


      document.getElementById("F_C1").innerHTML = "C<sub>1</sub> = " + C_Scale(C1_Init);
      document.getElementById("F_C2").innerHTML = "C<sub>2</sub> = " + C_Scale(C1_Init);
      document.getElementById("F_R1").innerHTML = "R<sub>1</sub> = " + comma_ins(Math.round(R1_Init)) + " Ohms";
      document.getElementById("F_R2").innerHTML = "R<sub>2</sub> = " + comma_ins(Math.round(R2_Init)) + " Ohms";
      document.getElementById("F_R3").innerHTML = "R<sub>3</sub> = " + comma_ins(Math.round(R3_Init)) + " Ohms";
      document.getElementById("F_R4").innerHTML = "R<sub>4</sub> = " + comma_ins(Math.round(R4_Init)) + " Ohms";
      document.getElementById("F_R5").innerHTML = "R<sub>5</sub> = " + comma_ins(Math.round(R5_Init)) + " Ohms";
      } // End - else (Fil_Type == VCVS )


   //***********************************************************************
   // Choice 1 - Select standard resistor values and calculate new filter
   // parameters.

   //***********************************************************************


   if (document.BP_Fil_Design.Res_Tol.options[0].selected) Res_Tol = "05";
   else Res_Tol = "10";


   Standard_R_Table = "<table align=center border=\"2\" bgcolor=\"#aaffaa\" bordercolor=\"#008b00\" cellpadding=\"5\" cellspacing=\"0\">\n";
   Standard_R_Table += "<TR>";
   Standard_R_Table += "<TD colspan=8><P class=std_10_bold align=center><BR>Standard Resistor Options ";
   Standard_R_Table += "for a Second-Order " + Fil_Type + " Band-Pass Active Filter.<BR><BR>"


   if ( Input_Spec == "F0_and_Q" ) {
      Standard_R_Table += "<blockquote><P class=std_10 align=justify>A <B>Center Frequency</B> (F<sub>0</sub>) of <B>" + Rnd(F_0,2) + " Hz</B> and ";
      Standard_R_Table += "a <B>Q</B> of <B>" + Rnd(Q_Value,2) + "</B> has been specified. ";
      Standard_R_Table += "This defines a <B>Bandwidth</B> (BW) of <B>" + Rnd(BW_Value,2) + " Hz</B> and sets ";
      Standard_R_Table += "<B>F<sub>Min</sub></B> to <B>" + Rnd(F_Min,2) + " Hz</B> ";
      Standard_R_Table += "and <B>F<sub>Max</sub></B> to <B>" + Rnd(F_Max,2) + " Hz</B>. "
      }
   else if ( Input_Spec == "Fmin_and_Fmax" ) {
      Standard_R_Table += "With F<sub>Min</sub> defined as " + Rnd(F_Min,2) + " Hz ";
      Standard_R_Table += "and F<sub>Max</sub> defined as " + Rnd(F_Max,2) + " Hz, the Bandwidth<BR>"
      Standard_R_Table += "(BW) is calculated as " + Rnd(BW_Value,2) + " Hz, the Center Frequency ";
      Standard_R_Table += "(F<sub>0</sub>) is calculated as<BR>" + Rnd(F_0,2) + " Hz, and ";
      Standard_R_Table += "the Q is calculated as " + Rnd(Q_Value,3) + ".<BR>";
      }
   else if ( Input_Spec == "F0_and_BW" ) {
      Standard_R_Table += "A Center Frequency (F<sub>0</sub>) of " + Rnd(F_0,2) + " Hz and<BR>";
      Standard_R_Table += "a Bandwidth (BW) of " + Rnd(BW_Value,2) + " has been specified.<br>";
      Standard_R_Table += "This sets F<sub>Min</sub> to " + Rnd(F_Min,2) + " Hz ";
      Standard_R_Table += "and F<sub>Max</sub> to " + Rnd(F_Max,2) + " Hz.<br>"
      Standard_R_Table += "The Q is calculated as " + Rnd(Q_Value,3) + ". ";
      }


   Standard_R_Table += "Intended <B>Stage Gain</B> (K) is <B>" + K_Value + "</B>.</blockquote>";


   TR = "<TR>\n"
   TD = "<TD><P class=std_10_bold align=center>"


   Standard_R_Table += TR + "\n" + TD + "Fil #\n";
   Standard_R_Table += TD + "Center<BR>Frequency\n";
   Standard_R_Table += TD + "Filter Q\n";
   Standard_R_Table += TD + "Gain K\n";
   Standard_R_Table += TD + "Bandwidth\n";
   Standard_R_Table += TD + "R<sub>1</sub>\n";
   Standard_R_Table += TD + "R<sub>2</sub>\n";
   Standard_R_Table += TD + "R<sub>3</sub>\n";


   BP_Fil_Calc_2_Data = "You have chosen " + C_Scale(C1_Init) + " for C1 and C2,\n";


   //***********************************************************************
   // Calculate filter properties for all of the possible resistor combinations.
   //***********************************************************************


   if ( Fil_Type == "MFB" ) {


      for ( I = 0; I < 2; I++ ) {
         for ( J = 0; J < 2; J++ ) {
            for ( K = 0; K < 2; K++ ) {
               L = I*4 + J*2 + K*1;
               R1_Val[L] = Get_Std_Res( R1_Init, Sel_Array[I], Res_Tol );
               R2_Val[L] = Get_Std_Res( R2_Init, Sel_Array[J], Res_Tol );
               R3_Val[L] = Get_Std_Res( R3_Init, Sel_Array[K], Res_Tol );


               K_Val[L] = MFB_K( R3_Val[L], R1_Val[L] );
               W0_Val[L] = MFB_W0( R1_Val[L], R2_Val[L], K_Val[L], C1_Init );
               Q_Val[L] = MFB_Q( R3_Val[L], W0_Val[L], C1_Init );
               F0_Val[L] = MFB_F0( W0_Val[L] );
               BW_Val[L] = MFB_BW( F0_Val[L], Q_Val[L] ); } } }


      //********************************************************************
      // Simple bubble sort based on frequency, highest to lowest.
      //********************************************************************


      for ( I = 0; I < 8; I++ ) {
         for ( J = 0; J < 7; J++ ) {
            if ( F0_Val[J] < F0_Val[J+1] ) {
               F0_Val_Tmp = F0_Val[J]; F0_Val[J] = F0_Val[J+1]; F0_Val[J+1] = F0_Val_Tmp;
               BW_Val_Tmp = BW_Val[J]; BW_Val[J] = BW_Val[J+1]; BW_Val[J+1] = BW_Val_Tmp;
               Q_Val_Tmp = Q_Val[J]; Q_Val[J] = Q_Val[J+1]; Q_Val[J+1] = Q_Val_Tmp;
               W0_Val_Tmp = W0_Val[J]; W0_Val[J] = W0_Val[J+1]; W0_Val[J+1] = W0_Val_Tmp;
               K_Val_Tmp = K_Val[J]; K_Val[J] = K_Val[J+1]; K_Val[J+1] = K_Val_Tmp;
               R1_Val_Tmp = R1_Val[J]; R1_Val[J] = R1_Val[J+1]; R1_Val[J+1] = R1_Val_Tmp;
               R2_Val_Tmp = R2_Val[J]; R2_Val[J] = R2_Val[J+1]; R2_Val[J+1] = R2_Val_Tmp;
               R3_Val_Tmp = R3_Val[J]; R3_Val[J] = R3_Val[J+1]; R3_Val[J+1] = R3_Val_Tmp; } } }


      //********************************************************************
      //
      //********************************************************************


      for ( I = 0; I < 8; I++ ) {
         Standard_R_Table += TR + "\n" + TD + (I+1) + "\n";
         Standard_R_Table += TD + Rnd(F0_Val[I],1) + " Hz\n";
         Standard_R_Table += TD + Rnd(Q_Val[I],2) + "\n";
         Standard_R_Table += TD + Rnd(K_Val[I],2) + "\n";
         Standard_R_Table += TD + comma_ins(Math.round(BW_Val[I])) + " Hz\n";
         Standard_R_Table += TD + comma_ins(Math.round(R1_Val[I])) + " Ohms\n";
         Standard_R_Table += TD + comma_ins(Math.round(R2_Val[I])) + " Ohms\n";
         Standard_R_Table += TD + comma_ins(Math.round(R3_Val[I])) + " Ohms\n";
         }


      Standard_R_Table += "            </table>\n";
      document.getElementById("Std_R_Table").innerHTML = Standard_R_Table;


      } // End - if ( Fil_Type == "MFB" )
   else {
      for ( H = 0; H < 2; H++ ) {
         for ( I = 0; I < 2; I++ ) {
            for ( J = 0; J < 2; J++ ) {
               for ( K = 0; K < 2; K++ ) {
                  L = H*8 + I*4 + J*2 + K*1;
                  R1_Val[L] = Get_Std_Res( R1_Init, Sel_Array[H], Res_Tol );
                  R2_Val[L] = Get_Std_Res( R2_Init, Sel_Array[I], Res_Tol );
                  R3_Val[L] = Get_Std_Res( R3_Init, Sel_Array[J], Res_Tol );
                  R4_Val[L] = Get_Std_Res( R4_Init, Sel_Array[K], Res_Tol );
                  R5_Val[L] = R4_Val[L];


                  W0_Val[L] = VCVS_W0( R1_Val[L], R2_Val[L], R3_Val[L], C1_Init );
                  F0_Val[L] = VCVS_F0( W0_Val[L] );


                  //********************************************************
                  // To find K and Q itterate through various values of
                  // K and calculate Q for each of the resistor sets. We
                  // do this by first assuming a K and then calculate a
                  // Q using the formula for R1. We then use the K and Q
                  // to calculate a R2 test value and compare it with
                  // the chosed R2. We itterate until the test R2 is near
                  // the chosen R2.
                  //********************************************************


                  for ( Test_K = 0.1; Test_K < 50; Test_K += 0.1 ) {
                     Test_K = parseFloat(Rnd(Test_K,1));
                     Test_Q = VCVS_Q ( R1_Val[L], C1_Init, W0_Val[L], Test_K )
                     Test_R2 = VCVS_R2( Test_Q, C1_Init, W0_Val[L], Test_K );
                     if ( Test_R2 < 0.0 ) continue;
                     if ( Test_R2 < R2_Val[L] ) break; }


                  K_Val[L] = Test_K; Q_Val[L] = Test_Q;
                  BW_Val[L] = VCVS_BW( F0_Val[L], Q_Val[L] ); } } } }


      //********************************************************************
      // Simple bubble sort based on frequency, highest to lowest.
      //********************************************************************


      for ( I = 0; I < 16; I++ ) {

         for ( J = 0; J < 15; J++ ) {
            if ( F0_Val[J] < F0_Val[J+1] ) {
               F0_Val_Tmp = F0_Val[J]; F0_Val[J] = F0_Val[J+1]; F0_Val[J+1] = F0_Val_Tmp;
               BW_Val_Tmp = BW_Val[J]; BW_Val[J] = BW_Val[J+1]; BW_Val[J+1] = BW_Val_Tmp;
               Q_Val_Tmp = Q_Val[J]; Q_Val[J] = Q_Val[J+1]; Q_Val[J+1] = Q_Val_Tmp;
               W0_Val_Tmp = W0_Val[J]; W0_Val[J] = W0_Val[J+1]; W0_Val[J+1] = W0_Val_Tmp;
               K_Val_Tmp = K_Val[J]; K_Val[J] = K_Val[J+1]; K_Val[J+1] = K_Val_Tmp;
               R1_Val_Tmp = R1_Val[J]; R1_Val[J] = R1_Val[J+1]; R1_Val[J+1] = R1_Val_Tmp;
               R2_Val_Tmp = R2_Val[J]; R2_Val[J] = R2_Val[J+1]; R2_Val[J+1] = R2_Val_Tmp;
               R3_Val_Tmp = R3_Val[J]; R3_Val[J] = R3_Val[J+1]; R3_Val[J+1] = R3_Val_Tmp;
               R4_Val_Tmp = R4_Val[J]; R4_Val[J] = R4_Val[J+1]; R4_Val[J+1] = R4_Val_Tmp;
               R5_Val_Tmp = R5_Val[J]; R5_Val[J] = R5_Val[J+1]; R5_Val[J+1] = R5_Val_Tmp; } } }


      //********************************************************************
      //
      //********************************************************************


      BP_Fil_Calc_2_Data += "\n\n";


      K = 1
      for ( I = 0; I < 16; I=I+2 ) {
         Standard_R_Table += TR + "\n" + TD + (K) + "\n";
         Standard_R_Table += TD + Rnd(F0_Val[I],1) + " Hz\n";
         Standard_R_Table += TD + Rnd(Q_Val[I],2) + "\n";
         Standard_R_Table += TD + Rnd(K_Val[I],2) + "\n";
         Standard_R_Table += TD + comma_ins(Math.round(BW_Val[I])) + " Hz\n";
         Standard_R_Table += TD + comma_ins(Math.round(R1_Val[I])) + " Ohms\n";
         Standard_R_Table += TD + comma_ins(Math.round(R2_Val[I])) + " Ohms\n";
         Standard_R_Table += TD + comma_ins(Math.round(R3_Val[I])) + " Ohms\n";


         K++;
         }


      Standard_R_Table += TR;
      Standard_R_Table += "<TD colspan=8><P class=std_10_bold align=center>";
      Standard_R_Table += "R4 and R5 are equal and can be " + comma_ins(Math.round(R4_Val[0])) + " Ohms ";
      Standard_R_Table += "or " + comma_ins(Math.round(R4_Val[1])) + " Ohms,\n";
      Standard_R_Table += "without affecting the other parameters.\n";


      Standard_R_Table += "            </table>\n";
      document.getElementById("Std_R_Table").innerHTML = Standard_R_Table;
      } // End - else (Fil_Type == VCVS )


   //***********************************************************************
   // Choice 2 - Calculate two standard resistors that, when wired in
   // parallel, will equal the initial design resistor values.
   //***********************************************************************


   if (document.BP_Fil_Design.Prec_Res_Tol.options[0].selected) Prec_Res_Tol = "05";
   else Prec_Res_Tol = "10";


   Custom_R_Table = "<table align=center border=\"2\" bgcolor=\"#aaffaa\" bordercolor=\"#008b00\" cellpadding=\"5\" cellspacing=\"0\">\n";
   Custom_R_Table += "<TR>";
   Custom_R_Table += "<TD colspan=6><P class=std_10_bold align=center><BR>Custom Resistor Options ";

   Custom_R_Table += "for a Second-Order " + Fil_Type + " Band-Pass Active Filter.<BR><BR>"


   Prec_Res_Calc( R1_Init, Prec_Res_Tol ); R1_A = RA_Std; R1_B = RB_Std; R1_Prec = RC_Prec; R1_Delta = R_Delta;
   Prec_Res_Calc( R2_Init, Prec_Res_Tol ); R2_A = RA_Std; R2_B = RB_Std; R2_Prec = RC_Prec; R2_Delta = R_Delta;
   Prec_Res_Calc( R3_Init, Prec_Res_Tol ); R3_A = RA_Std; R3_B = RB_Std; R3_Prec = RC_Prec; R3_Delta = R_Delta;


   if ( Fil_Type == "VCVS" ) {
      Prec_Res_Calc( R4_Init, Prec_Res_Tol ); R4_A = RA_Std; R4_B = RB_Std; R4_Prec = RC_Prec; R4_Delta = R_Delta;
      Prec_Res_Calc( R5_Init, Prec_Res_Tol ); R5_A = RA_Std; R5_B = RB_Std; R5_Prec = RC_Prec; R5_Delta = R_Delta;
      }


   //***********************************************************************
   // Reverse calculation from the precision resistors formed by two standard
   // resistors in parallel, for each resistor.
   //***********************************************************************


   if ( Fil_Type == "MFB" ) {
      RP_K_Value = MFB_K( R3_Prec, R1_Prec );
      RP_W0 = MFB_W0( R1_Prec, R2_Prec, RP_K_Value, C1_Init );
      RP_Q_Value = MFB_Q( R3_Prec, RP_W0, C1_Init );
      RP_F0 = MFB_F0( RP_W0 );
      RP_BW_Value = MFB_BW( RP_F0, RP_Q_Value ); }
   else {
      RP_W0 = VCVS_W0( R1_Prec, R2_Prec, R3_Prec, C1_Init );
      RP_F0 = VCVS_F0( RP_W0 );


      //********************************************************************
      // To find K and Q itterate through various values of
      // K and calculate Q for each of the resistor sets. We
      // do this by first assuming a K and then calculate a
      // Q using the formula for R1. We then use the K and Q
      // to calculate a R2 test value and compare it with
      // the chosed R2. We itterate until the test R2 is near
      // the chosen R2.
      //********************************************************************


      for ( Test_K = 0.1; Test_K < 50; Test_K += 0.1 ) {
         Test_K = parseFloat(Rnd(Test_K,1));
         Test_Q = VCVS_Q ( R1_Prec, C1_Init, RP_W0, Test_K )
         Test_R2 = VCVS_R2( Test_Q, C1_Init, RP_W0, Test_K );
         if ( Test_R2 < 0.0 ) continue;
         if ( Test_R2 < R2_Prec ) break; }


      RP_K_Value = Test_K; RP_Q_Value = Test_Q;
      RP_BW_Value = VCVS_BW( RP_F0, RP_Q_Value ); }


   Custom_R_Table += "<blockquote><P class=std_10 align=justify>For the parallel resistor combinations ";
   Custom_R_Table += "defined below, the <B>Center Frequency</B> (F<sub>0</sub>) is <B>" + Rnd(RP_F0,2) + " Hz</B> and ";
   Custom_R_Table += "<B>Q</B> is <B>" + Rnd(RP_Q_Value,2) + "</B>. ";
   Custom_R_Table += "The <B>Bandwidth</B> (BW) of <B>" + Rnd(RP_BW_Value,2) + " Hz</B> and sets ";
   Custom_R_Table += "<B>F<sub>Min</sub></B> to <B>" + Rnd(F_Min,2) + " Hz</B> ";
   Custom_R_Table += "and <B>F<sub>Max</sub></B> to <B>" + Rnd(F_Max,2) + " Hz</B>. "
   Custom_R_Table += "<B>Stage Gain</B> (K) is <B>" + Rnd(RP_K_Value,2) + "</B>.</blockquote>";


   Custom_R_Table += TR + "\n" + TD + "Resistor\n";
   Custom_R_Table += TD + "Intended<BR>Value\n";
   Custom_R_Table += "<TD colspan=2><P class=std_10_bold align=center>R<sub>A</sub> || R<sub>B</sub> Parallel Combination\n";
   Custom_R_Table += TD + "Actual<br>Value (R)\n";
   Custom_R_Table += TD + "Delta\n";


   //*****************************************************************
   // Setup the line for R1. The if statements increases the space for
   // numbers under 1,000,000.
   //*****************************************************************


   Custom_R_Table += TR + "\n" + TD + "R1\n";
   Custom_R_Table += TD + comma_ins(Math.round(R1_Init)) + "\n";
   Custom_R_Table += TD + R_Format(R1_A,1,"off") + "\n";
   Custom_R_Table += TD + R_Format(R1_B,1,"off") + "\n";
   Custom_R_Table += TD + comma_ins(Math.round(R1_Prec)) + "\n";
   Custom_R_Table += TD + Rnd(R1_Delta,2) + " %\n";


   Custom_R_Table += TR + "\n" + TD + "R2\n";
   Custom_R_Table += TD + comma_ins(Math.round(R2_Init)) + "\n";
   Custom_R_Table += TD + R_Format(R2_A,1,"off") + "\n";
   Custom_R_Table += TD + R_Format(R2_B,1,"off") + "\n";
   Custom_R_Table += TD + comma_ins(Math.round(R2_Prec)) + "\n";
   Custom_R_Table += TD + Rnd(R2_Delta,2) + " %\n";


   Custom_R_Table += TR + "\n" + TD + "R3\n";
   Custom_R_Table += TD + comma_ins(Math.round(R3_Init)) + "\n";
   Custom_R_Table += TD + R_Format(R3_A,1,"off") + "\n";
   Custom_R_Table += TD + R_Format(R3_B,1,"off") + "\n";
   Custom_R_Table += TD + comma_ins(Math.round(R3_Prec)) + "\n";
   Custom_R_Table += TD + Rnd(R3_Delta,2) + " %\n";


   if ( Fil_Type == "VCVS" ) {
      Custom_R_Table += TR + "\n" + TD + "R4\n";
      Custom_R_Table += TD + comma_ins(Math.round(R4_Init)) + "\n";
      Custom_R_Table += TD + R_Format(R4_A,1,"off") + "\n";
      Custom_R_Table += TD + R_Format(R4_B,1,"off") + "\n";
      Custom_R_Table += TD + comma_ins(Math.round(R4_Prec)) + "\n";
      Custom_R_Table += TD + Rnd(R4_Delta,2) + " %\n";


      Custom_R_Table += TR + "\n" + TD + "R5\n";
      Custom_R_Table += TD + comma_ins(Math.round(R5_Init)) + "\n";
      Custom_R_Table += TD + R_Format(R5_A,1,"off") + "\n";
      Custom_R_Table += TD + R_Format(R5_B,1,"off") + "\n";
      Custom_R_Table += TD + comma_ins(Math.round(R5_Prec)) + "\n";
      Custom_R_Table += TD + Rnd(R5_Delta,2) + " %\n";
      }


   //***********************************************************************
   // Change the number of rows in the text area based on how much data needs
   // to be displayed.
   //***********************************************************************


   Custom_R_Table += "            </table>\n";
   document.getElementById("Cust_R_Table").innerHTML = Custom_R_Table;
}


//**************************************************************************
// Foward functions to generate MFB BandPass Filter components.
//**************************************************************************


function MFB_R1( C1, W0, Q, K ) { return Q / ( C1 * W0 * K); }


function MFB_R2( C1, C2, W0, Q, K ) {
   X = C1 * (Math.pow(Q,2) - K); Y = C2 * Math.pow(Q,2);
   return Q_Value / ( W_0 * (X + Y)); }


function MFB_R3( C1, C2, W0, Q ) {return (Q / W0) * (1/C1 + 1/C2); }


//**************************************************************************
// Reverse functions to generate MFB BandPass Filter parameters.
//**************************************************************************


function MFB_K( R3, R1 ) { return R3 / ( 2 * R1 ); }


function MFB_W0( R1, R2, K, C1 ) {
   Numer = parseFloat(R1) + parseFloat(R2);
   Denom = 2 * Math.pow(R1,2) * K * Math.pow(C1,2) * R2;
   return Math.sqrt( Numer / Denom ); }


function MFB_Q( R3, W0, C1 ) { return ( R3 * W0 * C1 ) / 2; }


function MFB_F0( W0 ) { return W0/( 2*Math.PI ); }


function MFB_BW( F0, Q ) { return F0/Q; }


//**************************************************************************
// Foward functions to generate VCVS BandPass Filter components.
//**************************************************************************


//      X = 2 * Q;
//      Y = Math.pow(K-1,2) + ( 8 * Math.pow(Q,2));
//      Z = C1 * W0;
//
//      R1_Init = X / ( Z * K_Value);
//      R2_Init = X / ( Z * ( -1 + Math.sqrt(Y) ) );
//      R3_Init = (1/Math.pow(Z,2)) * ((1/R1_Init) + (1/R2_Init));

//      R4_Init = 2 * R3_Init;
//      R5_Init = 2 * R3_Init;


function VCVS_R1( Q, C1, W0 ) { return ((2*Q)/(C1*W0*K)); }


function VCVS_R2(Q, C1, W0, K ) {
   return (2*Q)/((C1*W0)*(-1 + Math.sqrt(Math.pow(K-1,2)+(8*Math.pow(Q,2))))); }


function VCVS_R3( C1, W0, R1, R2 ) {
   return (1/Math.pow(C1*W0,2))*((1/R1_Init)+(1/R2_Init)); }


function VCVS_R4( R3 ) { return 2*R3_Init; }


function VCVS_R5( R3 ) { return 2*R3_Init; }


//**************************************************************************
// Reverse functions to generate VCVS BandPass Filter parameters.
//**************************************************************************


function VCVS_W0( R1, R2, R3, C1 ) {
   return Math.sqrt( (1/(Math.pow(C1,2) * R3)) * ((1/R1) + (1/R2)) ); }


function VCVS_F0( W0 ) { return W0/(2*Math.PI); }


function VCVS_R2( Q, C1, W0, K ) {
   Y = Math.pow( K - 1, 2 ); Z = 8 * Math.pow( Q, 2 );
   return (2*Q) / (C1*W0*( -1 + Math.sqrt(Y + Z))); }


function VCVS_Q ( R1, C1, W0, K ) { return (R1 * C1 * W0 * K) / 2; }


function VCVS_BW( F0, Q ) { return F0/Q; }


//**************************************************************************
// Calculate the value of two standard resistors that will be very close
// to a precision resistor value, when they are wired in parallel.
//**************************************************************************


function Prec_Res_Calc( R_Prec, Prec_Res_Tol ) {


   //**************************************************************************
   // Find next largest standard resistor.
   //**************************************************************************


   RA_Std = Get_Std_Res( R_Prec, "GT", Prec_Res_Tol );


   //**************************************************************************
   // Calculate the precise resistor value for the parallel resistor.
   //**************************************************************************


   RB_Prec = R_Prec * RA_Std / ( RA_Std - R_Prec );


   //**************************************************************************
   // Find the next hightest resistor for the previous calculation.
   //**************************************************************************


   RB_Std = Get_Std_Res( RB_Prec, "GT", Prec_Res_Tol );


   //**************************************************************************
   // Calculate the result of RA_Std and RB_Std in parallel.
   //**************************************************************************


   RC_Prec = 1 /( 1 / RA_Std + 1 / RB_Std );


   //**************************************************************************
   // Calculate difference from the required value using standard resistors
   // for RA and RB.
   //**************************************************************************


   R_Delta = Math.abs(R_Prec-RC_Prec)/R_Prec*100;
}


//**************************************************************************
// Display window with design information. This function does not do any
// calculations on its own. It simply outputs the information calculated
// in the previous functions.
//**************************************************************************


function View_Act_Bpfil() {


//   Filter_View = window.open('','Des_Win',
//      'menubar=yes,resizable=yes,scrollbars=yes,status=yes,width=750,height=650');


   Filter_View = window.open('','Des_Win',
      'menubar=yes,resizable=yes,scrollbars=yes,status=yes,,');


   with (Filter_View.document) {
      write("<HTML>\n")
      write("<HEAD>\n")
      write("<title>" + Fil_Type + " Active Band-Pass Filter for " + F_0 + "Hz</title>\n")


      write("<link rel=stylesheet type=\"text/css\" href=\"../../dg.css\">\n\n")


      write("</HEAD>\n\n")


      write("<BODY bottommargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" topmargin=\"0\" marginheight=\"0\" marginwidth=\"0\">\n")


      write("<table width=\"100%\" height=\"100\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"black\">\n")
      write("  <tr valign=\"center\">\n")
      write("    <td align=center width=50%>\n")
      write("    <!----------your logo goes here---------->\n")
      write("    <img src=\"../../images/K7MEM_Logo.jpg\" border=\"0\" alt=\"\"></td>\n")
      write("    <!--------------------------------------->\n")
      write("    <td align=center width=50%><P class=std_16_aqua ALIGN=\"center\">Javascript Electronic Notebook<BR>\n")
      write("    <font color=\"#fff2d2\">")
      write(Fil_Type + " Active Band-Pass Filter for " + F_0 + "Hz</font><BR>\n")
      write("    by Martin E. Meserve</td>\n")
      write("  </tr>\n")
      write("</table>\n")


      write("<table width=\"100%\" height=\"19\" cellpadding=\"0\" cellspacing=\"0\" background=\"../../design/topgrbg.gif\" border=\"0\">\n")
      write("  <tr valign=\"top\">\n")
      write("    <td align=right width=\"100%\" background=\"../../design/topgrbg.gif\">\n")
      write("</td></tr></table>\n")


      write("<TABLE BORDER=\"0\" WIDTH=\"100%\" CELLPADDING=\"0\" CELLSPACING=\"0\" align=\"center\">\n")
      write("  <TR>\n")
      write("    <TD bgcolor=\"#000000\" HEIGHT=\"1\">\n")
      write("      <TABLE BORDER=\"0\" WIDTH=\"100%\" CELLPADDING=\"0\" CELLSPACING=\"0\">\n")
      write("        <TR>\n")
      write("          <TD>\n")
      write("      </TD></TR></TABLE>\n")
      write("</TD></TR></TABLE>\n")




      write("<table width=\"100%\" cellpadding=\"15\" cellspacing=\"0\" bgcolor=\"#C6F7BD\" border=\"0\">\n")
      write("  <tr valign=\"top\">\n")
      write("    <td width=\"100%\" height=\"100%\" bgcolor=\"#C6F7BD\" colspan=2>\n")




      write("<table width=\"100%\" cellpadding=\"15\" cellspacing=\"0\" bgcolor=\"#C6F7BD\" border=\"0\">\n")
      write("  <TR>\n")

      write("    <TD colspan=2><P class=std_16_fbrick ALIGN=\"center\">Initial Design Data\n")

      write("<table align=center border=\"0\" cellpadding=\"10\" cellspacing=\"0\">\n")
      write("  <TR>\n")
      write("    <TD colspan=2>\n")
      write("    <P class=std_10 align=justify>The drawing below is\n")
      write("    an example of the type of filter you have chosen. The data on the right\n")
      write("    lists the data you specified for the filter, followed by the\n")
      write("    resistor values that were calculated for the filter.</P>\n")

      write("  <TR>\n")
      write("    <TD width=50%>\n")
      if ( Fil_Type == "VCVS" ) {
         write("    <P class=std_10 align=center><IMG SRC=\"images_actfil/bpf_vcvs_sch.gif\" ALIGN=RIGHT HSPACE=10 >\n") }
      else {
         write("    <P class=std_10 align=center><IMG SRC=\"images_actfil/bpf_mfb_sch.gif\" ALIGN=center HSPACE=10 >\n") }

//         if ( Fil_Type == "VCVS" ) {
//            write("    <P class=std_10 align=center><IMG SRC=\"images/hpf_vcvs_sch.jpg\" ALIGN=RIGHT HSPACE=10 >\n") }
//         else {
//            write("    <P class=std_10 align=center><IMG SRC=\"images/hpf_mfb_sch.jpg\" ALIGN=RIGHT HSPACE=10  >\n") }
//         }

          write("    <td bgcolor=\"#C6F7BD\" width=50%><P class=\"calc_10_green\" align=center>\n");
          write("      <table align=center border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n");
          write("        <TR>\n");
          write("          <TD colspan=2><P class=std_10 align=justify>\n");
          write("          <B>Second-Order " + Fil_Type + " Band-Pass Active Filter</B>.\n");
          write("        <TR>\n");
          write("          <TD colspan=2><P class=std_bold_blue align=center>Specifications\n");
          write("        <TR>\n");
          write("          <TD><P class=std_10_bold>F<sub>0</sub> = " +  Rnd(F_0,2) + " Hz\n");
          write("          <TD><P class=std_10_bold>Q = " + Rnd(Q_Value,2) + "\n");
          write("        <TR>\n");
          write("          <TD><P class=std_10_bold>F<sub>Min</sub> = " + Rnd(F_Min,2) + " Hz\n");
          write("          <TD><P class=std_10_bold>F<sub>Max</sub> = " + Rnd(F_Max,2) + " Hz\n");
          write("        <TR>\n");
          write("          <TD><P class=std_10_bold>BandWidth = " + Rnd(BW_Value,2) + " Hz\n");
          write("          <TD><P class=std_10_bold>Stage Gain = " + Rnd(K_Value,2) + "\n");
          write("        <TR>\n");


          write("          <TD colspan=2><P class=std_bold_blue align=center>Components\n")
          write("        <TR>\n");
          write("          <TD><P class=std_10_bold>C<sub>1</sub> = " + C_Scale(C1_Init) + "\n");
          write("          <TD><P class=std_10_bold>C<sub>2</sub> = " + C_Scale(C2_Init) + "\n");
          write("        <TR>\n");
          write("          <TD><P class=std_10_bold>R<sub>1</sub> = " + comma_ins(Math.round(R1_Init)) + "\n");
          write("          <TD><P class=std_10_bold>R<sub>2</sub> = " + comma_ins(Math.round(R2_Init)) + "\n");
          write("        <TR>\n");
          write("          <TD><P class=std_10_bold>R<sub>3</sub> = " + comma_ins(Math.round(R3_Init)) + "\n");


          if ( Fil_Type == "MFB" ) {
             write("          <TD><P class=std_10_bold>&nbsp;\n"); }

          else {
             write("          <TD><P class=std_10_bold>R<sub>4</sub> = " + comma_ins(Math.round(R4_Init)) + "\n"); }


          write("        <TR>\n");


          if ( Fil_Type == "MFB" ) {
             write("          <TD><P class=std_10_bold>&nbsp;\n"); }
          else {
             write("          <TD><P class=std_10_bold>R<sub>5</sub> = " + comma_ins(Math.round(R5_Init)) + "\n"); }


          write("          <TD><P class=std_10_bold>&nbsp;\n");
          write("      </table>\n");


      write("  <TR>\n")
      if ( Res_Tol == "05" ) {
         write("    <TD colspan=2><P class=std_16_fbrick ALIGN=\"center\">Filter Options using 5% Tolerance Resistors\n")}
      else {
         write("    <TD colspan=2><P class=std_16_fbrick ALIGN=\"center\">Filter Options using 10% Tolerance Resistors\n")
         }


      write("  <TR valign=top>\n")
      write("    <TD><P class=std_10 align=justify>The table below lists ")


      if ( Fil_Type == "MFB" ) {
         write("8\n") }
      else {
         write("16\n") }


      write("    different combinations of standard resistors, that are near the calculated\n")
      write("    value, for each filter section defined. Scroll through the list(s) to see if one of the combinations\n")
      write("    may meet your needs, without resorting to other methods.\n\n")


      write("    <TD><P class=std_10 align=justify>")
      write("    Note that, <B>Gain (K)</B> also changes\n")
      write("    and may influence your decision. Entries are sorted by\n")
      write("    center frequency.\n")


      write("  <TR>\n")
      write("    <TD colspan=2><P class=std_10>\n" + Standard_R_Table + "\n")


      write("  <TR>\n")
      if ( Prec_Res_Tol == "05" ) {
         write("    <TD colspan=2><P class=std_16_fbrick ALIGN=\"center\">\n")
         write("    Calculated Precision Resistors<BR>Using Two Standard 5% Resistors\n") }
      else {
         write("    <TD colspan=2><P class=std_16_fbrick ALIGN=\"center\">\n")
         write("    Calculated Precision Resistors<BR>Using Two Standard 10% Resistors\n") }


      write("  <TR>\n")
      write("    <TD colspan=2><P class=std_10 align=justify>Each resistor in this filter\n")
      write("    can be very closely approximated by using two resistors in parallel. The\n")
      write("    listing below shows the standard resistor values that would be required\n")
      write("    to closly approximate the calculated values. The table header shows you the\n")
      write("    filter, if you use the resistors specified. The <B>Deviation</B> percentage\n")
      write("    listed is the percentage difference between the required/calculated value\n")
      write("    and the <B>Ra || Rb</B> conbination.\n")


      write("  <TR>\n")
      write("    <TD colspan=2><P class=std_10>\n" + Custom_R_Table + "\n")


      write("</TABLE><!-- xxx -->\n\n")
      write("</TABLE>\n\n")
      write("</body>\n")
      write("</html>\n")
      close()
      } // End of "with (Des_Win.document)" statement
}


function View_Act_xBpfil() {


   Filter_View = window.open('','Des_Win',
      'menubar=yes,resizable=yes,scrollbars=yes,status=yes,width=650,height=650');


   with (Filter_View.document) {
      write("<HTML>\n")
      write("<HEAD>\n")
      write("<title>" + Fil_Type + ", Second-Order,  Active Band Pass Filter for " + F_0 + "Hz</title>\n")


      write("<style type=\"text/css\">\n")
      write(".cell { position: relative; }\n")
      write(".loc { font-family: Arial; font-size: 8pt; font-weight: bold; color: #ffff00; text-decoration: none }\n")
      write(".nav { font-family: Arial; font-size: 8pt; font-weight: bold; color: #ffffff; text-decoration: none }\n")
      write(".tbl_item { font-size: 8pt; color: #0000af }\n")
      write(".std { font-family: Arial,Helvetica; font-size: 12pt; text-decoration: none }\n")
      write(".std_8 { font-family: Arial,Helvetica; font-size: 8pt; text-decoration: none }\n")
      write(".std_10 { font-family: Arial,Helvetica; font-size: 10pt; text-decoration: none }\n")
      write(".std_10_green { font-family: Arial,Helvetica; font-size: 10pt; color: #00af00; text-decoration: none }\n")
      write(".std_10_green_bold { font-family: Arial,Helvetica; font-size: 10pt; color: #00af00; font-weight: bold; text-decoration: none }\n")
      write(".std_10_blue_bold { font-family: Arial,Helvetica; font-size: 10pt; color: #0000af; font-weight: bold; text-decoration: none }\n")
      write(".std_12_green_bold { font-family: Arial,Helvetica; font-size: 12pt; color: #00af00; font-weight: bold; text-decoration: none }\n")
      write(".std_16_salmon { font-family: Arial,Helvetica; font-size: 16pt; color: #ffa07a; text-decoration: none }\n")
      write(".std_16_coral { font-family: Arial,Helvetica; font-size: 16pt; color: #f08080; text-decoration: none }\n")
      write(".std_16_gold { font-family: Arial,Helvetica; font-size: 16pt; color: #ffd700; text-decoration: none }\n")
      write(".std_16_dorange { font-family: Arial,Helvetica; font-size: 16pt; font-weight: bold; color: #ff8c00; text-decoration: none }\n")
      write(".std_16_aqua { font-family: Arial,Helvetica; font-size: 16pt; color: #00ffff; text-decoration: none }\n")
      write(".std_14_fbrick { font-family: Arial,Helvetica; font-size: 14pt; font-weight: bold; color: #B22222; text-decoration: none }\n")
      write(".std_16_fbrick { font-family: Arial,Helvetica; font-size: 16pt; font-weight: bold; color: #B22222; text-decoration: none }\n")
      write(".std_bold { font-family: Arial,Helvetica; font-size: 12pt; font-weight: bold; text-decoration: none }\n")
      write(".std_hdr { font-family: Arial,Helvetica; font-size: 14pt; font-weight: bold; color: #00af00; text-decoration: none }\n")
      write(".std_hdr_12 { font-family: Arial,Helvetica; font-size: 12pt; font-weight: bold; color: #00af00; text-decoration: none }\n")
      write(".std_hdr_14 { font-family: Arial,Helvetica; font-size: 14pt; font-weight: bold; color: #00af00; text-decoration: none }\n")
      write(".std_hdr_16 { font-family: Arial,Helvetica; font-size: 16pt; font-weight: bold; color: #00af00; text-decoration: none }\n")
      write("A:link {color: #0000FF; text-decoration: none}A:active {color: #0000FF; text-decoration: none}\n")
      write("A:visited {color: #0000FF; text-decoration: none}\n")
      write("P.special {color: green; border: solid red; font-weight: bold}\n")
      write("td.green {font:12px arial,helvetica,sans-serif; color:#000000; background:#bde1ab}\n")
      write("th.green {font:12px arial,helvetica,sans-serif; font-weight: bold; color:#000000; background:#bde1ab}\n")
      write("td.yellow {font:12px arial,helvetica,sans-serif; color:#000000; background:#fff2d2}\n")
      write("th.yellow {font:12px arial,helvetica,sans-serif; font-weight: bold; color:#000000; background:#fff2d2}\n")
      write("</style>\n")
      write("</HEAD>\n\n")


      write("<BODY ALINK=\"#AF0000\" BACKGROUND=\"../../lightppr.gif\" BGCOLOR=\"#EFEFEF\"\n")
      write(" LINK=\"#AF0000\" TEXT=\"#000000\" VLINK=\"#AF0000\">\n\n")


      write("<table align=center border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"600\">\n")
      write("<TR>\n")
      write(" <TD valign=center align=center background=\"../../icons/comp004.jpg\" width=60%>\n")
      write("   <img src=../../icons/letnum_letnum004_k.gif border=0>\n")
      write("   <img src=../../icons/letnum_letnum004_7.gif border=0>\n")
      write("   <img src=../../icons/letnum_letnum004_m.gif border=0>\n")
      write("  <img src=../../icons/letnum_letnum004_e.gif border=0>\n")
      write("   <img src=../../icons/letnum_letnum004_m.gif border=0>\n")
      write(" <TD valign=center background=\"../../icons/comp004.jpg\">\n")
      write("   <P class=std_16_aqua ALIGN=\"center\">JavaScript<SUP><FONT SIZE=-1>&reg;</font></sup>\n")
      write("  Electronic NoteBook<BR>\n")
      write("<TR>\n")
      write("  <TD colspan=2 background=\"../../icons/comp004.jpg\">\n")
      write("   <P class=std_16_aqua ALIGN=\"center\"><font color=\"#fff2d2\">\n")
      write(Fil_Type + ", Second-Order, <BR>Active Band Pass Filter for " + F_0 + "Hz</font>\n")
      write("</table>\n")


      write("<table bgcolor=\"#3cb371\" align=center cellpadding=\"0\" cellspacing=\"2\" border=\"0\" width=\"550\">\n")
      write("  <tr>\n")
      write("    <td bgcolor=\"#3cb371\">\n")


      write("<table align=center border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"596\">\n")
      write("  <TR>\n")


      write("    <TD class=green colspan=2><P class=std_16_fbrick ALIGN=\"center\">Initial Design Requirements\n")


//      if ( Fil_Order == "Fourth" ) {
//         write("    <P class=std_bold ALIGN=\"center\"><TT>Stage 1</TT>\n")
//         }


      write("    <P class=std_bold ALIGN=\"center\"><TT>F<sub>C</SUB> = " + F_0 + " Hz, ")
      write("    Gain = " + K_Value + ", \n")
      write("    C1 = " + C_Scale(C1_Init) + ", \n")
      write("    C2 = " + C_Scale(C2_Init) + "</tt>\n")


//      if ( Fil_Order == "Fourth" ) {
//         write("    <P class=std_bold ALIGN=\"center\"><TT>Stage 2</TT>\n")
//         write("    <P class=std_bold ALIGN=\"center\"><TT>F<sub>C</SUB> = " + F_0 + " Hz, ")
//         write("    Gain = " + K2_Value + ", \n")
//         write("    C1 = " + C_Scale(C1_2_Init) + ", \n")
//         write("    C2 = " + C_Scale(C2_2_Init) + "</tt>\n")
//         }
      write("<BR><BR>\n\n")
      write("</TABLE>\n\n")


//      if ( Fil_Order == "Second" ) {
         write("<table align=center border=\"0\" cellpadding=\"10\" cellspacing=\"0\">\n")
         write("  <TR>\n")
         write("    <TD class=green><P class=std align=justify>The drawing on the right is\n")
         write("    an example of the type of filter you have chosen. The\n")
         write("    table below lists the exact resistor values,\n")
         write("    calculated from the design requirements above, for the Stage 1 filter.\n")
         write("    <TD class=green>\n")
         if ( Fil_Type == "VCVS" ) {
            write("    <IMG SRC=\"images_actfil/hpf_vcvs_sch.gif\" ALIGN=RIGHT HSPACE=10 >\n") }
         else {
            write("    <IMG SRC=\"images_actfil/hpf_mfb_sch.gif\" ALIGN=RIGHT HSPACE=10 >\n") }
//         }
//      else {
//         write("<table align=center border=\"0\" cellpadding=\"10\" cellspacing=\"0\">\n")
//         write("  <TR>\n")
//         write("    <TD class=green><P class=std align=justify>The drawing on the right is\n")
//         write("    an example of a single filter stage for the type of filter\n")
//         write("    you have chosen. You will need to cascade two of these filters. The\n")
//         write("    table below lists the exact resistor values,\n")
//         write("    calculated from the design requirements above, for the Stage 1 and Stage 2 filters.\n")
//         write("    <TD class=green>\n")
//         if ( Fil_Type == "VCVS" ) {
//            write("    <IMG SRC=\"vcvs_hpfil.gif\" ALIGN=RIGHT HSPACE=10 >\n") }
//         else {
//            write("    <IMG SRC=\"mfb_hpfil.gif\" ALIGN=RIGHT HSPACE=10  >\n") }
//         }


      write("  <TR>\n")
      write("    <TD class=green colspan=2><P class=std_16_fbrick ALIGN=\"center\">Initial Calculations\n")
      write("    <P class=std_10 align=center><B><pre>" + BP_Fil_Calc_1_Data + "</pre></B>\n")


      write("  <TR>\n")
      if ( Res_Tol == "05" ) {
         write("    <TD class=green colspan=2><P class=std_16_fbrick ALIGN=\"center\">Filter Options using 5% Tolerance Resistors\n")}
      else {
         write("    <TD class=green colspan=2><P class=std_16_fbrick ALIGN=\"center\">Filter Options using 10% Tolerance Resistors\n")
         }


      write("  <TR>\n")
      write("    <TD class=green colspan=2><P class=std align=justify>The table below lists ")


      if ( Fil_Type == "MFB" ) {
         write("8\n") }
      else {
         write("16\n") }


      write("    different combinations of standard resistors that are near the calculated\n")
      write("    value. Scroll through the list to see if one of the combinations\n")
      write("    may meet your needs, without resorting to other methods.\n\n")
      write("    <P class=std align=justify>Note that, <B>Gain (K)</B> also changes\n")
      write("    and may influence your decision. Entries are sorted by\n")
      write("    center frequency.\n")


//      if ( Fil_Type == "MFB" ) {
//         write("8\n") }
//      else {
//         write("16\n") }


//      write("    different combinations of standard resistors that are near the calculated\n")
//      write("    value. Scroll through the list to see if one of the combinations\n")
//      write("    may meet your needs, without resorting to other methods.\n\n")
//      write("    <P class=std align=justify>Note that, <B>Gain (K)</B> also changes\n")
//      write("    and may influence your decision. Entries are sorted by\n")
//      write("    center frequency.\n")


//C1_Filter_List_Data


      write("  <TR>\n")
      if ( Fil_Type == "MFB" ) {
//         write("    <TD class=green colspan=2><P class=std_10 align=center><B><pre>" + BP_Fil_Calc_2_Data + "</pre></B>\n") }
         write("    <TD class=green colspan=2><P class=std_10><B><pre>" + C1_Filter_List_Data + "</pre></B>\n") }
      else {
//         write("    <TD class=green colspan=2><P class=std_10><B><pre>" + BP_Fil_Calc_2_Data + "</pre></B>\n") }
         write("    <TD class=green colspan=2><P class=std_10><B><pre>" + C1_Filter_List_Data + "</pre></B>\n") }


      write("  <TR>\n")
      if ( Res_Tol == "05" ) {
         write("    <TD class=green colspan=2><P class=std_16_fbrick ALIGN=\"center\">\n")
         write("    Calculated Precision Resistors<BR>Using Two Standard 5% Resistors\n") }
      else {
         write("    <TD class=green colspan=2><P class=std_16_fbrick ALIGN=\"center\">\n")
         write("    Calculated Precision Resistors<BR>Using Two Standard 10% Resistors\n") }


      write("  <TR>\n")
      write("    <TD class=green colspan=2><P class=std align=justify>The calculated resistors\n")
      write("    can be very closely approximated by using two resistors in parallel. The\n")
      write("    listing below shows the calculated resistors and the standard values\n")
      write("    that need to be paralled. It also recalculates the filter specifications.\n")
      write("  <TR>\n")
      write("    <TD class=green colspan=2><P class=std_10><B><pre>" + Prec_Res_List_Data + "</B></pre>\n")
      write("</TABLE>\n\n")
      write("</TABLE>\n\n")


      write("<!----------------------------------------------------------------->\n")
      write("<!-- Ending and credits. -->\n")
      write("<!----------------------------------------------------------------->\n")


      write("<table bgcolor=\"#3cb371\" align=center cellpadding=\"0\" cellspacing=\"2\" border=\"0\" width=\"600\">\n")
      write("  <tr>\n")
      write("    <td bgcolor=\"#3cb371\">\n")
      write("      <table align=center border=\"0\" cellpadding=\"10\" cellspacing=\"0\" width=100%>\n")
      write("        <TR>\n")
      write("          <th class=yellow width=50%><P class=\"std_10\"><I>&copy; Martin E. Meserve, K7MEM</i><BR>\n")
      write("          <a href=\"../../email.html#Page_Top\" target=\"blank\">Click here to send me a note.</a><BR>\n")
      write("\n")
      write("          <th class=yellow width=50%><P class=\"std_10\">Click to view the<BR>\n")
      write("          <a href=\"../../credits.html#Page_Top\" target=\"blank\">Resource Credits</a>\n")
      write("      </table>\n")
      write("</table>\n")


      write("</body>\n")
      write("</html>\n")


      close()
      } // End of "with (Des_Win.document)" statement
}

