Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

error_terms.cc

Go to the documentation of this file.
00001 // SuperMix version 1.0  C++ source file
00002 //
00003 // Copyright (c) 1999 California Institute of Technology.
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms for noncommercial
00007 // purposes are permitted provided that the above copyright notice and
00008 // this paragraph are duplicated in all such forms and that any
00009 // documentation and other materials related to such distribution and
00010 // use acknowledge that the software was developed by California
00011 // Institute of Technology. Redistribution and/or use in source or
00012 // binary forms is not permitted for any commercial purpose. Use of
00013 // this software does not include a permitted use of the Institute's
00014 // name or trademark for any purpose.
00015 //
00016 // DISCLAIMER:
00017 // THIS SOFTWARE AND/OR RELATED MATERIALS ARE PROVIDED "AS-IS" WITHOUT
00018 // WARRANTY OF ANY KIND INCLUDING ANY WARRANTIES OF PERFORMANCE OR
00019 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR PURPOSE (AS SET
00020 // FORTH IN UCC 23212-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
00021 // LICENSED PRODUCT, HOWEVER USED.  IN NO EVENT SHALL CALTECH/JPL BE
00022 // LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING BUT NOT LIMITED TO
00023 // INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC
00024 // DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF
00025 // WHETHER CALTECH/JPL SHALL BE ADVISED, HAVE REASON TO KNOW, OR IN
00026 // FACT SHALL KNOW OF THE POSSIBILITY.  THE USER BEARS ALL RISK
00027 // RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE AND/OR RELATED
00028 // MATERIALS.
00029 
00030 // ************************************************************************
00031 //
00032 // error_terms.cc
00033 //
00034 // See error_terms.h for more information.
00035 //
00036 // 7/22/98 J.Z.
00037 //
00038 // 4/26/99 Added new terms flat_gain and fts_match.  JSW
00039 //
00040 // ************************************************************************
00041 
00042 #include "error_terms.h"
00043 #include "error.h"
00044 
00045 // Need ampdata for amp_k and amp_mag_delta
00046 #include "ampdata.h"
00047 
00048 // Need logarithms.
00049 #include <math.h>
00050 
00051 
00052 double gain_dB::get(state_tag tag)
00053 {
00054   double retval = 0. ;
00055 
00056   // get a reference to scattering matrix in first nport object
00057   const Matrix & Scat = (np->get_data(tag)).S ;
00058     
00059   if(in_port < Scat.Rminindex() || in_port > Scat.Rmaxindex()) {
00060     error::warning("Input port index out of range in gain_dB::get()");
00061   }
00062   if(out_port < Scat.Lminindex() || out_port > Scat.Lmaxindex()) {
00063      error::warning("Output port index out of range in gain_dB::get()");
00064   }
00065     
00066   double gain = abs(Scat.read(out_port, in_port)) ;
00067   if(gain > 0.)
00068     gain = 20.*log10(gain) ;  // convert to dB
00069   else
00070     gain = -1.e20 ;           // just a huge negative number
00071   retval = checkval(gain) ;   // checkval looks at mode flag
00072 
00073   return(retval) ;
00074 }
00075 
00076 
00077 double s_mag::get(state_tag tag)
00078 {
00079   double retval = 0. ;
00080 
00081   // get a reference to scattering matrix in first nport object
00082   const Matrix & Scat = (np->get_data(tag)).S ;
00083     
00084   if(in_port < Scat.Rminindex() || in_port > Scat.Rmaxindex()) {
00085     error::warning("Input port index out of range in s_mag::get()");
00086   }
00087   if(out_port < Scat.Lminindex() || out_port > Scat.Lmaxindex()) {
00088     error::warning("Output port index out of range in s_mag::get()");
00089   }
00090     
00091   double sm = abs(Scat.read(out_port, in_port)) ;
00092   retval = checkval(sm) ;   // checkval looks at mode flag
00093 
00094   return(retval) ;
00095 }
00096 
00097 
00098 double input_tn::get(state_tag tag)
00099 {
00100   double retval = 0. ;
00101 
00102   // get a reference to scattering matrix in first nport object
00103   const Matrix & Scat = (np->get_data(tag)).S ;
00104   // get a reference to noise matrix in first nport object
00105   const Matrix & CNoise = (np->get_data(tag)).C ;
00106     
00107   if(in_port < Scat.Rminindex() || in_port > Scat.Rmaxindex()) {
00108     error::warning("Input port index out of range in sm::get()");
00109   }
00110   if(out_port < Scat.Lminindex() || out_port > Scat.Lmaxindex()) {
00111     error::warning("Output port index out of range in sm::get()");
00112   }
00113     
00114   double sm = abs(Scat.read(out_port, in_port)) ;
00115   double cm = abs(CNoise.read(out_port, out_port)) ;    
00116   double tn = cm/(sm*sm) ;
00117 
00118   retval = checkval(tn) ;   // checkval looks at mode flag
00119 
00120   return(retval) ;
00121 }
00122 
00123 
00124 // Error functions for amplifier stability
00125 
00126 double amp_k::get(state_tag tag)
00127 {
00128   ampdata sd(np->get_data(tag));
00129 
00130   return (checkval(sd.k()));
00131 }
00132 
00133 
00134 double amp_mag_delta::get(state_tag tag)
00135 {
00136   ampdata sd(np->get_data(tag));
00137 
00138   return (10.0 * checkval(zabs(sd.delta())));
00139 }
00140 
00141 
00142 // an error function term for matching S matrices of two circuits
00143 
00144 double two_match::get(state_tag tag)
00145 {
00146   double retval = 0. ;
00147 
00148   // get a reference to scattering matrices in two nport objects
00149   const Matrix & Scat0 = (np1->get_data(tag)).S ;
00150   const Matrix & Scat1 = (np2->get_data(tag)).S ;
00151   Matrix diff = Scat0 - Scat1 ;  // subtract the matrices
00152   // add up squares of complex differences
00153   for(int i = diff.Lminindex(); i<= diff.Lmaxindex(); i++)
00154     for(int j = diff.Rminindex(); j<= diff.Rmaxindex(); j++)
00155   retval += zmagsq(diff.read(i,j)) ;
00156 
00157   return(retval) ;
00158 }
00159 
00160 
00161 void fts_match::reset()
00162 {
00163   // We must call scaled_match_error_term::zero() in reset()
00164   zero();
00165 
00166   // Store initial LO power so that we can reset it before exit.
00167   // We use a parameter in case the LO power parameter shadows another
00168   parameter old_LO_power(*LO_power);
00169 
00170   // Calculate the dark current...
00171   *LO_power = 0.0;
00172   mix->balance();
00173 
00174   // Sum all junction DC currents into the variable dark_current
00175   currents = mix->I_junc(0);  // vector of DC bias currents
00176   int min = currents.minindex();
00177   int max = currents.maxindex();
00178   dark_current = 0.0;
00179   for(int i=min; i<=max; i++) dark_current += currents[i].real;
00180 
00181   // Make sure we leave the mixer the way we found it.
00182   *LO_power = old_LO_power;
00183 }
00184 
00185 double fts_match::get_b(state_tag tag)
00186 {
00187   // Store initial LO power so that we can reset it before exit.
00188   // We use a parameter in case the LO power parameter shadows another
00189   parameter old_LO_power(*LO_power);
00190 
00191   // Calculate the pumped current...
00192   *LO_power = pumped_power;
00193   mix->balance();
00194 
00195   // Sum all junction DC currents into the variable response
00196   currents = mix->I_junc(0);  // vector of DC bias currents
00197   int min = currents.minindex();
00198   int max = currents.maxindex();
00199   double response = 0.0;
00200   for(int i=min; i<=max; i++) response += currents[i].real;
00201 
00202   // Make sure we leave the mixer the way we found it.
00203   *LO_power = old_LO_power;
00204 
00205   // response holds the pumped current; subtract off dark current
00206   response -= dark_current;
00207 
00208   // If the measured FTS data includes a freq correction factor,
00209   // adjust response to include it as well.
00210   if (f) response *= *LO_freq;
00211 
00212   return response;
00213 }
00214 
00215 
00216 double iv_match::get_b()
00217 {
00218   mix->balance();
00219 
00220   // Sum all junction DC currents into the variable c
00221   currents = mix->I_junc(0);  // vector of DC bias currents
00222   int min = currents.minindex();
00223   int max = currents.maxindex();
00224   double c = 0.0;
00225   for(int i=min; i<=max; i++) c += currents[i].real;
00226 
00227   return c;
00228 }
00229 
00230 double iv_match::get(state_tag)
00231 {
00232   double i1 = get_a();
00233   double i2 = get_b();
00234   return (i1-i2)*(i1-i2);
00235 }
00236 

Please direct comments and corrections to supermix@submm.caltech.edu
Go to the supermix home page
Generated by doxygen1.2.7