Line data Source code
1 : /**
2 : * \file KorenTriodeFunction.h
3 : * Heavily inspired by Simulation of a guitar amplifier stage for several triode models (Cohen and Helie)
4 : */
5 :
6 : #ifndef ATK_PREAMPLIFIER_KORENTRIODEFUNCTION_H
7 : #define ATK_PREAMPLIFIER_KORENTRIODEFUNCTION_H
8 :
9 : #include <ATK/Utility/fmath.h>
10 :
11 : #include <cmath>
12 :
13 : namespace ATK
14 : {
15 : /// A simplified tube model, used with TriodeFilter
16 : template <typename DataType_>
17 : class KorenTriodeFunction
18 : {
19 : private:
20 : const DataType_ mu;
21 : const DataType_ K;
22 : const DataType_ Kp;
23 : const DataType_ Kvb;
24 : const DataType_ Kg;
25 : const DataType_ Ex;
26 :
27 : DataType_ muVbeVce;
28 : DataType_ muVbeVce2;
29 :
30 : DataType_ tmp;
31 : DataType_ E2;
32 : DataType_ lnE2;
33 : DataType_ E1;
34 : DataType_ E1_Ex1;
35 : public:
36 : /// For non static models
37 : const DataType_ Cpg;
38 :
39 : /// Compute grid current
40 119011 : DataType_ Lb(DataType_ Vbe, DataType_ Vce)
41 : {
42 119011 : muVbeVce = mu * Vbe + Vce;
43 119011 : if(muVbeVce > 0)
44 : {
45 73465 : muVbeVce2 = std::sqrt(mu * Vbe + Vce);
46 73465 : return K * muVbeVce * muVbeVce2;
47 : }
48 45546 : return 0;
49 : }
50 :
51 : /// Compute grid current derivative relative to the grid cathode voltage
52 119011 : DataType_ Lb_Vbe(DataType_ Vbe, DataType_ Vce)
53 : {
54 119011 : if (muVbeVce > 0)
55 : {
56 73465 : return K * mu * 1.5F * muVbeVce2;
57 : }
58 45546 : return 0;
59 : }
60 :
61 : /// Compute grid current derivative relative to the plate cathode voltage
62 119011 : DataType_ Lb_Vce(DataType_ Vbe, DataType_ Vce)
63 : {
64 119011 : if (muVbeVce > 0)
65 : {
66 73465 : return K * 1.5F * muVbeVce2;
67 : }
68 45546 : return 0;
69 : }
70 :
71 : /// Compute plate current
72 119011 : DataType_ Lc(DataType_ Vbe, DataType_ Vce)
73 : {
74 119011 : if (Vce > 0)
75 : {
76 119011 : tmp = std::sqrt(Kvb + Vce * Vce);
77 119011 : E2 = 1 + fmath::exp(Kp * (1 / mu + Vbe / tmp));
78 119011 : lnE2 = fmath::log(E2);
79 119011 : E1 = Vce / Kp * lnE2;
80 119011 : E1_Ex1 = fmath::pow(E1, Ex - 1);
81 119011 : return 2 / Kg * E1_Ex1 * E1;
82 : }
83 0 : return 0;
84 : }
85 :
86 : /// Compute plate current derivative relative to the grid cathode voltage
87 119011 : DataType_ Lc_Vbe(DataType_ Vbe, DataType_ Vce)
88 : {
89 119011 : if (Vce > 0)
90 : {
91 119011 : DataType_ E1p = Vce / Kp / E2 * (E2 - 1) * Kp / tmp;
92 119011 : return 2 * Ex / Kg * E1_Ex1 * E1p;
93 : }
94 0 : return 0;
95 : }
96 :
97 : /// Compute plate current derivative relative to the plate cathode voltage
98 119011 : DataType_ Lc_Vce(DataType_ Vbe, DataType_ Vce)
99 : {
100 119011 : if (Vce > 0)
101 : {
102 119011 : DataType_ E1p = 1 / Kp * lnE2 - Vce / Kp / E2 * (E2 - 1) * Kp * Vbe * Vce / (tmp * (Kvb + Vce * Vce));
103 119011 : return 2 * Ex / Kg * E1_Ex1 * E1p;
104 : }
105 0 : return 0;
106 : }
107 :
108 : /// Constructor
109 4 : KorenTriodeFunction(DataType_ mu, DataType_ K, DataType_ Kp, DataType_ Kvb, DataType_ Kg, DataType_ Ex, DataType_ Cpg)
110 4 : :mu(mu), K(K), Kp(Kp), Kvb(Kvb), Kg(Kg), Ex(Ex), Cpg(Cpg)
111 : {
112 4 : }
113 :
114 : /// Build a new triode function for a filter (12AX7/ECC83)
115 4 : static KorenTriodeFunction build_standard_function(DataType_ mu = 100, DataType_ K = 1.73e-6, DataType_ Kp = 600, DataType_ Kvb = 300, DataType_ Kg = 1060, DataType_ Ex = 1.4, DataType_ Cpg = 1.7e-12)
116 : {
117 4 : return KorenTriodeFunction(mu, K, Kp, Kvb, Kg, Ex, Cpg);
118 : }
119 :
120 : /// Build a new alternate triode function for a filter (12AX7/ECC83)
121 : static KorenTriodeFunction build_alternate_function_1()
122 : {
123 : return KorenTriodeFunction(93, 1.73e-6, 10000, 0, 1360, 1.4, 1.7e-12);
124 : }
125 : };
126 : }
127 :
128 : #endif
|