My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: twistedpair.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 "twistedpair.h"
31 
32 twistedpair::twistedpair () : circuit (4) {
33  type = CIR_TWISTEDPAIR;
34 }
35 
36 void twistedpair::initSP (void) {
37  allocMatrixS ();
38  calcLength ();
39 }
40 
41 void twistedpair::calcSP (nr_double_t frequency) {
42  calcPropagation (frequency);
43 
44  nr_complex_t g = rect (alpha, beta);
45  nr_double_t p = 2 * z0 + zl;
46  nr_double_t n = 2 * z0 - zl;
47  nr_complex_t e = exp (2.0 * g * len);
48  nr_complex_t d = p * p * e - n * n;
49 
50  nr_complex_t s11 = zl * (p * e + n) / d;
51  nr_complex_t s14 = 1.0 - s11;
52  nr_complex_t s12 = 4.0 * zl * z0 * exp (g * len) / d;
53 
54  setS (NODE_1, NODE_1, +s11); setS (NODE_2, NODE_2, +s11);
55  setS (NODE_3, NODE_3, +s11); setS (NODE_4, NODE_4, +s11);
56  setS (NODE_1, NODE_4, +s14); setS (NODE_4, NODE_1, +s14);
57  setS (NODE_2, NODE_3, +s14); setS (NODE_3, NODE_2, +s14);
58  setS (NODE_1, NODE_2, +s12); setS (NODE_2, NODE_1, +s12);
59  setS (NODE_3, NODE_4, +s12); setS (NODE_4, NODE_3, +s12);
60  setS (NODE_1, NODE_3, -s12); setS (NODE_3, NODE_1, -s12);
61  setS (NODE_2, NODE_4, -s12); setS (NODE_4, NODE_2, -s12);
62 }
63 
64 void twistedpair::calcNoiseSP (nr_double_t) {
65  if (len < 0) return;
66  // calculate noise using Bosma's theorem
67  nr_double_t T = getPropertyDouble ("Temp");
68  matrix s = getMatrixS ();
69  matrix e = eye (getSize ());
70  setMatrixN (kelvin (T) / T0 * (e - s * transpose (conj (s))));
71 }
72 
73 void twistedpair::initDC (void) {
74  nr_double_t d = getPropertyDouble ("d");
75  nr_double_t rho = getPropertyDouble ("rho");
76  calcLength ();
77 
78  if (d != 0.0 && rho != 0.0 && len != 0.0) {
79  // tiny resistances
80  nr_double_t g1 = M_PI * sqr (d / 2) / rho / len;
81  nr_double_t g2 = g1;
83  allocMatrixMNA ();
84  setY (NODE_1, NODE_1, +g1); setY (NODE_2, NODE_2, +g1);
85  setY (NODE_1, NODE_2, -g1); setY (NODE_2, NODE_1, -g1);
86  setY (NODE_3, NODE_3, +g2); setY (NODE_4, NODE_4, +g2);
87  setY (NODE_3, NODE_4, -g2); setY (NODE_4, NODE_3, -g2);
88  }
89  else {
90  // DC shorts
92  allocMatrixMNA ();
95  }
96 }
97 
98 void twistedpair::initAC (void) {
99  calcLength ();
100  if (len != 0.0) {
101  setVoltageSources (0);
102  allocMatrixMNA ();
103  } else {
104  setVoltageSources (2);
105  allocMatrixMNA ();
108  }
109 }
110 
111 nr_double_t twistedpair::calcLoss (nr_double_t frequency) {
112  nr_double_t d = getPropertyDouble ("d");
113  nr_double_t rho = getPropertyDouble ("rho");
114  nr_double_t mur = getPropertyDouble ("mur");
115  nr_double_t tand = getPropertyDouble ("tand");
116 
117  nr_double_t delta, rout, rin, ad, ac, l0;
118  // calculate conductor losses
119  rout = d / 2;
120  if (frequency > 0.0) {
121  delta = sqrt (rho / (M_PI * frequency * MU0 * mur));
122  rin = rout - delta;
123  if (rin < 0.0) rin = 0.0;
124  }
125  else rin = 0.0;
126  ac = (rho * M_1_PI) / (rout * rout - rin * rin) / zl;
127 
128  // calculate dielectric losses
129  l0 = C0 / frequency;
130  ad = M_PI * tand * sqrt (ereff) / l0;
131 
132  alpha = ac + ad;
133  return alpha;
134 }
135 
136 nr_double_t twistedpair::calcLength (void) {
137  nr_double_t l = getPropertyDouble ("L");
138  nr_double_t T = getPropertyDouble ("T");
139  nr_double_t D = getPropertyDouble ("D");
140  len = l * T * M_PI * D * sqrt (1 + 1 / sqr (T * M_PI * D));
141  return len;
142 }
143 
144 void twistedpair::calcPropagation (nr_double_t frequency) {
145  nr_double_t d = getPropertyDouble ("d");
146  nr_double_t D = getPropertyDouble ("D");
147  nr_double_t er = getPropertyDouble ("er");
148  nr_double_t T = getPropertyDouble ("T");
149 
150  nr_double_t q, p;
151  p = atan (T * M_PI * D);
152  q = 0.25 + 0.001 * p * p; // soft PTFE
153  q = 0.25 + 0.0004 * p * p; // usual
154  ereff = 1.0 + q * (er - 1.0);
155  zl = Z0 / M_PI / sqrt (ereff) * acosh (D / d);
156  beta = 2 * M_PI * frequency / C0 * sqrt (ereff);
157  angle = deg (p);
158  alpha = calcLoss (frequency);
159 }
160 
162  setCharacteristic ("Zl", zl);
163  setCharacteristic ("Er", ereff);
164  setCharacteristic ("Length", len);
165  setCharacteristic ("Angle", angle);
166 }
167 
168 void twistedpair::calcAC (nr_double_t frequency) {
169  if (len != 0.0) {
170  calcPropagation (frequency);
171  nr_complex_t g = rect (alpha, beta);
172  nr_complex_t y11 = coth (g * len) / zl;
173  nr_complex_t y21 = -cosech (g * len) / zl;
174  setY (NODE_1, NODE_1, +y11); setY (NODE_2, NODE_2, +y11);
175  setY (NODE_3, NODE_3, +y11); setY (NODE_4, NODE_4, +y11);
176  setY (NODE_1, NODE_4, -y11); setY (NODE_4, NODE_1, -y11);
177  setY (NODE_2, NODE_3, -y11); setY (NODE_3, NODE_2, -y11);
178  setY (NODE_1, NODE_2, +y21); setY (NODE_2, NODE_1, +y21);
179  setY (NODE_3, NODE_4, +y21); setY (NODE_4, NODE_3, +y21);
180  setY (NODE_1, NODE_3, -y21); setY (NODE_3, NODE_1, -y21);
181  setY (NODE_2, NODE_4, -y21); setY (NODE_4, NODE_2, -y21);
182  }
183 }
184 
185 void twistedpair::calcNoiseAC (nr_double_t) {
186  if (len < 0) return;
187  // calculate noise using Bosma's theorem
188  nr_double_t T = getPropertyDouble ("Temp");
189  setMatrixN (4 * kelvin (T) / T0 * real (getMatrixY ()));
190 }
191 
192 void twistedpair::initTR (void) {
193  initDC ();
194 }
195 
196 // properties
197 PROP_REQ [] = {
198  { "d", PROP_REAL, { 0.5e-3, PROP_NO_STR }, PROP_POS_RANGEX },
199  { "D", PROP_REAL, { 0.8e-3, PROP_NO_STR }, PROP_POS_RANGEX },
200  { "L", PROP_REAL, { 1500e-3, PROP_NO_STR }, PROP_NO_RANGE },
201  { "T", PROP_REAL, { 100, PROP_NO_STR }, PROP_POS_RANGE },
202  { "er", PROP_REAL, { 4, PROP_NO_STR }, PROP_RNGII (1, 100) },
203  { "mur", PROP_REAL, { 1, PROP_NO_STR }, PROP_RNGII (1, 100) },
204  { "tand", PROP_REAL, { 4e-4, PROP_NO_STR }, PROP_POS_RANGE },
205  { "rho", PROP_REAL, { 0.022e-6, PROP_NO_STR }, PROP_POS_RANGE },
206  PROP_NO_PROP };
207 PROP_OPT [] = {
208  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
209  PROP_NO_PROP };
210 struct define_t twistedpair::cirdef =