Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ivnoise.cpp
Go to the documentation of this file.
1 /*
2  * ivnoise.cpp - correlated noise sources class implementation
3  *
4  * Copyright (C) 2005, 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 "ivnoise.h"
31 
32 #define NODE_I1P 0
33 #define NODE_I1N 3
34 #define NODE_V2P 1
35 #define NODE_V2N 2
36 
37 using namespace qucs;
38 
39 ivnoise::ivnoise () : circuit (4) {
40  type = CIR_IVNOISE;
41  setVoltageSources (1);
42 }
43 
44 void ivnoise::initSP (void) {
45  allocMatrixS ();
46  setS (NODE_I1P, NODE_I1P, 1.0);
47  setS (NODE_I1N, NODE_I1N, 1.0);
48  setS (NODE_V2P, NODE_V2N, 1.0);
49  setS (NODE_V2N, NODE_V2P, 1.0);
50 }
51 
52 void ivnoise::calcNoiseSP (nr_double_t frequency) {
53  nr_double_t C = getPropertyDouble ("C");
54  nr_double_t e = getPropertyDouble ("e");
55  nr_double_t c = getPropertyDouble ("c");
56  nr_double_t a = getPropertyDouble ("a");
57  nr_double_t k = a + c * qucs::pow (frequency, e);
58  nr_double_t i1 = getPropertyDouble ("i1") / k / kB / T0;
59  nr_double_t u2 = getPropertyDouble ("v2") / k / kB / T0;
60  nr_double_t ci = C * std::sqrt (i1 * u2) / 2;
61 
62  // entries of source 1
63  setN (NODE_I1P, NODE_I1P, +i1 * z0); setN (NODE_I1N, NODE_I1N, +i1 * z0);
64  setN (NODE_I1P, NODE_I1N, -i1 * z0); setN (NODE_I1N, NODE_I1P, -i1 * z0);
65  // entries of source 2
66  setN (NODE_V2P, NODE_V2P, +u2 /4/z0); setN (NODE_V2N, NODE_V2N, +u2 /4/z0);
67  setN (NODE_V2P, NODE_V2N, -u2 /4/z0); setN (NODE_V2N, NODE_V2P, -u2 /4/z0);
68  // correlation entries
69  setN (NODE_I1P, NODE_V2P, +ci); setN (NODE_I1N, NODE_V2N, +ci);
70  setN (NODE_I1P, NODE_V2N, -ci); setN (NODE_I1N, NODE_V2P, -ci);
71  setN (NODE_V2P, NODE_I1P, +ci); setN (NODE_V2N, NODE_I1N, +ci);
72  setN (NODE_V2P, NODE_I1N, -ci); setN (NODE_V2N, NODE_I1P, -ci);
73 }
74 
75 void ivnoise::initDC (void) {
76  allocMatrixMNA ();
78 }
79 
80 void ivnoise::initAC (void) {
81  initDC ();
82 }
83 
84 void ivnoise::initTR (void) {
85  initDC ();
86 }
87 
88 void ivnoise::calcNoiseAC (nr_double_t frequency) {
89  nr_double_t C = getPropertyDouble ("C");
90  nr_double_t e = getPropertyDouble ("e");
91  nr_double_t c = getPropertyDouble ("c");
92  nr_double_t a = getPropertyDouble ("a");
93  nr_double_t k = a + c * qucs::pow (frequency, e);
94  nr_double_t i1 = getPropertyDouble ("i1") / k / kB / T0;
95  nr_double_t u2 = getPropertyDouble ("v2") / k / kB / T0;
96  nr_double_t ci = C * std::sqrt (i1 * u2);
97  setN (NODE_I1P, NODE_I1P, +i1); setN (NODE_I1N, NODE_I1N, +i1);
98  setN (NODE_I1P, NODE_I1N, -i1); setN (NODE_I1N, NODE_I1P, -i1);
99  setN (NODE_5, NODE_I1P, ci);
100  setN (NODE_I1P, NODE_5, ci);
101  setN (NODE_5, NODE_5, u2);
102 }
103 
104 // properties
105 PROP_REQ [] = {
106  { "i1", PROP_REAL, { 1e-6, PROP_NO_STR }, PROP_POS_RANGE },
107  { "v2", PROP_REAL, { 1e-6, PROP_NO_STR }, PROP_POS_RANGE },
108  { "C", PROP_REAL, { 0.5, PROP_NO_STR }, PROP_RNGII (-1, 1) },
109  PROP_NO_PROP };
110 PROP_OPT [] = {
111  { "a", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
112  { "c", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE },
113  { "e", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
114  PROP_NO_PROP };
115 struct define_t ivnoise::cirdef =
void calcNoiseAC(nr_double_t)
Definition: ivnoise.cpp:88
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define T0
standard temperature
Definition: constants.h:61
#define PROP_RNGII(f, t)
Definition: netdefs.h:138
#define NODE_I1P
Definition: ivnoise.cpp:32
PROP_NO_SUBSTRATE
Definition: ivnoise.cpp:116
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
nr_complex_t pow(const nr_complex_t z, const nr_double_t d)
Compute power function with real exponent.
Definition: complex.cpp:238
#define C(c)
Definition: eqndefined.cpp:73
#define PROP_REAL
Definition: netdefs.h:174
#define PROP_NO_PROP
Definition: netdefs.h:122
#define PROP_NO_STR
Definition: netdefs.h:125
void initDC(void)
Definition: ivnoise.cpp:75
void allocMatrixS(void)
Definition: circuit.cpp:251
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
i1
Definition: parse_citi.y:148
#define VSRC_1
Definition: circuit.h:40
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
#define NODE_I1N
Definition: ivnoise.cpp:33
#define PROP_COMPONENT
Definition: netdefs.h:116
PROP_REQ[]
Definition: ivnoise.cpp:105
#define kB
Boltzmann constant ( )
Definition: constants.h:64
PROP_OPT[]
Definition: ivnoise.cpp:110
type
Definition: parse_vcd.y:164
void allocMatrixMNA(void)
Definition: circuit.cpp:267
#define NODE_V2N
Definition: ivnoise.cpp:35
void initAC(void)
Definition: ivnoise.cpp:80
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: ivnoise.cpp:44
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void initTR(void)
Definition: ivnoise.cpp:84
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void setN(int, int, nr_complex_t)
Definition: circuit.cpp:597
void calcNoiseSP(nr_double_t)
Definition: ivnoise.cpp:52
#define NODE_5
Definition: circuit.h:38
#define NODE_V2P
Definition: ivnoise.cpp:34