Qucs-core  0.0.19
attenuator.cpp
Go to the documentation of this file.
00001 /*
00002  * attenuator.cpp - attenuator class implementation
00003  *
00004  * Copyright (C) 2003, 2004, 2005, 2008 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00025 #if HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #include "component.h"
00030 #include "attenuator.h"
00031 
00032 using namespace qucs;
00033 
00034 attenuator::attenuator () : circuit (2) {
00035   type = CIR_ATTENUATOR;
00036 }
00037 
00038 void attenuator::initSP (void) {
00039   allocMatrixS ();
00040   nr_double_t a = getPropertyDouble ("L");
00041   nr_double_t z = getPropertyDouble ("Zref");
00042   nr_double_t r = (z - z0) / (z + z0);
00043   nr_double_t s11 = r * (1 - a) / (a - r * r);
00044   nr_double_t s21 = std::sqrt (a) * (1 - r * r) / (a - r * r);
00045   setS (NODE_1, NODE_1, s11);
00046   setS (NODE_2, NODE_2, s11);
00047   setS (NODE_1, NODE_2, s21);
00048   setS (NODE_2, NODE_1, s21);
00049 }
00050 
00051 void attenuator::calcNoiseSP (nr_double_t) {
00052   nr_double_t T = getPropertyDouble ("Temp");
00053   nr_double_t l = getPropertyDouble ("L");
00054   nr_double_t z = getPropertyDouble ("Zref");
00055   nr_double_t r = (z - z0) / (z + z0);
00056   nr_double_t f = (l - 1) * (r * r - 1) / sqr (l - r * r) * celsius2kelvin (T) / T0;
00057   setN (NODE_1, NODE_1, -f * (r * r + l));
00058   setN (NODE_2, NODE_2, -f * (r * r + l));
00059   setN (NODE_1, NODE_2, +f * 2 * r * std::sqrt (l));
00060   setN (NODE_2, NODE_1, +f * 2 * r * std::sqrt (l));
00061 }
00062 
00063 void attenuator::calcNoiseAC (nr_double_t) {
00064   nr_double_t T = getPropertyDouble ("Temp");
00065   nr_double_t l = getPropertyDouble ("L");
00066   nr_double_t z = getPropertyDouble ("Zref");
00067   nr_double_t f = 4.0 * celsius2kelvin (T) / T0 / z / (l - 1);
00068   setN (NODE_1, NODE_1, +f * (l + 1));
00069   setN (NODE_2, NODE_2, +f * (l + 1));
00070   setN (NODE_1, NODE_2, -f * 2 * std::sqrt (l));
00071   setN (NODE_2, NODE_1, -f * 2 * std::sqrt (l));
00072 }
00073 
00074 void attenuator::initDC (void) {
00075   nr_double_t a = getPropertyDouble ("L");
00076   if (a == 1.0) { // no attenuation
00077     setVoltageSources (1);
00078     allocMatrixMNA ();
00079     voltageSource (VSRC_1, NODE_1, NODE_2);
00080   }
00081 #if AUGMENTED
00082   else { // compute Z-parameters
00083     setVoltageSources (2);
00084     allocMatrixMNA ();
00085     nr_double_t zref = getPropertyDouble ("Zref");
00086     nr_double_t z11 = zref * (a + 1) / (a - 1);
00087     nr_double_t z21 = zref * (std::sqrt (a) * 2) / (a - 1);
00088     setB (NODE_1, VSRC_1, +1.0); setB (NODE_1, VSRC_2, +0.0);
00089     setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
00090     setC (VSRC_1, NODE_1, -1.0); setC (VSRC_1, NODE_2, +0.0);
00091     setC (VSRC_2, NODE_1, +0.0); setC (VSRC_2, NODE_2, -1.0);
00092     setD (VSRC_1, VSRC_1, +z11); setD (VSRC_2, VSRC_2, +z11);
00093     setD (VSRC_1, VSRC_2, +z21); setD (VSRC_2, VSRC_1, +z21);
00094     setE (VSRC_1, +0.0); setE (VSRC_2, +0.0);
00095   }
00096   clearY ();
00097 #else
00098   else { // compute Y-parameters
00099     setVoltageSources (0);
00100     allocMatrixMNA ();
00101     nr_double_t z = getPropertyDouble ("Zref");
00102     nr_double_t f = 1 / z / (a - 1);
00103     setY (NODE_1, NODE_1, f * (a + 1));
00104     setY (NODE_2, NODE_2, f * (a + 1));
00105     setY (NODE_1, NODE_2, -f * 2 * std::sqrt (a));
00106     setY (NODE_2, NODE_1, -f * 2 * std::sqrt (a));
00107   }
00108 #endif
00109 }
00110 
00111 void attenuator::initAC (void) {
00112   nr_double_t a = getPropertyDouble ("L");
00113 
00114   if (a == 1.0) { // no attenuation
00115     setVoltageSources (1);
00116     allocMatrixMNA ();
00117     clearY ();
00118     voltageSource (VSRC_1, NODE_1, NODE_2);
00119   }
00120 #if AUGMENTED
00121   else { // compute Z-parameters
00122     setVoltageSources (0);
00123     allocMatrixMNA ();
00124     nr_double_t zref = getPropertyDouble ("Zref");
00125     nr_double_t z11 = zref * (a + 1) / (a - 1);
00126     nr_double_t z21 = zref * (std::sqrt (a) * 2) / (a - 1);
00127 
00128     // build Z-parameter matrix and convert it to Y-parameters
00129     matrix z (2);
00130     z.set (NODE_1, NODE_1, z11); z.set (NODE_2, NODE_2, z11);
00131     z.set (NODE_1, NODE_2, z21); z.set (NODE_2, NODE_1, z21);
00132     setMatrixY (ztoy (z));
00133   }
00134 #else
00135   else { // compute Y-parameters
00136     setVoltageSources (0);
00137     allocMatrixMNA ();
00138     nr_double_t z = getPropertyDouble ("Zref");
00139     nr_double_t f = 1 / z / (a - 1);
00140     setY (NODE_1, NODE_1, f * (a + 1));
00141     setY (NODE_2, NODE_2, f * (a + 1));
00142     setY (NODE_1, NODE_2, -f * 2 * std::sqrt (a));
00143     setY (NODE_2, NODE_1, -f * 2 * std::sqrt (a));
00144   }
00145 #endif
00146 }
00147 
00148 void attenuator::initTR (void) {
00149   initDC ();
00150 }
00151 
00152 // properties
00153 PROP_REQ [] = {
00154   { "L", PROP_REAL, { 10, PROP_NO_STR }, PROP_MIN_VAL (1) },
00155   PROP_NO_PROP };
00156 PROP_OPT [] = {
00157   { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
00158   { "Zref", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
00159   PROP_NO_PROP };
00160 struct define_t attenuator::cirdef =
00161   { "Attenuator",
00162     2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };