/** * Compute the value for the function. * See {@link PolynomialSplineFunction} for details on the algorithm for * computing the value of the function. * * @param v Point for which the function value should be computed. * @return the value. * @throws OutOfRangeException if {@code v} is outside of the domain of the * spline function (smaller than the smallest knot point or larger than the * largest knot point). */ public double value(double v) { if (v < knots[0] || v > knots[n]) { throw new OutOfRangeException(v, knots[0], knots[n]); } int i = Arrays.binarySearch(knots, v); if (i < 0) { i = -i - 2; } // This will handle the case where v is the last knot value // There are only n-1 polynomials, so if v is the last knot // then we will use the last polynomial to calculate the value. if ( i >= polynomials.length ) { i--; } return polynomials[i].value(v - knots[i]); }
/** {@inheritDoc} * @since 3.1 */ public DerivativeStructure value(final DerivativeStructure t) { final double t0 = t.getValue(); if (t0 < knots[0] || t0 > knots[n]) { throw new OutOfRangeException(t0, knots[0], knots[n]); } int i = Arrays.binarySearch(knots, t0); if (i < 0) { i = -i - 2; } // This will handle the case where t is the last knot value // There are only n-1 polynomials, so if t is the last knot // then we will use the last polynomial to calculate the value. if ( i >= polynomials.length ) { i--; } return polynomials[i].value(t.subtract(knots[i])); }
public double[] fixValue(double[] val) { double[] calcData = new double[val.length]; if (resolution == 12) for (int i = 0; i < val.length; i++) calcData[i] = calibration_ref196 * (analogInputSource.calPoly12.value(val[i])); else for (int i = 0; i < val.length; i++) calcData[i] = calibration_ref196 * (analogInputSource.calPoly10.value(val[i])); return calcData; }
boolean conservativeInRange(double val) { double solution = voltToCode12.value(val); return solution >= 50 && solution <= 4000; }
boolean inRange(double val) { double sum = voltToCode12.value(val); return sum >= 50 && sum <= 4095; }
public double[] cal10(double[] RAW) { double[] calcData = new double[RAW.length]; for (int i = 0; i < RAW.length; i++) { RAW[i] *= 4095 / 1023; double avg_shifts = (adc_shifts.get((int) Math.floor(RAW[i])) + adc_shifts.get((int) Math.ceil(RAW[i]))) / 2; RAW[i] -= 4095 * avg_shifts / 3.3; calcData[i] = (polynomials.get((int) gain).value(RAW[i])); } return calcData; } }
public double[] cal12(double[] RAW) { double[] calcData = new double[RAW.length]; for (int i = 0; i < RAW.length; i++) { double avg_shifts = (adc_shifts.get((int) Math.floor(RAW[i])) + adc_shifts.get((int) Math.ceil(RAW[i]))) / 2; RAW[i] -= 4095 * avg_shifts / 3.3; calcData[i] = (polynomials.get((int) gain).value(RAW[i])); } return calcData; }
public double setVoltage(String name, double val) { DACChannel dacChannel = chans.get(name); int v = (int) (Math.round(dacChannel.VToCode.value(val))); return setRawVoltage(name, v); }
public double setCurrent(float val) { DACChannel dacChannel = chans.get("PCS"); int v = (int) (Math.round(dacChannel.VToCode.value(val))); return setRawVoltage("PCS", v); }
private double getAverageVoltage(String channelName, Integer sample) { if (sample == null) sample = 1; PolynomialFunction poly; double sum = 0; poly = analogInputSources.get(channelName).calPoly12; ArrayList<Double> vals = new ArrayList<>(); for (int i = 0; i < sample; i++) { vals.add(getRawAverageVoltage(channelName)); } for (int j = 0; j < vals.size(); j++) { sum = sum + poly.value(vals.get(j)); } return sum / 2 * vals.size(); }
private double setRawVoltage(String name, int v) { DACChannel CHAN = chans.get(name); int val; if (v <= 0) { v = 0; } else if (v >= 4095) { v = 4095; } val = CHAN.applyCalibration(v); try { i2c.writeBulk(addr, new int[]{64 | (CHAN.channum << 1), (val >> 8) & 0x0F, val & 0xFF}); } catch (IOException e) { e.printStackTrace(); } this.values.put(name, CHAN.CodeToV.value(v)); return this.values.get(name); }
private boolean fetchData(String chan) throws IOException, InterruptedException { while (true) { int stat = readRegister(STATUS); if ((stat & 0x80) == 1) { float data = readData(); data = convertUniPolar(data); List channelList = Collections.singletonList(chan); if ((int) channelList.get(3) > 4) { data = (data - 3.3f / 2) * 4; } PolynomialFunction function = new PolynomialFunction(caldata.get(chan)); return function.value(data) == 0; } else { Thread.sleep(100); Log.d(TAG, "Increase Delay"); } } }
public void configureTrigger(int channel, String channelName, double voltage, Integer resolution, Integer prescalar) { if (resolution == null) resolution = 10; if (prescalar == null) prescalar = 0; try { mPacketHandler.sendByte(mCommandsProto.ADC); mPacketHandler.sendByte(mCommandsProto.CONFIGURE_TRIGGER); mPacketHandler.sendByte((prescalar << 4) | (1 << channel)); double level; if (resolution == 12) { level = this.analogInputSources.get(channelName).voltToCode12.value(voltage); if (level < 0) level = 0; else if (level > 4095) level = 4095; } else { level = this.analogInputSources.get(channelName).voltToCode10.value(voltage); if (level < 0) level = 0; else if (level > 1023) level = 1023; } if (level > Math.pow(2, resolution - 1)) level = Math.pow(2, resolution - 1); else if (level < 0) level = 0; mPacketHandler.sendInt((int) level); mPacketHandler.getAcknowledgement(); } catch (IOException e) { e.printStackTrace(); } }
double[] yData = new double[DACX.length]; for (int j = 0; j < DACX.length; j++) { yData[j] = fitFunction.value(DACX[j]) - (OFF.get(j) * slope + intercept);
@Override protected double getXValue(double t) { return tx.value(t); }
@Override protected double getYValue(double t) { return ty.value(t); }
/** {@inheritDoc} * @since 3.1 */ public DerivativeStructure value(final DerivativeStructure t) { final double t0 = t.getValue(); if (t0 < knots[0] || t0 > knots[n]) { throw new OutOfRangeException(t0, knots[0], knots[n]); } int i = Arrays.binarySearch(knots, t0); if (i < 0) { i = -i - 2; } // This will handle the case where t is the last knot value // There are only n-1 polynomials, so if t is the last knot // then we will use the last polynomial to calculate the value. if ( i >= polynomials.length ) { i--; } return polynomials[i].value(t.subtract(knots[i])); }
/** {@inheritDoc} * @since 3.1 */ public DerivativeStructure value(final DerivativeStructure t) { final double t0 = t.getValue(); if (t0 < knots[0] || t0 > knots[n]) { throw new OutOfRangeException(t0, knots[0], knots[n]); } int i = Arrays.binarySearch(knots, t0); if (i < 0) { i = -i - 2; } // This will handle the case where t is the last knot value // There are only n-1 polynomials, so if t is the last knot // then we will use the last polynomial to calculate the value. if ( i >= polynomials.length ) { i--; } return polynomials[i].value(t.subtract(knots[i])); }
/** * Fits sampled data to a polynomial function and keeps the fit in memory. * * @param degree * Degree of the polynomial to be fitted * @throws NullArgumentException * if the computed polynomial coefficients were null * @throws NoDataException * if the computed polynomial coefficients were empty */ public void fitPolynomial(final int degree) { final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree); final ArrayList<WeightedObservedPoint> points = new ArrayList<>(); for (int i = 0; i < nPoints; i++) { points.add(new WeightedObservedPoint(1, inputRadii[i], inputCounts[i])); } pFunction = new PolynomialFunction(fitter.fit(points)); fCounts = new double[nPoints]; for (int i = 0; i < nPoints; i++) { fCounts[i] = pFunction.value(inputRadii[i]); } }