Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amplifier.cpp
Go to the documentation of this file.
1 /*
2  * amplifier.cpp - amplifier class implementation
3  *
4  * Copyright (C) 2004, 2008, 2010 Stefan Jahn <stefan@lkcc.org>
5  * Copyright (C) 2008 Michael Margraf <Michael.Margraf@alumni.TU-Berlin.DE>
6  *
7  * This is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this package; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  * $Id$
23  *
24  */
25 
33 #if HAVE_CONFIG_H
34 # include <config.h>
35 #endif
36 
37 #include "component.h"
38 #include "amplifier.h"
39 
40 using namespace qucs;
41 
43 amplifier::amplifier () : circuit (2) {
45 }
46 
60 void amplifier::initSP (void) {
61  nr_double_t g = getPropertyDouble ("G");
62  nr_double_t z1 = getPropertyDouble ("Z1");
63  nr_double_t z2 = getPropertyDouble ("Z2");
64 
65  allocMatrixS ();
66 
67  setS (NODE_1, NODE_1, (z1 - z0) / (z1 + z0));
68  setS (NODE_1, NODE_2, 0);
69  setS (NODE_2, NODE_2, (z2 - z0) / (z2 + z0));
70  setS (NODE_2, NODE_1, 4 * z0 * std::sqrt (z1 * z2) * g / (z1 + z0) / (z2 + z0));
71 }
72 
73 void amplifier::calcNoiseSP (nr_double_t) {
74  nr_double_t g = getPropertyDouble ("G");
75  nr_double_t z2 = getPropertyDouble ("Z2");
76  nr_double_t NF = getPropertyDouble ("NF");
77  setN (NODE_1, NODE_1, 0);
78  setN (NODE_2, NODE_2, 4 * z0 * z2 * sqr (g) * (NF - 1) / sqr (z2 + z0));
79  setN (NODE_1, NODE_2, 0);
80  setN (NODE_2, NODE_1, 0);
81 }
82 
95 void amplifier::initDC (void) {
96  nr_double_t g = getPropertyDouble ("G");
97  nr_double_t z1 = getPropertyDouble ("Z1");
98  nr_double_t z2 = getPropertyDouble ("Z2");
99 
100  allocMatrixMNA ();
101 
102  setY (NODE_1, NODE_1, 1 / z1);
103  setY (NODE_1, NODE_2, 0);
104  setY (NODE_2, NODE_1, -2 * g / std::sqrt (z1 * z2));
105  setY (NODE_2, NODE_2, 1 / z2);
106 }
107 
112 void amplifier::initAC (void) {
113  initDC ();
114 }
115 
116 void amplifier::calcNoiseAC (nr_double_t) {
117  nr_double_t g = getPropertyDouble ("G");
118  nr_double_t z2 = getPropertyDouble ("Z2");
119  nr_double_t NF = getPropertyDouble ("NF");
120  setN (NODE_1, NODE_1, 0);
121  setN (NODE_2, NODE_2, 4 * sqr (g) * (NF - 1) / z2);
122  setN (NODE_1, NODE_2, 0);
123  setN (NODE_2, NODE_1, 0);
124 }
125 
130 void amplifier::initTR (void) {
131  initDC ();
132 }
133 
134 // properties
135 PROP_REQ [] = {
136  { "G", PROP_REAL, { 10, PROP_NO_STR }, PROP_MIN_VAL (1) },
137  PROP_NO_PROP };
138 PROP_OPT [] = {
139  { "Z1", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
140  { "Z2", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
141  { "NF", PROP_REAL, { 1, PROP_NO_STR }, PROP_MIN_VAL (1) },
142  PROP_NO_PROP };
143 struct define_t amplifier::cirdef =
#define PROP_POS_RANGE
Definition: netdefs.h:129
void initAC(void)
Definition: amplifier.cpp:112
#define NODE_2
Definition: circuit.h:35
#define PROP_DEF
Definition: netdefs.h:189
PROP_OPT[]
Definition: acsolver.cpp:232
#define PROP_REAL
Definition: netdefs.h:174
#define PROP_NO_PROP
Definition: netdefs.h:122
#define PROP_NO_STR
Definition: netdefs.h:125
#define PROP_LINEAR
Definition: netdefs.h:120
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
void calcNoiseSP(nr_double_t)
Definition: amplifier.cpp:73
#define PROP_COMPONENT
Definition: netdefs.h:116
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
#define NODE_1
Definition: circuit.h:34
PROP_REQ[]
Definition: acsolver.cpp:229
void initDC(void)
Definition: amplifier.cpp:95
void calcNoiseAC(nr_double_t)
Definition: amplifier.cpp:116
void initTR(void)
Definition: amplifier.cpp:130
void initSP(void)
Definition: amplifier.cpp:60