Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
phaseshifter.cpp
Go to the documentation of this file.
1 /*
2  * phaseshifter.cpp - phase shifter class implementation
3  *
4  * Copyright (C) 2004, 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 "phaseshifter.h"
31 
32 using namespace qucs;
33 
34 phaseshifter::phaseshifter () : circuit (2) {
35  type = CIR_PHASESHIFTER;
36 }
37 
38 void phaseshifter::initSP (void) {
39  nr_double_t p = rad (getPropertyDouble ("phi"));
40  nr_double_t z = getPropertyDouble ("Zref");
41  nr_double_t r = (z0 - z) / (z0 + z);
42  nr_complex_t d = 1.0 - qucs::polar (r * r, 2 * p);
43  nr_complex_t s11 = r * (qucs::polar (1.0, 2 * p) - 1.0) / d;
44  nr_complex_t s21 = (1.0 - r * r) * qucs::polar (1.0, p) / d;
45  allocMatrixS ();
46  setS (NODE_1, NODE_1, s11);
47  setS (NODE_2, NODE_2, s11);
48  setS (NODE_1, NODE_2, s21);
49  setS (NODE_2, NODE_1, s21);
50 }
51 
52 void phaseshifter::initDC (void) {
54  allocMatrixMNA ();
55  clearY ();
57 }
58 
59 void phaseshifter::initAC (void) {
60  nr_double_t p = rad (getPropertyDouble ("phi"));
61 
62  if (p == 0.0) { // no phase shift, thus a short
63  initDC ();
64  }
65  else { // compute Y-parameters directly
67  allocMatrixMNA ();
68  nr_double_t z = getPropertyDouble ("Zref");
69  nr_double_t y11 = 1 / z / std::tan (p);
70  nr_double_t y21 = -1 / z / std::sin (p);
71  setY (NODE_1, NODE_1, nr_complex_t (0, y11)); setY (NODE_2, NODE_2, nr_complex_t (0, y11));
72  setY (NODE_1, NODE_2, nr_complex_t (0, y21)); setY (NODE_2, NODE_1, nr_complex_t (0, y21));
73  }
74 }
75 
76 // properties
77 PROP_REQ [] = {
78  { "phi", PROP_REAL, { 1e-90, PROP_NO_STR }, PROP_NO_RANGE },
79  PROP_NO_PROP };
80 PROP_OPT [] = {
81  { "Zref", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
82  PROP_NO_PROP };
83 struct define_t phaseshifter::cirdef =
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define PROP_POS_RANGE
Definition: netdefs.h:129
void clearY(void)
Definition: circuit.cpp:740
#define NODE_2
Definition: circuit.h:35
void initSP(void)
placehoder for S-Parameter initialisation function
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define PROP_NO_RANGE
Definition: netdefs.h:126
#define PROP_NO_STR
Definition: netdefs.h:125
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
#define VSRC_1
Definition: circuit.h:40
void initAC(void)
nr_complex_t sin(const nr_complex_t z)
Compute complex sine.
Definition: complex.cpp:66
PROP_REQ[]
#define PROP_COMPONENT
Definition: netdefs.h:116
PROP_OPT[]
#define rad(x)
Convert degree to radian.
Definition: constants.h:118
type
Definition: parse_vcd.y:164
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
void allocMatrixMNA(void)
Definition: circuit.cpp:267
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
nr_complex_t tan(const nr_complex_t z)
Compute complex tangent.
Definition: complex.cpp:75
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
nr_complex_t polar(const nr_double_t mag, const nr_double_t ang)
Construct a complex number using polar notation.
Definition: complex.cpp:551
void initDC(void)
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118