-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCircuit.h
More file actions
195 lines (150 loc) · 6.07 KB
/
Circuit.h
File metadata and controls
195 lines (150 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#pragma once
// Header file for the Circuit.cpp class which contains
// all the circuit parameters
#include "MyMatrixTypes.h"
#include <iostream>
#include "ProjectSettings.h"
//Use the namespace in projectsettings.h
using namespace constants;
class Circuit
{
public: //access control
//Default Constructor
//Circuit();
//Constructor with samplerate as an argument
Circuit(double _sampleRate);
//Default Destructor
~Circuit();
//The samplerate of the system
double sampleRate;
double getSaturationCurrent(); //returns the circuit's saturation current IS
double getThermalVoltage(); //returns the circuit's thermal voltage VT
double Circuit::getCircuitSampleRate(); //returns the samplerate
//Method to set the fuzz and vol params to the arguement vals.
void setParams(double _fuzzVal, double _volVal);
//Declare variables for the individual elements of the matrices which cause zipper noise, where cTarget13 = C(1,3) etc.
double aTarget22, cTarget13, cTarget23, kTarget33, kTarget34, kTarget44;
//Update the values causing zipper noise with smoothed values each sample
void updateZipperMatrices();
void updateZipperTargets();
//the smoothed values
double aStore22, cStore13, cStore23, kStore33, kStore34, kStore44;
//the coefficient which governs the smoothing of zipper matrix values
double kCoeff;
double getFuzz(); //returns the fuzz parameter
double getVol(); //returns the volume parameter
//Declare the statespace terms and their constant elements
StateSpaceA stateSpaceA;
StateSpaceB stateSpaceB;
StateSpaceC stateSpaceC;
StateSpaceD stateSpaceD;
StateSpaceE stateSpaceE;
StateSpaceF stateSpaceF;
StateSpaceG stateSpaceG;
StateSpaceH stateSpaceH;
StateSpaceK stateSpaceK;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW //Aligns all the Eigen Members in the class to avoid memory allocation errors... see https://eigen.tuxfamily.org/dox/group__TopicUnalignedArrayAssert.html & https://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html
protected:
/*Accessors and Mutators*/
//Fuzz
void setFuzz(double _fuzz); //function used to set fuzz paramater
void setVol(double _vol); //function used to set volume parameter
void refreshFullCircuit(); //Refresh All matrices, call when paramater change needs to be implemented
//sets the samplerate and updates the matrices
void setCircuitSampleRate(double _sampleRate);
//Declare the statespace terms and their constant elements
StateSpaceA stateSpaceA0;
StateSpaceB stateSpaceB0;
StateSpaceC stateSpaceC0;
StateSpaceD stateSpaceD0;
StateSpaceE stateSpaceE0;
StateSpaceF stateSpaceF0;
StateSpaceG stateSpaceG0;
StateSpaceH stateSpaceH0;
StateSpaceK stateSpaceK0;
//Declare the constant state space terms used in Holters method
StateSpaceQ stateSpaceQ;
StateSpaceUx stateSpaceUx;
StateSpaceUo stateSpaceUo;
StateSpaceUn stateSpaceUn;
StateSpaceUu stateSpaceUu;
//Sample period
double samplePeriod;
//PNP Bipolar Junction Transistor Values
double forwardGain; //200 or 110
double forwardGain2;
double reverseGain;
double thermalVoltage;
double saturationCurrent;
/*
* Nonlinear function matrices, set as 4x4 matrices
*/
NonlinearFunctionMatrix psi; //Ebers-moller term
NonlinearFunctionMatrix phi; //Ebers-moller term
NonlinearFunctionMatrix nonLinEquationMatrix; //Nonlinear equation matrix (MATLAB - M)
NonlinearFunctionMatrix alteredStateSpaceK; //Kd is an altered form of the K statespace matrix (MATLAB - kd)
private: //access control
//Initialise all the circuit values r1,r2 etc etc
void initialiseValues();
double fuzz; //value for the fuzz parameter
double vol; //value for the vol parameter
//potentiometer resistances
double volPotRes;
double fuzzPotRes;
double volPotVar1, volPotVar2, fuzzPotVar1, fuzzPotVar2; //Variables for the potentiometer
//Resistors Values
double r1;
double r2 ;
double r3;
double r4;
double r5;
double r6;
double r7;
double r8;
//Capacitors Values
double c1;
double c2;
double c3;
//Initial setup functions
void setupCircuit();
/*Circuit matrices*/
void populateComponentMatrices(); //populate circuit component matrices, performed at setup
void refreshPotentiometerMatrices(); //update the circuit matrices
//Potentiometer Matrices
PotMatrix potMatrix; //1row 4 col - potentiometer matrix
DiagPot diagPotMatrix; //diagonal - pot matrix
//Resistor Matrices
ResMatrix resMatrix; //1row 8col - resistor matrix
DiagRes diagResMatrix; //diagonal - resistor matrix
//Capacitor Matrices
CapMatrix capMatrix; //1row 3col - capacitor matrix
DiagCap diagCapMatrix; //diagonal - capacitor matrix
/*Incident Matrices*/
void initialiseIncidentMatrices(); //One time setup of incident matrices, this is performed in the constructor and sets up the incident matrices
IncidentPot incidentPot; //incident potentiometer matrix
IncidentRes incidentResistors; //incident resistor matrix
IncidentCap incidentCapacitors; //incident capacitor matrix
IncidentVoltage incidentVoltage; //incident voltage matrix
IncidentNonLin incidentNonlinearities; //incident nonlinearity matrix
IncidentOutput incidentOutput; //incident output matrix
/**
* State Space Matrices
*/
//Setup functions for the system matrix
IntermediateSystemMatrix systemRes; //Resistor matrix used in calculation of system matrix
IntermediateSystemMatrix systemCap; //Capacitor matrix used in calculation of system matrix
SystemMatrix systemMatrix; //Create a 12x12 system matrix
void populateConstantSystemMatrix(); //function to setup and refrseh the system matrix
//Setup functions for the state space terms
PaddedCap padC; //padded capacitor matrix
PaddedNonLin padNL; //padded nonlinearity matrix
PaddedOutput padO; //padded output matrix
PaddedInput padI; //padded input matrix
PaddedPot padPot; //padded potentiometer matrix
//Populate the constant state space terms
void populateConstantStateSpaceTerms();
//Refresh the nonlinear state space equations with updated fuzz and vol settings
void refreshStateSpace();
//Refresh the nonlinear function matrices
void refreshNonlinearFunctions();
};