Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vvnoise.cpp
Go to the documentation of this file.
1 /*
2  * vvnoise.cpp - correlated noise voltage 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 "vvnoise.h"
31 
32 #define NODE_V1P 0
33 #define NODE_V1N 3
34 #define NODE_V2P 1
35 #define NODE_V2N 2
36 
37 using namespace qucs;
38 
39 vvnoise::vvnoise () : circuit (4) {
40  type = CIR_VVNOISE;
41  setVoltageSources (2);
42 }
43 
44 void vvnoise::initSP (void) {
45  allocMatrixS ();
46  setS (NODE_V1P, NODE_V1N, 1.0);
47  setS (NODE_V1N, NODE_V1P, 1.0);
48  setS (NODE_V2P, NODE_V2N, 1.0);
49  setS (NODE_V2N, NODE_V2P, 1.0);
50 }
51 
52 void vvnoise::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 u1 = getPropertyDouble ("v1") / k / kB / T0 / 4 / z0;
59  nr_double_t u2 = getPropertyDouble ("v2") / k / kB / T0 / 4 / z0;
60  nr_double_t cu = C * std::sqrt (u1 * u2);
61 
62  // entries of source 1
63  setN (NODE_V1P, NODE_V1P, +u1); setN (NODE_V1N, NODE_V1N, +u1);
64  setN (NODE_V1P, NODE_V1N, -u1); setN (NODE_V1N, NODE_V1P, -u1);
65  // entries of source 2
66  setN (NODE_V2P, NODE_V2P, +u2); setN (NODE_V2N, NODE_V2N, +u2);
67  setN (NODE_V2P, NODE_V2N, -u2); setN (NODE_V2N, NODE_V2P, -u2);
68  // correlation entries
69  setN (NODE_V1P, NODE_V2P, +cu); setN (NODE_V1N, NODE_V2N, +cu);
70  setN (NODE_V1P, NODE_V2N, -cu); setN (NODE_V1N, NODE_V2P, -cu);
71  setN (NODE_V2P, NODE_V1P, +cu); setN (NODE_V2N, NODE_V1N, +cu);
72  setN (NODE_V2P, NODE_V1N, -cu); setN (NODE_V2N, NODE_V1P, -cu);
73 }
74 
75 void vvnoise::initDC (void) {
76  allocMatrixMNA ();
79 }
80 
81 void vvnoise::initTR (void) {
82  initDC ();
83 }
84 
85 void vvnoise::initAC (void) {
86  initDC ();
87 }
88 
89 void vvnoise::calcNoiseAC (nr_double_t frequency) {
90  nr_double_t C = getPropertyDouble ("C");
91  nr_double_t e = getPropertyDouble ("e");
92  nr_double_t c = getPropertyDouble ("c");
93  nr_double_t a = getPropertyDouble ("a");
94  nr_double_t k = a + c * qucs::pow (frequency, e);
95  nr_double_t u1 = getPropertyDouble ("v1") / k / kB / T0;
96  nr_double_t u2 = getPropertyDouble ("v2") / k / kB / T0;
97  nr_double_t cu = C * std::sqrt (u1 * u2);
98  setN (NODE_5, NODE_5, u1); setN (NODE_6, NODE_6, u2);
99  setN (NODE_5, NODE_6, cu); setN (NODE_6, NODE_5, cu);
100 }
101 
102 // properties
103 PROP_REQ [] = {
104  { "v1", PROP_REAL, { 1e-6, PROP_NO_STR }, PROP_POS_RANGE },
105  { "v2", PROP_REAL, { 1e-6, PROP_NO_STR }, PROP_POS_RANGE },
106  { "C", PROP_REAL, { 0.5, PROP_NO_STR }, PROP_RNGII (-1, 1) },
107  PROP_NO_PROP };
108 PROP_OPT [] = {
109  { "a", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
110  { "c", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE },
111  { "e", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
112  PROP_NO_PROP };
113 struct define_t vvnoise::cirdef =
#define PROP_POS_RANGE
Definition: netdefs.h:129
void calcNoiseAC(nr_double_t)
Definition: vvnoise.cpp:89
#define T0
standard temperature
Definition: constants.h:61
#define PROP_RNGII(f, t)
Definition: netdefs.h:138
#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 calcNoiseSP(nr_double_t)
Definition: vvnoise.cpp:52
#define NODE_V1N
Definition: vvnoise.cpp:33
void allocMatrixS(void)
Definition: circuit.cpp:251
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: vvnoise.cpp:44
#define NODE_6
Definition: circuit.h:39
#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_V1P
Definition: vvnoise.cpp:32
#define PROP_COMPONENT
Definition: netdefs.h:116
PROP_REQ[]
Definition: vvnoise.cpp:103
#define kB
Boltzmann constant ( )
Definition: constants.h:64
PROP_OPT[]
Definition: vvnoise.cpp:108
type
Definition: parse_vcd.y:164
void allocMatrixMNA(void)
Definition: circuit.cpp:267
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
#define NODE_V2N
Definition: vvnoise.cpp:35
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void setN(int, int, nr_complex_t)
Definition: circuit.cpp:597
void initDC(void)
Definition: vvnoise.cpp:75
void initTR(void)
Definition: vvnoise.cpp:81
#define VSRC_2
Definition: circuit.h:41
#define NODE_V2P
Definition: vvnoise.cpp:34
#define NODE_5
Definition: circuit.h:38
void initAC(void)
Definition: vvnoise.cpp:85
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118