Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 using namespace qucs;
33 
34 attenuator::attenuator () : circuit (2) {
36 }
37 
38 void attenuator::initSP (void) {
39  allocMatrixS ();
40  nr_double_t a = getPropertyDouble ("L");
41  nr_double_t z = getPropertyDouble ("Zref");
42  nr_double_t r = (z - z0) / (z + z0);
43  nr_double_t s11 = r * (1 - a) / (a - r * r);
44  nr_double_t s21 = std::sqrt (a) * (1 - r * r) / (a - r * r);
45  setS (NODE_1, NODE_1, s11);
46  setS (NODE_2, NODE_2, s11);
47  setS (NODE_1, NODE_2, s21);
48  setS (NODE_2, NODE_1, s21);
49 }
50 
51 void attenuator::calcNoiseSP (nr_double_t) {
52  nr_double_t T = getPropertyDouble ("Temp");
53  nr_double_t l = getPropertyDouble ("L");
54  nr_double_t z = getPropertyDouble ("Zref");
55  nr_double_t r = (z - z0) / (z + z0);
56  nr_double_t f = (l - 1) * (r * r - 1) / sqr (l - r * r) * kelvin (T) / T0;
57  setN (NODE_1, NODE_1, -f * (r * r + l));
58  setN (NODE_2, NODE_2, -f * (r * r + l));
59  setN (NODE_1, NODE_2, +f * 2 * r * std::sqrt (l));
60  setN (NODE_2, NODE_1, +f * 2 * r * std::sqrt (l));
61 }
62 
63 void attenuator::calcNoiseAC (nr_double_t) {
64  nr_double_t T = getPropertyDouble ("Temp");
65  nr_double_t l = getPropertyDouble ("L");
66  nr_double_t z = getPropertyDouble ("Zref");
67  nr_double_t f = 4.0 * kelvin (T) / T0 / z / (l - 1);
68  setN (NODE_1, NODE_1, +f * (l + 1));
69  setN (NODE_2, NODE_2, +f * (l + 1));
70  setN (NODE_1, NODE_2, -f * 2 * std::sqrt (l));
71  setN (NODE_2, NODE_1, -f * 2 * std::sqrt (l));
72 }
73 
74 void attenuator::initDC (void) {
75  nr_double_t a = getPropertyDouble ("L");
76  if (a == 1.0) { // no attenuation
78  allocMatrixMNA ();
80  }
81 #if AUGMENTED
82  else { // compute Z-parameters
84  allocMatrixMNA ();
85  nr_double_t zref = getPropertyDouble ("Zref");
86  nr_double_t z11 = zref * (a + 1) / (a - 1);
87  nr_double_t z21 = zref * (std::sqrt (a) * 2) / (a - 1);
88  setB (NODE_1, VSRC_1, +1.0); setB (NODE_1, VSRC_2, +0.0);
89  setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
90  setC (VSRC_1, NODE_1, -1.0); setC (VSRC_1, NODE_2, +0.0);
91  setC (VSRC_2, NODE_1, +0.0); setC (VSRC_2, NODE_2, -1.0);
92  setD (VSRC_1, VSRC_1, +z11); setD (VSRC_2, VSRC_2, +z11);
93  setD (VSRC_1, VSRC_2, +z21); setD (VSRC_2, VSRC_1, +z21);
94  setE (VSRC_1, +0.0); setE (VSRC_2, +0.0);
95  }
96  clearY ();
97 #else
98  else { // compute Y-parameters
100  allocMatrixMNA ();
101  nr_double_t z = getPropertyDouble ("Zref");
102  nr_double_t f = 1 / z / (a - 1);
103  setY (NODE_1, NODE_1, f * (a + 1));
104  setY (NODE_2, NODE_2, f * (a + 1));
105  setY (NODE_1, NODE_2, -f * 2 * std::sqrt (a));
106  setY (NODE_2, NODE_1, -f * 2 * std::sqrt (a));
107  }
108 #endif
109 }
110 
111 void attenuator::initAC (void) {
112  nr_double_t a = getPropertyDouble ("L");
113 
114  if (a == 1.0) { // no attenuation
115  setVoltageSources (1);
116  allocMatrixMNA ();
117  clearY ();
119  }
120 #if AUGMENTED
121  else { // compute Z-parameters
122  setVoltageSources (0);
123  allocMatrixMNA ();
124  nr_double_t zref = getPropertyDouble ("Zref");
125  nr_double_t z11 = zref * (a + 1) / (a - 1);
126  nr_double_t z21 = zref * (std::sqrt (a) * 2) / (a - 1);
127 
128  // build Z-parameter matrix and convert it to Y-parameters
129  matrix z (2);
130  z.set (NODE_1, NODE_1, z11); z.set (NODE_2, NODE_2, z11);
131  z.set (NODE_1, NODE_2, z21); z.set (NODE_2, NODE_1, z21);
132  setMatrixY (ztoy (z));
133  }
134 #else
135  else { // compute Y-parameters
136  setVoltageSources (0);
137  allocMatrixMNA ();
138  nr_double_t z = getPropertyDouble ("Zref");
139  nr_double_t f = 1 / z / (a - 1);
140  setY (NODE_1, NODE_1, f * (a + 1));
141  setY (NODE_2, NODE_2, f * (a + 1));
142  setY (NODE_1, NODE_2, -f * 2 * std::sqrt (a));
143  setY (NODE_2, NODE_1, -f * 2 * std::sqrt (a));
144  }
145 #endif
146 }
147 
148 void attenuator::initTR (void) {
149  initDC ();
150 }
151 
152 // properties
153 PROP_REQ [] = {
154  { "L", PROP_REAL, { 10, PROP_NO_STR }, PROP_MIN_VAL (1) },
155  PROP_NO_PROP };
156 PROP_OPT [] = {
157  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
158  { "Zref", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
159  PROP_NO_PROP };
160 struct define_t attenuator::cirdef =
161  { "Attenuator",
#define PROP_POS_RANGE
Definition: netdefs.h:129
l
Definition: parse_vcd.y:213
void clearY(void)
Definition: circuit.cpp:740
#define NODE_2
Definition: circuit.h:35
#define T0
standard temperature
Definition: constants.h:61
#define kelvin(x)
Definition: constants.h:108
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
void setD(int, int, nr_complex_t)
Definition: circuit.cpp:373
#define PROP_REAL
Definition: netdefs.h:174
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define K
Absolute 0 in centigrade.
Definition: constants.h:59
#define PROP_NO_STR
Definition: netdefs.h:125
void setB(int, int, nr_complex_t)
Definition: circuit.cpp:349
void allocMatrixS(void)
Definition: circuit.cpp:251
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
r
Definition: parse_mdl.y:515
void calcNoiseSP(nr_double_t)
Definition: attenuator.cpp:51
#define VSRC_1
Definition: circuit.h:40
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
Definition: complex.cpp:673
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
void calcNoiseAC(nr_double_t)
Definition: attenuator.cpp:63
#define PROP_COMPONENT
Definition: netdefs.h:116
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
void setMatrixY(matrix)
Definition: circuit.cpp:685
void initDC(void)
Definition: attenuator.cpp:74
type
Definition: parse_vcd.y:164
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
PROP_REQ[]
Definition: attenuator.cpp:153
void allocMatrixMNA(void)
Definition: circuit.cpp:267
void initTR(void)
Definition: attenuator.cpp:148
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void setN(int, int, nr_complex_t)
Definition: circuit.cpp:597
void setC(int, int, nr_complex_t)
Definition: circuit.cpp:361
void initAC(void)
Definition: attenuator.cpp:111
#define VSRC_2
Definition: circuit.h:41
zref
Definition: parse_zvr.y:130
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: attenuator.cpp:38
matrix ztoy(matrix z)
impedance matrix to admittance matrix.
Definition: matrix.cpp:1050
PROP_OPT[]
Definition: attenuator.cpp:156