@@ -41,7 +41,16 @@ public class SensorGSR extends AbstractSensor {
4141 private double [] currentGsrRefResistorsKohms = SHIMMER3_GSR_REF_RESISTORS_KOHMS ;
4242 private double [][] currentGsrResistanceKohmsMinMax = SHIMMER3_GSR_RESISTANCE_MIN_MAX_KOHMS ;
4343 private int currentGsrUncalLimitRange3 = GSR_UNCAL_LIMIT_RANGE3 ;
44-
44+ private double currentGsrAmplifierRefVoltage = GSR_AMPLIFIER_REF_VOLTAGE ;
45+
46+ /**
47+ * The voltage on the GSR amplifier's non-inverting input, which the amplifier equation divides
48+ * by: 0.5 V on the Shimmer3, the ShimmerGQ and the Verisense GSR+ (SR62). The Verisense Pulse+
49+ * (SR68) and SR61-5/6 front end has its own:
50+ * {@code SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE}.
51+ */
52+ public static final double GSR_AMPLIFIER_REF_VOLTAGE = 0.5 ;
53+
4554 public static final double [] SHIMMER3_GSR_REF_RESISTORS_KOHMS = new double [] {
4655 40.2 , //Range 0
4756 287.0 , //Range 1
@@ -361,7 +370,7 @@ public ObjectCluster processDataCustom(SensorDetails sensorDetails, byte[] senso
361370// gsrAdcValueUnCal = SensorGSR.nudgeGsrADC(gsrAdcValueUnCal, currentGSRRange);
362371
363372 //...and on ranges 0-2 too, where only the resistance changes (DEV-1070)
364- gsrResistanceKOhms = SensorGSR .calibrateGsrDataToKOhmsWithOpenCircuitLimit (gsrAdcValueUnCal , currentGSRRange , currentGsrUncalLimitRange3 , microcontrollerAdcProperties , currentGsrRefResistorsKohms );
373+ gsrResistanceKOhms = SensorGSR .calibrateGsrDataToKOhmsWithOpenCircuitLimit (gsrAdcValueUnCal , currentGSRRange , currentGsrUncalLimitRange3 , microcontrollerAdcProperties , currentGsrRefResistorsKohms , currentGsrAmplifierRefVoltage );
365374 gsrResistanceKOhms = SensorGSR .nudgeGsrResistance (gsrResistanceKOhms , getGSRRange (), currentGsrResistanceKohmsMinMax );
366375 gsrConductanceUSiemens = SensorGSR .convertkOhmToUSiemens (gsrResistanceKOhms );
367376// } else {
@@ -602,17 +611,27 @@ public static double calibrateGsrDataToSiemens(double gsrUncalibratedData, doubl
602611 return gsrCalibratedData ;
603612 }
604613
605- /** Based on circuit theory of the GSR non-inverting amplifier.
606- *
614+ /** Based on circuit theory of the GSR non-inverting amplifier, with the 0.5 V reference of the
615+ * Shimmer3, the ShimmerGQ and the Verisense GSR+ (SR62).
616+ *
607617 * @param gsrUncalibratedData
608618 * @param range
609- * @param microcontrollerAdcProperties
619+ * @param microcontrollerAdcProperties
610620 * @return
611621 */
612622 public static double calibrateGsrDataToKOhmsUsingAmplifierEq (double gsrUncalibratedData , int range , MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties , double [] gsrRefResistorsKohms ){
623+ return calibrateGsrDataToKOhmsUsingAmplifierEq (gsrUncalibratedData , range , microcontrollerAdcProperties , gsrRefResistorsKohms , GSR_AMPLIFIER_REF_VOLTAGE );
624+ }
625+
626+ /** Based on circuit theory of the GSR non-inverting amplifier: R = Rf / (V / Vref - 1).
627+ *
628+ * @param gsrAmplifierRefVoltage the front end's amplifier reference: {@link #GSR_AMPLIFIER_REF_VOLTAGE},
629+ * or {@code SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE} on gen-2
630+ */
631+ public static double calibrateGsrDataToKOhmsUsingAmplifierEq (double gsrUncalibratedData , int range , MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties , double [] gsrRefResistorsKohms , double gsrAmplifierRefVoltage ){
613632 double rFeedback = gsrRefResistorsKohms [range ];
614633 double volts = SensorADC .calibrateAdcChannelToVolts (gsrUncalibratedData , microcontrollerAdcProperties );
615- double rSource = rFeedback /((volts /0.5 )-1.0 );
634+ double rSource = rFeedback /((volts /gsrAmplifierRefVoltage )-1.0 );
616635 return rSource ;
617636 }
618637
@@ -622,7 +641,7 @@ public static double calibrateGsrDataToKOhmsUsingAmplifierEq(double gsrUncalibra
622641 * <p>
623642 * The amplifier equation has no positive solution at or below the amplifier's reference: no skin
624643 * resistance can pull the output under it, so a code there means the electrodes are open. Range 3
625- * has long raised such a code to its open-circuit limit, the first code above the reference, so
644+ * has long raised such a code to its open-circuit limit, a code just above the reference, so
626645 * that an open circuit decodes as thousands of MOhm. Ranges 0-2 did not, and in auto-range they
627646 * see these codes too. When the electrodes come off, the device climbs one range at a time, and
628647 * the firmware repeats the sample that triggered each switch through the 80 ms settling time,
@@ -641,17 +660,32 @@ public static double calibrateGsrDataToKOhmsUsingAmplifierEq(double gsrUncalibra
641660 * or {@code SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_UNCAL_LIMIT_RANGE3} on gen-2
642661 */
643662 public static double calibrateGsrDataToKOhmsWithOpenCircuitLimit (double gsrUncalibratedData , int range , int gsrUncalLimitRange3 , MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties , double [] gsrRefResistorsKohms ){
663+ return calibrateGsrDataToKOhmsWithOpenCircuitLimit (gsrUncalibratedData , range , gsrUncalLimitRange3 , microcontrollerAdcProperties , gsrRefResistorsKohms , GSR_AMPLIFIER_REF_VOLTAGE );
664+ }
665+
666+ /**
667+ * {@link #calibrateGsrDataToKOhmsWithOpenCircuitLimit(double, int, int, MICROCONTROLLER_ADC_PROPERTIES, double[])}
668+ * with the front end's own amplifier reference.
669+ */
670+ public static double calibrateGsrDataToKOhmsWithOpenCircuitLimit (double gsrUncalibratedData , int range , int gsrUncalLimitRange3 , MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties , double [] gsrRefResistorsKohms , double gsrAmplifierRefVoltage ){
644671 if (gsrUncalibratedData <gsrUncalLimitRange3 ) {
645- return calibrateGsrDataToKOhmsUsingAmplifierEq (gsrUncalLimitRange3 , 3 , microcontrollerAdcProperties , gsrRefResistorsKohms );
672+ return calibrateGsrDataToKOhmsUsingAmplifierEq (gsrUncalLimitRange3 , 3 , microcontrollerAdcProperties , gsrRefResistorsKohms , gsrAmplifierRefVoltage );
646673 }
647- return calibrateGsrDataToKOhmsUsingAmplifierEq (gsrUncalibratedData , range , microcontrollerAdcProperties , gsrRefResistorsKohms );
674+ return calibrateGsrDataToKOhmsUsingAmplifierEq (gsrUncalibratedData , range , microcontrollerAdcProperties , gsrRefResistorsKohms , gsrAmplifierRefVoltage );
648675 }
649676
650677 /**TODO test method no functioning properly yet
651678 * @param gsrkOhms
652679 * @return
653680 */
654681 public static int uncalibrateGsrDataTokOhmsUsingAmplifierEq (double gsrkOhms , MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties , double [] gsrRefResistorsKohms , double [][] gsrResistanceKohmsMinMax ){
682+ return uncalibrateGsrDataTokOhmsUsingAmplifierEq (gsrkOhms , microcontrollerAdcProperties , gsrRefResistorsKohms , gsrResistanceKohmsMinMax , GSR_AMPLIFIER_REF_VOLTAGE );
683+ }
684+
685+ /**{@link #uncalibrateGsrDataTokOhmsUsingAmplifierEq(double, MICROCONTROLLER_ADC_PROPERTIES, double[], double[][])}
686+ * with the front end's own amplifier reference.
687+ */
688+ public static int uncalibrateGsrDataTokOhmsUsingAmplifierEq (double gsrkOhms , MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties , double [] gsrRefResistorsKohms , double [][] gsrResistanceKohmsMinMax , double gsrAmplifierRefVoltage ){
655689 int range = 0 ;
656690 for (int i =0 ;i <gsrResistanceKohmsMinMax .length ;i ++) {
657691 double [] minMax = gsrResistanceKohmsMinMax [i ];
@@ -663,7 +697,7 @@ public static int uncalibrateGsrDataTokOhmsUsingAmplifierEq(double gsrkOhms, MIC
663697 }
664698
665699 double rFeedback = gsrRefResistorsKohms [range ];
666- double volts = ((rFeedback / gsrkOhms ) + 1.0 ) * 0.5 ;
700+ double volts = ((rFeedback / gsrkOhms ) + 1.0 ) * gsrAmplifierRefVoltage ;
667701
668702 int gsrUncalibratedData = SensorADC .uncalibrateAdcChannelFromVolts (volts , microcontrollerAdcProperties );
669703 //Add range
@@ -777,6 +811,15 @@ public void setCurrentGsrUncalLimitRange3(int currentGsrUncalLimitRange3) {
777811 this .currentGsrUncalLimitRange3 = currentGsrUncalLimitRange3 ;
778812 }
779813
814+ public double getCurrentGsrAmplifierRefVoltage () {
815+ return currentGsrAmplifierRefVoltage ;
816+ }
817+
818+
819+ public void setCurrentGsrAmplifierRefVoltage (double currentGsrAmplifierRefVoltage ) {
820+ this .currentGsrAmplifierRefVoltage = currentGsrAmplifierRefVoltage ;
821+ }
822+
780823// @Deprecated
781824// public static boolean isSupportedImprovedGsrCalibration(ShimmerVerObject svo) {
782825// if(svo.compareVersions(HW_ID.SHIMMER_3, FW_ID.SDLOG, 0, 19, 0)
0 commit comments