My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attenuator.cpp
Go to the documentation of this file.
1 /*
2  * attenuator.cpp - attenuator class implementation
3  *
4  * Copyright (C) 2003, 2004, 2005, 2008 Stefan Jahn <stefan@lkcc.org>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this package; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * $Id: attenuator.cpp 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "component.h"
30 #include "attenuator.h"
31 
32 attenuator::attenuator () : circuit (2) {
33  type = CIR_ATTENUATOR;
34 }
35 
36 void attenuator::initSP (void) {
37  allocMatrixS ();
38  nr_double_t a = getPropertyDouble ("L");
39  nr_double_t z = getPropertyDouble ("Zref");
40  nr_double_t r = (z - z0) / (z + z0);
41  nr_double_t s11 = r * (1 - a) / (a - r * r);
42  nr_double_t s21 = sqrt (a) * (1 - r * r) / (a - r * r);
43  setS (NODE_1, NODE_1, s11);
44  setS (NODE_2, NODE_2, s11);
45  setS (NODE_1, NODE_2, s21);
46  setS (NODE_2, NODE_1, s21);
47 }
48 
49 void attenuator::calcNoiseSP (nr_double_t) {
50  nr_double_t T = getPropertyDouble ("Temp");
51  nr_double_t l = getPropertyDouble ("L");
52  nr_double_t z = getPropertyDouble ("Zref");
53  nr_double_t r = (z - z0) / (z + z0);
54  nr_double_t f = (l - 1) * (r * r - 1) / sqr (l - r * r) * kelvin (T) / T0;
55  setN (NODE_1, NODE_1, -f * (r * r + l));
56  setN (NODE_2, NODE_2, -f * (r * r + l));
57  setN (NODE_1, NODE_2, +f * 2 * r * sqrt (l));
58  setN (NODE_2, NODE_1, +f * 2 * r * sqrt (l));
59 }
60 
61 void attenuator::calcNoiseAC (nr_double_t) {
62  nr_double_t T = getPropertyDouble ("Temp");
63  nr_double_t l = getPropertyDouble ("L");
64  nr_double_t z = getPropertyDouble ("Zref");
65  nr_double_t f = 4.0 * kelvin (T) / T0 / z / (l - 1);
66  setN (NODE_1, NODE_1, +f * (l + 1));
67  setN (NODE_2, NODE_2, +f * (l + 1));
68  setN (NODE_1, NODE_2, -f * 2 * sqrt (l));
69  setN (NODE_2, NODE_1, -f * 2 * sqrt (l));
70 }
71 
72 void attenuator::initDC (void) {
73  nr_double_t a = getPropertyDouble ("L");
74  if (a == 1.0) { // no attenuation
76  allocMatrixMNA ();
78  }
79 #if AUGMENTED
80  else { // compute Z-parameters
82  allocMatrixMNA ();
83  nr_double_t zref = getPropertyDouble ("Zref");
84  nr_double_t z11 = zref * (a + 1) / (a - 1);
85  nr_double_t z21 = zref * (sqrt (a) * 2) / (a - 1);
86  setB (NODE_1, VSRC_1, +1.0); setB (NODE_1, VSRC_2, +0.0);
87  setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
88  setC (VSRC_1, NODE_1, -1.0); setC (VSRC_1, NODE_2, +0.0);
89  setC (VSRC_2, NODE_1, +0.0); setC (VSRC_2, NODE_2, -1.0);
90  setD (VSRC_1, VSRC_1, +z11); setD (VSRC_2, VSRC_2, +z11);
91  setD (VSRC_1, VSRC_2, +z21); setD (VSRC_2, VSRC_1, +z21);
92  setE (VSRC_1, +0.0); setE (VSRC_2, +0.0);
93  }
94  clearY ();
95 #else
96  else { // compute Y-parameters
98  allocMatrixMNA ();
99  nr_double_t z = getPropertyDouble ("Zref");
100  nr_double_t f = 1 / z / (a - 1);
101  setY (NODE_1, NODE_1, f * (a + 1));
102  setY (NODE_2, NODE_2, f * (a + 1));
103  setY (NODE_1, NODE_2, -f * 2 * sqrt (a));
104  setY (NODE_2, NODE_1, -f * 2 * sqrt (a));
105  }
106 #endif
107 }
108 
109 void attenuator::initAC (void) {
110  nr_double_t a = getPropertyDouble ("L");
111 
112  if (a == 1.0) { // no attenuation
113  setVoltageSources (1);
114  allocMatrixMNA ();
115  clearY ();
117  }
118 #if AUGMENTED
119  else { // compute Z-parameters
120  setVoltageSources (0);
121  allocMatrixMNA ();
122  nr_double_t zref = getPropertyDouble ("Zref");
123  nr_double_t z11 = zref * (a + 1) / (a - 1);
124  nr_double_t z21 = zref * (sqrt (a) * 2) / (a - 1);
125 
126  // build Z-parameter matrix and convert it to Y-parameters
127  matrix z (2);
128  z.set (NODE_1, NODE_1, z11); z.set (NODE_2, NODE_2, z11);
129  z.set (NODE_1, NODE_2, z21); z.set (NODE_2, NODE_1, z21);
130  setMatrixY (ztoy (z));
131  }
132 #else
133  else { // compute Y-parameters
134  setVoltageSources (0);
135  allocMatrixMNA ();
136  nr_double_t z = getPropertyDouble ("Zref");
137  nr_double_t f = 1 / z / (a - 1);
138  setY (NODE_1, NODE_1, f * (a + 1));
139  setY (NODE_2, NODE_2, f * (a + 1));
140  setY (NODE_1, NODE_2, -f * 2 * sqrt (a));
141  setY (NODE_2, NODE_1, -f * 2 * sqrt (a));
142  }
143 #endif
144 }
145 
146 void attenuator::initTR (void) {
147  initDC ();
148 }
149 
150 // properties
151 PROP_REQ [] = {
152  { "L", PROP_REAL, { 10, PROP_NO_STR }, PROP_MIN_VAL (1) },
153  PROP_NO_PROP };
154 PROP_OPT [] = {
155  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
156  { "Zref", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
157  PROP_NO_PROP };
158 struct define_t attenuator::cirdef =
159  { "Attenuator",