This version logs 3 APs and starts correcting the 4th AP and onwards, using an LED light source connected to output(0), if the AP becomes longer then the average of the 3 that has been recorded.
*/
#include<APqr8.h>
#include<math.h>
#include<vector>
...
...
@@ -85,7 +80,6 @@ STATE: non-modifiable variable in the code
{"Iout (pA)","Output current (pA)",DefaultGUIModel::OUTPUT,},
{"iAP","ideal AP",DefaultGUIModel::OUTPUT,},
{"Cm (pF)","pF",DefaultGUIModel::PARAMETER
|DefaultGUIModel::DOUBLE,},
{"V_cutoff (mV)","Threshold potential for the detection of the beginning of an AP, together with Slope_thresh",DefaultGUIModel::PARAMETER|DefaultGUIModel::DOUBLE,},
{"Period (ms)","Period (ms)",DefaultGUIModel::STATE,},// To check that the period taken by the algorithm is the same as the one i nthe control panel module
{"Time (ms)","Time (ms)",DefaultGUIModel::STATE,},// To check that the algorithm is running
{"APs2","APs",DefaultGUIModel::STATE,},// To check whether APs are being logged and the counter increases
{"BCL2","BCL",DefaultGUIModel::STATE,},// To check what the eventual BCL of the ideal AP has become. You can see then if the APs were logged correctly
{"act2","0 or 1",DefaultGUIModel::STATE,},// Switches from 0 to 1 and back continuously as a check to see whether you are computing error values and corrected values
if((Vm_diff_log[count-1]/Vm_diff_log[count])<0)//they have the opposite sign, so an overshoot occured
// This statement is entered whenever an update is needed in the resistance.
// The if conditions measure the following:
// 1) Whether correction adaptation is on
// 2) Whether currently there is correction going on
// 3) whether we are not in the very first step (gives errors)
// 4) whether the current error is larger than the noise threshold
if((Vm_diff_log[count-1]/Vm_diff_log[count])<0)
{
Rm=Rm*Rm_corr_up;
// This statement is entered whenever two consecutive error values have
// an opposite sign. This means that an overshoot in correction occurred.
// Therefore Iout should become less, and hence Rm should be increased.
Rm=Rm*Rm_corr_up;// Increase the resistance
}
if(abs(Vm_diff_log[count-1])<abs(Vm_diff_log[count])&&(Vm_diff_log[count-1]/Vm_diff_log[count])>0)//the difference is getting larger, so increase current