00001 // filter.cc: 00002 // 00003 // The following code builds a 2 GHz maximally flat low-pass filter. 00004 // See Pozar, page 489. 00005 00006 // access the supermix library definitions 00007 #include "supermix.h" 00008 00009 int main() 00010 { 00011 // Set the global temperature and normalization impedance. 00012 // This should be done early in main(). 00013 // These variables are described in device.h 00014 // The physical units are described in global.h and units.h 00015 00016 device::T = 295. * Kelvin; 00017 device::Z0 = 50. * Ohm; 00018 00019 00020 // capacitors and inductors are defined in elements.h; they are 2-port 00021 // primitive elements which can be either series or parallel. 00022 00023 // Create a capacitor, call it c1. 00024 capacitor c1; // c1 has been created with no particular value 00025 c1.parallel(); 00026 c1.C = 0.984 * pFarad; // here the value parameter is being accessed directly 00027 00028 00029 // Create an inductor, call it l2. 00030 inductor l2(6.438*nHenry); // here's how to set the value at creation 00031 l2.series(); 00032 00033 00034 // Create a capacitor, call it c3. 00035 capacitor c3; 00036 c3.parallel(); 00037 c3.C = 3.183 * pFarad; 00038 00039 00040 // Create an inductor, call it l4. Make it be identical to inductor l2. 00041 inductor l4 = l2; // using the assignment operator 00042 00043 00044 // Create a capacitor, call it c5. Make it be identical to capacitor c1. 00045 capacitor c5(c1); // using the copy constructor (usually more efficient) 00046 00047 00048 // Create a circuit called filter to hold the connected circuit. 00049 // Actually a cascade would be more appropriate for this simple circuit. 00050 // circuits are defined in circuit.h 00051 00052 circuit filter; 00053 00054 // Build the filter circuit 00055 // The following statements could be rearranged in any desired order. 00056 00057 // Specify the ports of the resulting circuit using add_port. The port 00058 // numbers of the circuit are automatically assigned consecutively. 00059 // add_port() returns the port number so you don't have to figure it out. 00060 00061 int input = filter.add_port(c1, 1); // Specify the input port (port 1). 00062 int output = filter.add_port(c5, 2); // Specify the output port (port 2). 00063 00064 // Interconnect the component elements using connect(). 00065 00066 filter.connect(c1, 2, l2, 1); // Make the connections in any 00067 filter.connect(l2, 2, c3, 1); // convenient order. 00068 filter.connect(c3, 2, l4, 1); 00069 filter.connect(l4, 2, c5, 1); 00070 00071 00072 // Now set the output number format and display a header: 00073 cout << fixed << setprecision(3); 00074 cout << "2 GHz low-pass filter" << endl << endl; 00075 cout << "F(GHz)" << "\t" << "S21" << "\t" << "Phase" << endl; 00076 00077 // Here we set the desired complex number output format. See 00078 // SIScmplx.h for details. 00079 complex::out_degree(); // use magnitude and phase (in degrees) 00080 complex::out_separator("\t"); // separate the parts with a tab 00081 // (the default is a single space) 00082 00083 // Loop over frequency and print out the frequency response 00084 for(double f=0.25; f<5.0; f+=0.25) { 00085 00086 // Set the global frequency. All circuit elements use device::f to 00087 // determine the frequency. Note the need for units, as always. 00088 00089 device::f = f*GHz; 00090 00091 00092 // Find the complex transmission scattering parameter for the circuit. 00093 // Here we create a temporary sdata object to hold the circuit's 00094 // response at frequency device::f and temperature device::T. The 00095 // scattering matrix is normalized to impedance device::Z0. See 00096 // sdata.h for the definition of an sdata object. See nport.h for 00097 // a description of the member function get_data(), which actually 00098 // calculates and returns the circuit's response. 00099 00100 sdata response = filter.get_data(); 00101 complex S21 = response.S[output][input]; // pick out the S parameter 00102 // from the S matrix. 00103 00104 // Display the results. Note use of units with the frequency 00105 cout << device::f/GHz << "\t" << S21 << endl; 00106 } 00107 00108 }
Please direct comments and corrections to
supermix@submm.caltech.edu
Go to the supermix home page
Generated by
1.2.7