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

circuit.cc

Go to the documentation of this file.
00001 // circuit.cc
00002 //
00003 // How circuit elements are created, manipulated, and evaluated.
00004 
00005 // access the supermix library definitions
00006 #include "supermix.h"
00007 
00008 int main()
00009 {
00010   // -----------------------------------------------------------------
00011   // THE GLOBAL VALUES WHICH MUST BE SET
00012 
00013   // SuperMix must always know the following three facts about any
00014   // circuit it is called upon to analyze:
00015   //
00016   //   (1) The temperatures of the various parts of the circuit 
00017   //   (2) The frequency at which the circuit is to be analyzed
00018   //   (3) The normalizing impedance for the scattering matrices
00019   //
00020   // SuperMix therefore has three global variables which must be set
00021   // to provide these values (these variables are declared and
00022   // described in the SuperMix include file "device.h"). It is wise
00023   // to set these three variables early in main():
00024 
00025   device::T  = 295.*Kelvin;    // the default circuit temperature
00026   device::f  = 1*GHz;          // the frequency
00027   device::Z0 = 50.*Ohm;        // the S matrix normalizing impedance
00028 
00029   // NOTE THAT WE MUST PROVIDE UNITS WITH THE VALUES!!!
00030 
00031   
00032   // -----------------------------------------------------------------
00033   // HOW TO CREATE A CIRCUIT MODEL
00034 
00035   // First let's create a simple 2-port circuit consisting of a single
00036   // resistor in series with the two ports:
00037 
00038   resistor r;      // the type "resistor" is defined in "elements.h".
00039     r.series();    // now r represents a series resistance
00040     r.R = 50*Ohm;  // it now has a value; R is of type "parameter"
00041 
00042   // Circuit elements are all derived from the class "nport", defined
00043   // in "nport.h". This class provides the common interface for all
00044   // circuit elements, which includes the methods to calculate the
00045   // circuit elements' scattering and noise correlation matrices and
00046   // source vector (for elements that have embedded signal sources).
00047 
00048   // Now here's a parallel capacitor:
00049 
00050   capacitor c;     // also in "elements.h"
00051     c.parallel();
00052     c.C = 3*Pico*Farad;
00053 
00054   // We can create a circuit combining these two elements:
00055 
00056   circuit ckt;           // type "circuit" is defined in "circuit.h"
00057 
00058   // To build up our new circuit object, we list connections between
00059   // the ports of the component elements of our circuit. To do this we
00060   // use the member function connect():
00061  
00062   ckt.connect(r,2,c,1);  // we've connected port 2 of r to port 1 of c
00063 
00064   // Now we need to identify the ports of our newly-created
00065   // circuit. Member function add_port() accomplishes this. The ports
00066   // are added in order, so the first call to add_port identifies port
00067   // 1 of our circuit. add_port() returns the port number as an int,
00068   // so we can save the value if we want.
00069 
00070   int input  = ckt.add_port(r,1);  // port 1 of r becomes ckt's first port
00071   int output = ckt.add_port(c,2);  // port 2 of c becomes the other port
00072 
00073   // input == 1, since it was set by the first call to ckt.add_port().
00074   // similarly, output == 2. Let's check:
00075 
00076   cout << "input = " << input << ", output = " << output << endl << endl;
00077 
00078   
00079   // -----------------------------------------------------------------
00080   // CALCULATING CIRCUIT RESPONSE: sdata DATA TYPE
00081 
00082   // The results of a circuit response calcultion are presented using
00083   // the class "sdata", defined in "sdata.h". This class has 3 complex
00084   // member variables:
00085   //   S : a complex_matrix holding the scattering matrix
00086   //   C : a complex_matrix holding the noise correlation matrix
00087   //   B : a complex_vector holding the source vector
00088 
00089   // Let's look at the response of the resistor r:
00090 
00091   sdata s = r.get_data();
00092 
00093   // r.get_data() just calculated the response of r at the conditions
00094   // set by our global variables device::T and device::f, and
00095   // normalized the response using device::Z0. The results returned by
00096   // r.get_data() have been copied into the new variable s.
00097 
00098   cout << "Response of r at " << device::f/GHz << " GHz and " 
00099        << device::T/Kelvin << " Kelvin:" << endl << endl;
00100 
00101   cout << "S matrix:" << endl << s.S << endl << endl;
00102   cout << "C matrix (Kelvin):" << endl << s.C/Kelvin << endl << endl;
00103   cout << "B vector:" << endl << s.B << endl << endl;
00104 
00105   // The noise correlation matrix has elements with units of
00106   // Power/Bandwidth. SuperMix actually stores the elements using
00107   // Temperature units: (Power/Bandwidth)/(Boltzmann's Constant).
00108   // That's why we divided by Kelvin when outputting the C matrix, so
00109   // the numbers output would be meaningful.
00110   //
00111   // Since there isn't a signal generator in our resistor, the source
00112   // vector is all zeroes.
00113 
00114   // Here's the response of the RC circuit we built:
00115 
00116   s = ckt.get_data();
00117   
00118   cout << "Response of ckt:" << endl << endl;
00119 
00120   cout << "S matrix:" << endl << s.S << endl << endl;
00121   cout << "C matrix (Kelvin):" << endl << s.C/Kelvin << endl << endl;
00122   cout << "B vector:" << endl << s.B << endl << endl;
00123 
00124 
00125   // If we change the frequency, we get a different response:
00126 
00127   device::f = 10*GHz;
00128   s = ckt.get_data();
00129 
00130   cout << "Response of ckt at " << device::f/GHz << " GHz and " 
00131        << device::T/Kelvin << " Kelvin:" << endl << endl;
00132 
00133   cout << "S matrix:" << endl << s.S << endl << endl;
00134   cout << "C matrix (Kelvin):" << endl << s.C/Kelvin << endl << endl;
00135   cout << "B vector:" << endl << s.B << endl << endl;
00136 
00137   
00138   // -----------------------------------------------------------------
00139   // SOME OTHER FEATURES OF sdata
00140 
00141   // The sdata class has a couple of member functions for quickly
00142   // getting a specific feature of the response:
00143 
00144   // Gain in dB:
00145   cout << "Gain (dB):   " << s.SdB(output,input) << endl;
00146 
00147   // Noise temperature:
00148   cout << "Tn (Kelvin): " << s.tn(output,input)/Kelvin << endl;
00149 
00150   // Noise figure:
00151   cout << "NF:          " << s.NF(output,input)/Kelvin << endl;
00152 
00153   // (Note how we're using our port number variables we created)
00154 
00155   
00156 }

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