Qucs-core  0.0.19
phaseshifter.cpp
Go to the documentation of this file.
00001 /*
00002  * phaseshifter.cpp - phase shifter class implementation
00003  *
00004  * Copyright (C) 2004, 2008 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00025 #if HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #include "component.h"
00030 #include "phaseshifter.h"
00031 
00032 using namespace qucs;
00033 
00034 phaseshifter::phaseshifter () : circuit (2) {
00035   type = CIR_PHASESHIFTER;
00036 }
00037 
00038 void phaseshifter::initSP (void) {
00039   nr_double_t p = deg2rad (getPropertyDouble ("phi"));
00040   nr_double_t z = getPropertyDouble ("Zref");
00041   nr_double_t r = (z0 - z) / (z0 + z);
00042   nr_complex_t d = 1.0 - qucs::polar (r * r, 2 * p);
00043   nr_complex_t s11 = r * (qucs::polar (1.0, 2 * p) - 1.0) / d;
00044   nr_complex_t s21 = (1.0 - r * r) * qucs::polar (1.0, p) / d;
00045   allocMatrixS ();
00046   setS (NODE_1, NODE_1, s11);
00047   setS (NODE_2, NODE_2, s11);
00048   setS (NODE_1, NODE_2, s21);
00049   setS (NODE_2, NODE_1, s21);
00050 }
00051 
00052 void phaseshifter::initDC (void) {
00053   setVoltageSources (1);
00054   allocMatrixMNA ();
00055   clearY ();
00056   voltageSource (VSRC_1, NODE_1, NODE_2);
00057 }
00058 
00059 void phaseshifter::initAC (void) {
00060   nr_double_t p = deg2rad (getPropertyDouble ("phi"));
00061 
00062   if (p == 0.0) { // no phase shift, thus a short
00063     initDC ();
00064   }
00065   else { // compute Y-parameters directly
00066     setVoltageSources (0);
00067     allocMatrixMNA ();
00068     nr_double_t z = getPropertyDouble ("Zref");
00069     nr_double_t y11 =  1 / z / std::tan (p);
00070     nr_double_t y21 = -1 / z / std::sin (p);
00071     setY (NODE_1, NODE_1, nr_complex_t (0, y11)); setY (NODE_2, NODE_2, nr_complex_t (0, y11));
00072     setY (NODE_1, NODE_2, nr_complex_t (0, y21)); setY (NODE_2, NODE_1, nr_complex_t (0, y21));
00073   }
00074 }
00075 
00076 // properties
00077 PROP_REQ [] = {
00078   { "phi", PROP_REAL, { 1e-90, PROP_NO_STR }, PROP_NO_RANGE },
00079   PROP_NO_PROP };
00080 PROP_OPT [] = {
00081   { "Zref", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
00082   PROP_NO_PROP };
00083 struct define_t phaseshifter::cirdef =
00084   { "PShift", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };