Line data Source code
1 : /**
2 : * \file EnhancedKorenTriodeFunction.h
3 : * from Measures and models of real triodes, for the simulation of guitar amplifiers (Cohen and Helie)
4 : * https://hal.archives-ouvertes.fr/hal-00811215
5 : */
6 :
7 : #ifndef ATK_PREAMPLIFIER_ENHANCEDKORENTRIODEFUNCTION_H
8 : #define ATK_PREAMPLIFIER_ENHANCEDKORENTRIODEFUNCTION_H
9 :
10 : #include <ATK/Utility/fmath.h>
11 :
12 : #include <cmath>
13 :
14 : namespace ATK
15 : {
16 : /// A more complex triode model, used with TriodeFilter
17 : template <typename DataType_>
18 : class EnhancedKorenTriodeFunction
19 : {
20 : private:
21 : const DataType_ a;
22 : const DataType_ b;
23 : const DataType_ c;
24 : const DataType_ Vphi;
25 : const DataType_ gamma;
26 :
27 : const DataType_ mu;
28 : const DataType_ Kp;
29 : const DataType_ Vct;
30 : const DataType_ Kvb;
31 : const DataType_ Kvb2;
32 : const DataType_ Kg;
33 : const DataType_ Ex;
34 :
35 : DataType_ exp_comp;
36 : DataType_ ln_exp_comp_1;
37 : DataType_ first_term;
38 :
39 : DataType_ tmp;
40 : DataType_ E2;
41 : DataType_ lnE2;
42 : DataType_ E1;
43 : DataType_ E1_Ex1;
44 :
45 : public:
46 : /// For non static models
47 : const DataType_ Cpg;
48 :
49 : /// Compute grid current
50 14488 : DataType_ Lb(DataType_ Vbe, DataType_ Vce)
51 : {
52 14488 : exp_comp = fmath::exp(a * (Vbe + Vphi));
53 14488 : ln_exp_comp_1 = fmath::log(1 + exp_comp);
54 14488 : first_term = fmath::pow(ln_exp_comp_1, gamma - 1);
55 14488 : return first_term * ln_exp_comp_1 * (1/(b * Vce + 1) + 1/c);
56 : }
57 :
58 : /// Compute grid current derivative relative to the grid cathode voltage
59 14488 : DataType_ Lb_Vbe(DataType_ Vbe, DataType_ Vce)
60 : {
61 14488 : return (1/(b * Vce + 1) + 1/c) * gamma * first_term / (1+exp_comp) * a * exp_comp;
62 : }
63 :
64 : /// Compute grid current derivative relative to the plate cathode voltage
65 14488 : DataType_ Lb_Vce(DataType_ Vbe, DataType_ Vce)
66 : {
67 14488 : return - first_term * ln_exp_comp_1 * b / ((b * Vce + 1)*(b * Vce + 1));
68 : }
69 :
70 : /// Compute plate current
71 14488 : DataType_ Lc(DataType_ Vbe, DataType_ Vce)
72 : {
73 14488 : if (Vce > 0)
74 : {
75 14488 : tmp = std::sqrt(Kvb + Vce * Kvb2 + Vce * Vce);
76 14488 : E2 = 1 + fmath::exp(Kp * (1 / mu + (Vbe + Vct) / tmp));
77 14488 : lnE2 = fmath::log(E2);
78 14488 : E1 = Vce / Kp * lnE2;
79 14488 : E1_Ex1 = fmath::pow(E1, Ex - 1);
80 14488 : return 2 / Kg * E1_Ex1 * E1;
81 : }
82 0 : return 0;
83 : }
84 :
85 : /// Compute plate current derivative relative to the grid cathode voltage
86 14488 : DataType_ Lc_Vbe(DataType_ Vbe, DataType_ Vce)
87 : {
88 14488 : if (Vce > 0)
89 : {
90 14488 : DataType_ E1p = Vce / Kp / E2 * (E2 - 1) * Kp / tmp;
91 14488 : return 2 * Ex / Kg * E1_Ex1 * E1p;
92 : }
93 0 : return 0;
94 : }
95 :
96 : /// Compute plate current derivative relative to the plate cathode voltage
97 14488 : DataType_ Lc_Vce(DataType_ Vbe, DataType_ Vce)
98 : {
99 14488 : if (Vce > 0)
100 : {
101 14488 : DataType_ E1p = 1 / Kp * lnE2 - Vce / Kp / E2 * (E2 - 1) * Kp * (Vbe + Vct) * (2 * Vce + Kvb2) / 2 / (tmp * (Kvb + Vce * Kvb2 + Vce * Vce));
102 14488 : return 2 * Ex / Kg * E1_Ex1 * E1p;
103 : }
104 0 : return 0;
105 : }
106 :
107 : /// Constructor
108 1 : EnhancedKorenTriodeFunction(DataType_ a, DataType_ b, DataType_ c, DataType_ Vphi, DataType_ gamma, DataType_ mu, DataType_ Kp, DataType_ Vct, DataType_ Kvb, DataType_ Kvb2, DataType_ Kg, DataType_ Ex, DataType_ Cpg)
109 1 : :a(a), b(b), c(c), Vphi(Vphi), gamma(gamma), mu(mu), Kp(Kp), Vct(Vct), Kvb(Kvb), Kvb2(Kvb2), Kg(Kg), Ex(Ex), Cpg(Cpg)
110 : {
111 1 : }
112 :
113 : /// Build a new triode function for a filter (12AX7/ECC83)
114 1 : static EnhancedKorenTriodeFunction build_standard_function(DataType_ a = 17.32, DataType_ b = 21238.8, DataType_ c = 163757, DataType_ Vphi = -0.2227, DataType_ gamma = 1.444, DataType_ mu = 105, DataType_ Kp = 578.2, DataType_ Vct = 0.378, DataType_ Kvb = 50, DataType_ Kvb2 = 18.8, DataType_ Kg = 1335, DataType_ Ex = 1.277, DataType_ Cpg = 1.7e-12)
115 : {
116 1 : return EnhancedKorenTriodeFunction(a, b, c, Vphi, gamma, mu, Kp, Vct, Kvb, Kvb2, Kg, Ex, Cpg);
117 : }
118 :
119 : };
120 : }
121 :
122 : #endif
|