|
OptoMMP3
|
Piecewise Linearization More...
Public Member Functions | |
| PiecewiseLinear (Int32 i32Length, Boolean bAscendingInput) | |
| Constructor More... | |
| Boolean | SetLookupElement (Int32 i32Index, Double dInput, Double dOutput) |
| Set a lookup element in the piecewise linear table. More... | |
| Boolean | Compute (Double dInput, out Double dOutput, out Boolean bUnderRange, out Boolean bOverRange) |
| Compute the output. More... | |
Piecewise Linearization
Piecewise linearization is typically used for thermocouple, high-temperature resistive and capacitive measurement (where the extreme temperatures cause non-linear responses), non-linear mechanical systems, and converting pressure to tank level (or capacity).
(C#)
// input resistance values of an Omega 44007 probe, the resistance is decending with each next element
// this is an abbreviated table...
Double[] daryR_Input =
{
10960.0, 10440.0, 9951.0, 9486.0, 9046.0, 8628.0, 8232.0, 7857.0,
7500.0, 7162.0, 6841.0, 6536.0, 6247.0, 5972.0, 5710.0, 5462.0,
5225.0, 5000.0, 4787.0, 4583.0, 4389.0, 4204.0, 4029.0, 3861.0,
3702.0, 3549.0, 3404.0, 3266.0, 3134.0, 3008.0, 2888.0, 2773.0,
2663.0, 2559.0, 2459.0, 2363.0, 2272.0, 2184.0, 2101.0, 2021.0,
1944.0, 1871.0, 1801.0, 1244.0, 875.7, 628.1, 458.2, 339.6,
255.4, 194.7, 150.3, 117.4, 92.7
};
// corresponding temperature output for the resistance table.
Double[] daryC_Output =
{
8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0,
16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0,
24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0,
32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0,
40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0,
48.0, 49.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0,
110.0, 120.0, 130.0, 140.0, 150.0
};
// our linearization object, note the false argument to indicate a decreasing input table
PiecewiseLinear piecewise = new PiecewiseLinear(daryR_Input.Length, false);
// initialize the coefficients
for (Int32 i = 0; i < daryR_Input.Length; i++)
{
// set the table element
piecewise.SetLookupElement(i, daryR_Input[i], daryC_Output[i]);
}
Double dResistanceInput;
Double dTemperatureOutput;
Boolean bOverRange;
Boolean bUnderRange;
// 5000 ohms (25C)
dResistanceInput = 5000.00;
piecewise.Compute(dResistanceInput, out dTemperatureOutput, out bUnderRange, out bOverRange);
Console.WriteLine("Probe Resistance of {0} Ohms is {1} C", dResistanceInput.ToString("F2"), dTemperatureOutput.ToString("F2"));
// 9951 ohms (10C)
dResistanceInput = 9951.00;
piecewise.Compute(dResistanceInput, out dTemperatureOutput, out bUnderRange, out bOverRange);
Console.WriteLine("Probe Resistance of {0} Ohms is {1} C", dResistanceInput.ToString("F2"), dTemperatureOutput.ToString("F2"));
// 2663 ohms (40C)
dResistanceInput = 2663.00;
piecewise.Compute(dResistanceInput, out dTemperatureOutput, out bUnderRange, out bOverRange);
Console.WriteLine("Probe Resistance of {0} Ohms is {1} C", dResistanceInput.ToString("F2"), dTemperatureOutput.ToString("F2"));
// 458.2 ohms (90C)
dResistanceInput = 458.2;
piecewise.Compute(dResistanceInput, out dTemperatureOutput, out bUnderRange, out bOverRange);
Console.WriteLine("Probe Resistance of {0} Ohms is {1} C", dResistanceInput.ToString("F2"), dTemperatureOutput.ToString("F2"));
| Opto22.Linearization.PiecewiseLinear.PiecewiseLinear | ( | Int32 | i32Length, |
| Boolean | bAscendingInput | ||
| ) |
Constructor
| i32Length | The length of the table. |
| bAscendingInput | Indicates if the input values ascend with increasing index or not. |
| Boolean Opto22.Linearization.PiecewiseLinear.Compute | ( | Double | dInput, |
| out Double | dOutput, | ||
| out Boolean | bUnderRange, | ||
| out Boolean | bOverRange | ||
| ) |
Compute the output.
| dInput | The input to convert. |
| dOutput | The computed output. If the return is false, this value will be Double.NaN. |
| bUnderRange | If this method returns false, check to see if the input was underrange. |
| bOverRange | If this method returns false, check if the input was overrange. |
| Boolean Opto22.Linearization.PiecewiseLinear.SetLookupElement | ( | Int32 | i32Index, |
| Double | dInput, | ||
| Double | dOutput | ||
| ) |
Set a lookup element in the piecewise linear table.
| i32Index | The index to set. |
| dInput | The input value at this index. |
| dOutput | The output value at this index. |