Branch data Line data Source code
1 : : /*
2 : : * hybrid.cpp - hybrid class implementation
3 : : *
4 : : * Copyright (C) 2011 Michael Margraf <michael.margraf@alumni.tu-berlin.de>
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 "hybrid.h"
31 : :
32 : : using namespace qucs;
33 : :
34 : 0 : hybrid::hybrid () : circuit (4) {
35 : 0 : type = CIR_HYBRID;
36 : 0 : }
37 : :
38 : :
39 : : //All functions below are obtained from
40 : : //http://qucs.sourceforge.net/tech/node56.html
41 : :
42 : 0 : void hybrid::initSP (void) {
43 : :
44 [ # # ][ # # ]: 0 : nr_complex_t p = qucs::polar (1.0, rad (getPropertyDouble ("phi")));
45 : : //nr_double_t k = std::sqrt(1-pow((1/M_SQRT2),2));
46 : 0 : nr_double_t k = (1/M_SQRT2); //last line reduces to this for 1/std::sqrt(2)
47 : :
48 [ # # ]: 0 : allocMatrixS ();
49 : : //S11 = S22 = S33 = S44 = 0
50 [ # # ][ # # ]: 0 : setS (NODE_1, NODE_1, 0.0); setS (NODE_2, NODE_2, 0.0);
51 [ # # ][ # # ]: 0 : setS (NODE_3, NODE_3, 0.0); setS (NODE_4, NODE_4, 0.0);
52 : : //S14 = S23 = S32 = S41 = 0
53 [ # # ][ # # ]: 0 : setS (NODE_1, NODE_4, 0.0); setS (NODE_2, NODE_3, 0.0);
54 [ # # ][ # # ]: 0 : setS (NODE_3, NODE_2, 0.0); setS (NODE_4, NODE_1, 0.0);
55 : : //S12 = S21 = S34 = S43 = std::sqrt(1-k^2)
56 [ # # ][ # # ]: 0 : setS (NODE_1, NODE_2, k); setS (NODE_2, NODE_1, k);
57 [ # # ][ # # ]: 0 : setS (NODE_3, NODE_4, k); setS (NODE_4, NODE_3, k);
58 : : //S13 = S31 = S24 = S42 = k*exp(j * p)
59 [ # # ][ # # ]: 0 : setS (NODE_1, NODE_3, k * p); setS (NODE_3, NODE_1, k * p);
60 [ # # ][ # # ]: 0 : setS (NODE_2, NODE_4, k * p); setS (NODE_4, NODE_2, k * p);
61 : 0 : }
62 : :
63 : 0 : void hybrid::initDC (void) {
64 : 0 : setVoltageSources (2);
65 : 0 : setInternalVoltageSource (1);
66 : 0 : allocMatrixMNA ();
67 : 0 : voltageSource (VSRC_1, NODE_1, NODE_3);
68 : 0 : voltageSource (VSRC_2, NODE_2, NODE_4);
69 : 0 : }
70 : :
71 : 0 : void hybrid::initAC (void) {
72 : :
73 : 0 : nr_double_t k = 1 / M_SQRT2;
74 : 0 : nr_complex_t y;
75 [ # # ][ # # ]: 0 : nr_complex_t A = k*k*(nr_complex_t(1,0)+qucs::polar(1.0, 2.0*rad (getPropertyDouble ("phi"))));
[ # # ]
76 : 0 : nr_double_t B = 2 * std::sqrt(1-(k*k));
77 [ # # ][ # # ]: 0 : nr_complex_t C = qucs::polar (2*k, rad (getPropertyDouble ("phi")));
78 [ # # ][ # # ]: 0 : nr_complex_t D = getPropertyDouble ("Zref") * ((A*A)-(C*C));
[ # # ][ # # ]
79 : :
80 [ # # ]: 0 : setVoltageSources (0);
81 [ # # ]: 0 : allocMatrixMNA ();
82 : : // d *= getPropertyDouble ("Zref");
83 : :
84 [ # # ][ # # ]: 0 : y = (A*(nr_complex_t(2,0)-A))/D;
[ # # ]
85 [ # # ][ # # ]: 0 : setY (NODE_1, NODE_1, y); setY (NODE_2, NODE_2, y);
86 [ # # ][ # # ]: 0 : setY (NODE_3, NODE_3, y); setY (NODE_4, NODE_4, y);
87 : :
88 [ # # ][ # # ]: 0 : y = (nr_complex_t(-1,0)*A*B)/D;
89 [ # # ][ # # ]: 0 : setY (NODE_1, NODE_2, y); setY (NODE_2, NODE_1, y);
90 [ # # ][ # # ]: 0 : setY (NODE_3, NODE_4, y); setY (NODE_4, NODE_3, y);
91 : :
92 [ # # ][ # # ]: 0 : y = (C*(nr_complex_t(-2,0)+A))/D;
[ # # ]
93 [ # # ][ # # ]: 0 : setY (NODE_1, NODE_3, y); setY (NODE_3, NODE_1, y);
94 [ # # ][ # # ]: 0 : setY (NODE_2, NODE_4, y); setY (NODE_4, NODE_2, y);
95 : :
96 [ # # ]: 0 : y= (B*C)/D;
97 [ # # ][ # # ]: 0 : setY (NODE_1, NODE_4, y); setY (NODE_4, NODE_1, y);
98 [ # # ][ # # ]: 0 : setY (NODE_2, NODE_3, y); setY (NODE_3, NODE_2, y);
99 : :
100 : :
101 : :
102 : 0 : }
103 : :
104 : 0 : void hybrid::initTR (void) {
105 : 0 : initDC ();
106 : 0 : }
107 : :
108 : : // properties
109 : : PROP_REQ [] = {
110 : : { "phi", PROP_REAL, { 0, PROP_NO_STR }, PROP_RNGII (-180, +180) },
111 : : PROP_NO_PROP };
112 : : PROP_OPT [] = {
113 : : { "Zref", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
114 : : PROP_NO_PROP };
115 : : struct define_t hybrid::cirdef =
116 : : { "Hybrid", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
117 : :
|