Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
twistedpair.cpp
Go to the documentation of this file.
1 /*
2  * twistedpair.cpp - twisted pair line class implementation
3  *
4  * Copyright (C) 2007, 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 "twistedpair.h"
31 
32 using namespace qucs;
33 
34 twistedpair::twistedpair () : circuit (4) {
35  type = CIR_TWISTEDPAIR;
36 }
37 
38 void twistedpair::initSP (void) {
39  allocMatrixS ();
40  calcLength ();
41 }
42 
43 void twistedpair::calcSP (nr_double_t frequency) {
44  calcPropagation (frequency);
45 
47  nr_double_t p = 2 * z0 + zl;
48  nr_double_t n = 2 * z0 - zl;
49  nr_complex_t e = qucs::exp (2.0 * g * len);
50  nr_complex_t d = p * p * e - n * n;
51 
52  nr_complex_t s11 = zl * (p * e + n) / d;
53  nr_complex_t s14 = 1.0 - s11;
54  nr_complex_t s12 = 4.0 * zl * z0 * qucs::exp (g * len) / d;
55 
56  setS (NODE_1, NODE_1, +s11); setS (NODE_2, NODE_2, +s11);
57  setS (NODE_3, NODE_3, +s11); setS (NODE_4, NODE_4, +s11);
58  setS (NODE_1, NODE_4, +s14); setS (NODE_4, NODE_1, +s14);
59  setS (NODE_2, NODE_3, +s14); setS (NODE_3, NODE_2, +s14);
60  setS (NODE_1, NODE_2, +s12); setS (NODE_2, NODE_1, +s12);
61  setS (NODE_3, NODE_4, +s12); setS (NODE_4, NODE_3, +s12);
62  setS (NODE_1, NODE_3, -s12); setS (NODE_3, NODE_1, -s12);
63  setS (NODE_2, NODE_4, -s12); setS (NODE_4, NODE_2, -s12);
64 }
65 
66 void twistedpair::calcNoiseSP (nr_double_t) {
67  if (len < 0) return;
68  // calculate noise using Bosma's theorem
69  nr_double_t T = getPropertyDouble ("Temp");
70  matrix s = getMatrixS ();
71  matrix e = eye (getSize ());
72  setMatrixN (kelvin (T) / T0 * (e - s * transpose (conj (s))));
73 }
74 
75 void twistedpair::initDC (void) {
76  nr_double_t d = getPropertyDouble ("d");
77  nr_double_t rho = getPropertyDouble ("rho");
78  calcLength ();
79 
80  if (d != 0.0 && rho != 0.0 && len != 0.0) {
81  // tiny resistances
82  nr_double_t g1 = M_PI * sqr (d / 2) / rho / len;
83  nr_double_t g2 = g1;
85  allocMatrixMNA ();
86  setY (NODE_1, NODE_1, +g1); setY (NODE_2, NODE_2, +g1);
87  setY (NODE_1, NODE_2, -g1); setY (NODE_2, NODE_1, -g1);
88  setY (NODE_3, NODE_3, +g2); setY (NODE_4, NODE_4, +g2);
89  setY (NODE_3, NODE_4, -g2); setY (NODE_4, NODE_3, -g2);
90  }
91  else {
92  // DC shorts
94  allocMatrixMNA ();
97  }
98 }
99 
100 void twistedpair::initAC (void) {
101  calcLength ();
102  if (len != 0.0) {
103  setVoltageSources (0);
104  allocMatrixMNA ();
105  } else {
106  setVoltageSources (2);
107  allocMatrixMNA ();
110  }
111 }
112 
113 nr_double_t twistedpair::calcLoss (nr_double_t frequency) {
114  nr_double_t d = getPropertyDouble ("d");
115  nr_double_t rho = getPropertyDouble ("rho");
116  nr_double_t mur = getPropertyDouble ("mur");
117  nr_double_t tand = getPropertyDouble ("tand");
118 
119  nr_double_t delta, rout, rin, ad, ac, l0;
120  // calculate conductor losses
121  rout = d / 2;
122  if (frequency > 0.0) {
123  delta = qucs::sqrt (rho / (M_PI * frequency * MU0 * mur));
124  rin = rout - delta;
125  if (rin < 0.0) rin = 0.0;
126  }
127  else rin = 0.0;
128  ac = (rho * M_1_PI) / (rout * rout - rin * rin) / zl;
129 
130  // calculate dielectric losses
131  l0 = C0 / frequency;
132  ad = M_PI * tand * qucs::sqrt (ereff) / l0;
133 
134  alpha = ac + ad;
135  return alpha;
136 }
137 
138 nr_double_t twistedpair::calcLength (void) {
139  nr_double_t l = getPropertyDouble ("L");
140  nr_double_t T = getPropertyDouble ("T");
141  nr_double_t D = getPropertyDouble ("D");
142  len = l * T * M_PI * D * qucs::sqrt (1 + 1 / sqr (T * M_PI * D));
143  return len;
144 }
145 
146 void twistedpair::calcPropagation (nr_double_t frequency) {
147  nr_double_t d = getPropertyDouble ("d");
148  nr_double_t D = getPropertyDouble ("D");
149  nr_double_t er = getPropertyDouble ("er");
150  nr_double_t T = getPropertyDouble ("T");
151 
152  nr_double_t q, p;
153  p = qucs::atan (T * M_PI * D);
154  q = 0.25 + 0.001 * p * p; // soft PTFE
155  q = 0.25 + 0.0004 * p * p; // usual
156  ereff = 1.0 + q * (er - 1.0);
157  zl = Z0 / M_PI / qucs::sqrt (ereff) * qucs::acosh (D / d);
158  beta = 2 * M_PI * frequency / C0 * qucs::sqrt (ereff);
159  angle = deg (p);
160  alpha = calcLoss (frequency);
161 }
162 
164  setCharacteristic ("Zl", zl);
165  setCharacteristic ("Er", ereff);
166  setCharacteristic ("Length", len);
167  setCharacteristic ("Angle", angle);
168 }
169 
170 void twistedpair::calcAC (nr_double_t frequency) {
171  if (len != 0.0) {
172  calcPropagation (frequency);
174  nr_complex_t y11 = coth (g * len) / zl;
175  nr_complex_t y21 = -cosech (g * len) / zl;
176  setY (NODE_1, NODE_1, +y11); setY (NODE_2, NODE_2, +y11);
177  setY (NODE_3, NODE_3, +y11); setY (NODE_4, NODE_4, +y11);
178  setY (NODE_1, NODE_4, -y11); setY (NODE_4, NODE_1, -y11);
179  setY (NODE_2, NODE_3, -y11); setY (NODE_3, NODE_2, -y11);
180  setY (NODE_1, NODE_2, +y21); setY (NODE_2, NODE_1, +y21);
181  setY (NODE_3, NODE_4, +y21); setY (NODE_4, NODE_3, +y21);
182  setY (NODE_1, NODE_3, -y21); setY (NODE_3, NODE_1, -y21);
183  setY (NODE_2, NODE_4, -y21); setY (NODE_4, NODE_2, -y21);
184  }
185 }
186 
187 void twistedpair::calcNoiseAC (nr_double_t) {
188  if (len < 0) return;
189  // calculate noise using Bosma's theorem
190  nr_double_t T = getPropertyDouble ("Temp");
191  setMatrixN (4 * kelvin (T) / T0 * real (getMatrixY ()));
192 }
193 
194 void twistedpair::initTR (void) {
195  initDC ();
196 }
197 
198 // properties
199 PROP_REQ [] = {
200  { "d", PROP_REAL, { 0.5e-3, PROP_NO_STR }, PROP_POS_RANGEX },
201  { "D", PROP_REAL, { 0.8e-3, PROP_NO_STR }, PROP_POS_RANGEX },
202  { "L", PROP_REAL, { 1500e-3, PROP_NO_STR }, PROP_NO_RANGE },
203  { "T", PROP_REAL, { 100, PROP_NO_STR }, PROP_POS_RANGE },
204  { "er", PROP_REAL, { 4, PROP_NO_STR }, PROP_RNGII (1, 100) },
205  { "mur", PROP_REAL, { 1, PROP_NO_STR }, PROP_RNGII (1, 100) },
206  { "tand", PROP_REAL, { 4e-4, PROP_NO_STR }, PROP_POS_RANGE },
207  { "rho", PROP_REAL, { 0.022e-6, PROP_NO_STR }, PROP_POS_RANGE },
208  PROP_NO_PROP };
209 PROP_OPT [] = {
210  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
211  PROP_NO_PROP };
212 struct define_t twistedpair::cirdef =
nr_double_t calcLoss(nr_double_t)
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define MU0
magnetic constant of vacuum ( )
Definition: constants.h:49
#define PROP_POS_RANGE
Definition: netdefs.h:129
l
Definition: parse_vcd.y:213
#define NODE_2
Definition: circuit.h:35
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
void calcAC(nr_double_t)
#define T0
standard temperature
Definition: constants.h:61
#define PROP_RNGII(f, t)
Definition: netdefs.h:138
#define kelvin(x)
Definition: constants.h:108
#define PROP_DEF
Definition: netdefs.h:189
nr_complex_t coth(const nr_complex_t z)
Compute complex hyperbolic cotangent.
Definition: complex.cpp:320
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
void calcNoiseSP(nr_double_t)
Definition: twistedpair.cpp:66
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
nr_complex_t atan(const nr_complex_t z)
Compute complex arc tangent.
Definition: complex.cpp:117
void calcPropagation(nr_double_t)
#define K
Absolute 0 in centigrade.
Definition: constants.h:59
#define PROP_NO_RANGE
Definition: netdefs.h:126
#define PROP_NO_STR
Definition: netdefs.h:125
void allocMatrixS(void)
Definition: circuit.cpp:251
n
Definition: parse_citi.y:147
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
nr_complex_t acosh(const nr_complex_t z)
Compute complex arc hyperbolic cosine.
Definition: complex.cpp:162
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: twistedpair.cpp:38
matrix getMatrixY(void)
Definition: circuit.cpp:696
int getSize(void)
Get the number of ports the circuit element has.
Definition: circuit.h:143
#define NODE_4
Definition: circuit.h:37
#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
nr_complex_t cosech(const nr_complex_t z)
Compute complex argument hyperbolic cosec.
Definition: complex.cpp:364
#define PROP_COMPONENT
Definition: netdefs.h:116
void calcSP(nr_double_t)
Definition: twistedpair.cpp:43
PROP_OPT[]
void initAC(void)
#define NODE_3
Definition: circuit.h:36
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
matrix transpose(matrix a)
Matrix transposition.
Definition: matrix.cpp:492
nr_double_t angle
Definition: twistedpair.h:48
nr_double_t alpha
Definition: twistedpair.h:48
type
Definition: parse_vcd.y:164
nr_double_t len
Definition: twistedpair.h:48
matrix getMatrixS(void)
Definition: circuit.cpp:654
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
PROP_REQ[]
nr_double_t ereff
Definition: twistedpair.h:48
nr_double_t zl
Definition: twistedpair.h:48
void calcNoiseAC(nr_double_t)
void allocMatrixMNA(void)
Definition: circuit.cpp:267
#define M_1_PI
Inverse of Archimedes' constant ( )
Definition: consts.h:59
nr_double_t beta
Definition: twistedpair.h:48
void initTR(void)
#define PROP_POS_RANGEX
Definition: netdefs.h:131
#define NODE_1
Definition: circuit.h:34
#define C0
speed of light in vacuum ( )
Definition: constants.h:47
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void setMatrixN(matrix)
Definition: circuit.cpp:664
#define deg(x)
Convert radian to degree.
Definition: constants.h:123
matrix eye(int rs, int cs)
Create identity matrix with specified number of rows and columns.
Definition: matrix.cpp:603
nr_complex_t exp(const nr_complex_t z)
Compute complex exponential.
Definition: complex.cpp:205
#define D(con)
void initDC(void)
Definition: twistedpair.cpp:75
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
matrix conj(matrix a)
Conjugate complex matrix.
Definition: matrix.cpp:505
nr_double_t calcLength(void)
void setCharacteristic(const char *, nr_double_t)
Definition: circuit.cpp:566
#define VSRC_2
Definition: circuit.h:41
void saveCharacteristics(nr_double_t)
#define Z0
Wave impedance in vacuum ( )
Definition: constants.h:53
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118