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 // sdata_interp.h 00032 // 00033 // Contains classes which allow creation of nport objects which interpolate 00034 // their S matrix and noise data. Values may be read from files of S, Y, or 00035 // Z matrix data vs. frequency in any of a number of data file formats. 00036 // (currently [12/99] only Touchstone format is recognized) 00037 // 00038 // FRR 10/7/99 00039 // 00040 // ******************************************************************** 00041 00042 #ifndef SDATA_INTERP_H 00043 #define SDATA_INTERP_H 00044 00045 #include "interpolate.h" 00046 #include "io.h" 00047 #include "nport.h" 00048 #include "parameter/abstract_real_parameter.h" 00049 00050 // ******************************************************************** 00051 // class S_interp: interpolate S and C matrix data; not an nport device 00052 00053 class S_interp 00054 { 00055 public: 00056 00057 explicit 00058 S_interp(int ports = 2) : N(ports), Znorm_(0.0), noise_(false) { } 00059 00060 00061 // ------------------------------------------------ 00062 // fill the interpolators and prepare them for use: 00063 00064 // Read in Touchstone-formatted data from the named file, convert to 00065 // S matrix data, and rebuild the interpolators. Returns false if the file 00066 // could not be read or interpreted with the proper number of ports. Uses 00067 // the provided frequency scale factor if none included in the file spec line. 00068 // Will also read in noise data and build a C matrix interpolation if it is a 2 port 00069 // and noise data is available in the touchstone file. 00070 bool touchstone(const char * name, double f_scale = GHz); 00071 00072 // The function add_S() adds a single S matrix point to the S interpolator. 00073 // S must have the correct number of ports in order for it to be added. 00074 // Warns if S is improper. User must later call build() to have the 00075 // point included in the interpolation. Zn should be the normalization 00076 // impedance used to calculate S; S will then be renormalized if necessary. 00077 // Ignores Zn if it is not positive. 00078 S_interp & add_S(double f, const Matrix & S, double Zn = device::Z0); 00079 S_interp & add_S(double f, const sdata & Sd); // uses sdata's normalization 00080 00081 // add_SC() adds both S and C matrix data to the interpolators 00082 S_interp & add_SC(double f, const Matrix & S, const Matrix & C, double Zn = device::Z0); 00083 S_interp & add_SC(double f, const sdata & Sd); 00084 00085 // incorporate the matrices added using add_S() and add_C() into the interpolation. 00086 // (Note that touchstone() automatically builds the interpolations, so you need not call 00087 // this function if the data comes from a call to touchstone()) 00088 S_interp & build() { if(Znorm_ != 0.0) {s.build(); if(noise_) c.build();} return *this; } 00089 00090 00091 // ------------------------------------------------ 00092 // interpolate the matrix data. The matrices are normalized to Znorm(). 00093 00094 // interpolate S matrix. 00095 Matrix S(double f) const 00096 { return s(f); } 00097 00098 // interpolate noise correlation (C) matrix. If no noise interpolation is available, 00099 // returns all zeroes. 00100 Matrix C(double f) const 00101 { return (noise_) ? c(f) : Matrix(N); } 00102 00103 // fill Sd.S and Sd.C, set Sd normalization to Znorm(). If no noise interpolation is 00104 // available, leaves Sd.C unmodified. Returns true if noise interpolation 00105 // performed, false if only S matrix interpolated. 00106 bool fill(sdata & Sd, double f) const 00107 { Sd.S = s(f); if(noise_) Sd.C = c(f); Sd.set_znorm(Znorm_); return noise_; } 00108 00109 00110 // ------------------------------------------------ 00111 // manage and manipulate the interpolations 00112 00113 // Clear out all data and start over; number of ports unchanged 00114 S_interp & clear() { Znorm_ = 0.0; noise_ = false; s.clear(); c.clear(); return *this; } 00115 00116 // Clear out only noise data 00117 S_interp & clear_noise() { noise_ = false; c.clear(); return *this; } 00118 00119 // Directly access the interpolators to set special options, etc. 00120 interpolator<Matrix> & S_interpolator() { return s; } 00121 interpolator<Matrix> & C_interpolator() { return c; } 00122 00123 00124 // ------------------------------------------------ 00125 // status information: 00126 00127 // return the normalization impedance for the interpolated matrix data. It will 00128 // equal the value of device::Z0 when the first data point was added, if any. 00129 // Returns 0 if no data has been added yet. 00130 double Znorm() const { return Znorm_ ; } 00131 00132 // return the number of ports. 00133 int ports() const { return N ; } 00134 00135 // Is S_interp ready to provide interpolated values? 00136 bool ready() const { return s.ready() && ( !noise_ || c.ready() ); } 00137 00138 // Is noise data interpolation available? 00139 bool has_noise() const { return noise_ ; } 00140 00141 00142 private: 00143 int N; // number of ports 00144 double Znorm_; // normalization impedance 00145 bool noise_; // interpolating noise values 00146 interpolator<Matrix> s, c; 00147 }; 00148 00149 00150 // ******************************************************************** 00151 // class sdata_interp: nport with interpolated S matrix data 00152 00153 class sdata_interp : public nport 00154 { 00155 public: 00156 00157 // Call constructor with the number of ports for this object and reference to 00158 // a parameter to be used as the interpolation index. 00159 explicit 00160 sdata_interp(int ports = 2, const abstract_real_parameter & f = device::f); 00161 00162 // Change the index parameter used for the interpolation 00163 sdata_interp & parameter(const abstract_real_parameter & f) { pf = &f; return *this; } 00164 00165 // ------------------- 00166 // Various status functions: 00167 00168 // Returns true if the data has been filled and it's ready to go 00169 bool ready() const { return S.ready(); } 00170 00171 // Return info about the sdata of the device. 00172 const data_info & get_data_info() { info.active = S.has_noise(); return info; } 00173 00174 // Returns true if noise data is being interpolated. Returns false if noise 00175 // data comes from a passive noise calculation from the S matrix interpolation, 00176 // device::f, and device::T. 00177 bool active_noise() const { return S.has_noise(); } 00178 00179 // ------------------- 00180 // Various ways to fill the matrix data for the interpolation. Returns false 00181 // if there was a problem. 00182 00183 // Read in Touchstone-formatted data from the named file, convert to 00184 // S (and, if available, C) matrix data, and rebuild the interpolation. 00185 // Returns false if the file could not be read or interpreted with the proper 00186 // number of ports. Uses the provided frequency scale factor if none included 00187 // in the file spec line. 00188 bool touchstone(const char * name, double f_scale = GHz) 00189 { return S.touchstone(name, f_scale); } 00190 00191 // Copy the provided interpolator into the object's internal interpolator. 00192 // The argument must have the correct number of ports. 00193 bool copy(const S_interp & source); 00194 00195 // Provide for direct modification of the internal S matrix interpolator. 00196 S_interp & interpolator() { return S ; } 00197 00198 00199 private: 00200 const abstract_real_parameter * pf; // points to the index variable 00201 S_interp S; // interpolates S matrix 00202 void recalc(); 00203 void recalc_S(); 00204 }; 00205 00206 00207 // ******************************************************************** 00208 // Some generally useful utility functions for S matrix manipulation 00209 00210 // return a new S matrix with normalization impedance Znew by renormalizing 00211 // S, which has normalization impedance Zold. S must be square, Index_1. 00212 Matrix S_renormalize(const Matrix & S, double Znew, double Zold); 00213 00214 // function S_to_sdata(sdata & SD, const Matrix & S) : fill sdata using S. 00215 // uses Zn, device::T, and device::f to set up SD. Noise comes from 00216 // sdata::passive_noise(). SD must have the correct size for S. 00217 void S_to_sdata(sdata & SD, const Matrix & S, double Zn = device::Z0); 00218 00219 00220 #endif /* SDATA_INTERP_H */
Please direct comments and corrections to
supermix@submm.caltech.edu
Go to the supermix home page
Generated by
1.2.7