LCOV - code coverage report
Current view: top level - src/components - vvnoise.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 0 52 0.0 %
Date: 2015-01-05 16:01:02 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 52 0.0 %

           Branch data     Line data    Source code
       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                 :          0 : vvnoise::vvnoise () : circuit (4) {
      40                 :          0 :   type = CIR_VVNOISE;
      41   [ #  #  #  # ]:          0 :   setVoltageSources (2);
      42                 :          0 : }
      43                 :            : 
      44                 :          0 : void vvnoise::initSP (void) {
      45                 :          0 :   allocMatrixS ();
      46         [ #  # ]:          0 :   setS (NODE_V1P, NODE_V1N, 1.0);
      47         [ #  # ]:          0 :   setS (NODE_V1N, NODE_V1P, 1.0);
      48         [ #  # ]:          0 :   setS (NODE_V2P, NODE_V2N, 1.0);
      49         [ #  # ]:          0 :   setS (NODE_V2N, NODE_V2P, 1.0);
      50                 :          0 : }
      51                 :            : 
      52                 :          0 : void vvnoise::calcNoiseSP (nr_double_t frequency) {
      53                 :          0 :   nr_double_t C = getPropertyDouble ("C");
      54                 :          0 :   nr_double_t e = getPropertyDouble ("e");
      55                 :          0 :   nr_double_t c = getPropertyDouble ("c");
      56                 :          0 :   nr_double_t a = getPropertyDouble ("a");
      57                 :          0 :   nr_double_t k = a + c * qucs::pow (frequency, e);
      58                 :          0 :   nr_double_t u1 = getPropertyDouble ("v1") / k / kB / T0 / 4 / z0;
      59                 :          0 :   nr_double_t u2 = getPropertyDouble ("v2") / k / kB / T0 / 4 / z0;
      60                 :          0 :   nr_double_t cu = C * std::sqrt (u1 * u2);
      61                 :            : 
      62                 :            :   // entries of source 1
      63 [ #  # ][ #  # ]:          0 :   setN (NODE_V1P, NODE_V1P, +u1); setN (NODE_V1N, NODE_V1N, +u1);
      64 [ #  # ][ #  # ]:          0 :   setN (NODE_V1P, NODE_V1N, -u1); setN (NODE_V1N, NODE_V1P, -u1);
      65                 :            :   // entries of source 2
      66 [ #  # ][ #  # ]:          0 :   setN (NODE_V2P, NODE_V2P, +u2); setN (NODE_V2N, NODE_V2N, +u2);
      67 [ #  # ][ #  # ]:          0 :   setN (NODE_V2P, NODE_V2N, -u2); setN (NODE_V2N, NODE_V2P, -u2);
      68                 :            :   // correlation entries
      69 [ #  # ][ #  # ]:          0 :   setN (NODE_V1P, NODE_V2P, +cu); setN (NODE_V1N, NODE_V2N, +cu);
      70 [ #  # ][ #  # ]:          0 :   setN (NODE_V1P, NODE_V2N, -cu); setN (NODE_V1N, NODE_V2P, -cu);
      71 [ #  # ][ #  # ]:          0 :   setN (NODE_V2P, NODE_V1P, +cu); setN (NODE_V2N, NODE_V1N, +cu);
      72 [ #  # ][ #  # ]:          0 :   setN (NODE_V2P, NODE_V1N, -cu); setN (NODE_V2N, NODE_V1P, -cu);
      73                 :          0 : }
      74                 :            : 
      75                 :          0 : void vvnoise::initDC (void) {
      76                 :          0 :   allocMatrixMNA ();
      77                 :          0 :   voltageSource (VSRC_1, NODE_V1P, NODE_V1N);
      78                 :          0 :   voltageSource (VSRC_2, NODE_V2P, NODE_V2N);
      79                 :          0 : }
      80                 :            : 
      81                 :          0 : void vvnoise::initTR (void) {
      82                 :          0 :   initDC ();
      83                 :          0 : }
      84                 :            : 
      85                 :          0 : void vvnoise::initAC (void) {
      86                 :          0 :   initDC ();
      87                 :          0 : }
      88                 :            : 
      89                 :          0 : void vvnoise::calcNoiseAC (nr_double_t frequency) {
      90                 :          0 :   nr_double_t C = getPropertyDouble ("C");
      91                 :          0 :   nr_double_t e = getPropertyDouble ("e");
      92                 :          0 :   nr_double_t c = getPropertyDouble ("c");
      93                 :          0 :   nr_double_t a = getPropertyDouble ("a");
      94                 :          0 :   nr_double_t k = a + c * qucs::pow (frequency, e);
      95                 :          0 :   nr_double_t u1 = getPropertyDouble ("v1") / k / kB / T0;
      96                 :          0 :   nr_double_t u2 = getPropertyDouble ("v2") / k / kB / T0;
      97                 :          0 :   nr_double_t cu = C * std::sqrt (u1 * u2);
      98 [ #  # ][ #  # ]:          0 :   setN (NODE_5, NODE_5, u1); setN (NODE_6, NODE_6, u2);
      99 [ #  # ][ #  # ]:          0 :   setN (NODE_5, NODE_6, cu); setN (NODE_6, NODE_5, cu);
     100                 :          0 : }
     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 =
     114                 :            :   { "VVnoise", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11