====== Smart Average ====== {{:en:mervis-ide:35-help:b48.png}} ===== Block name ===== B48_SMART_AVERAGE ===== ST call ===== PROGRAM B48_TEST VAR IN1, IN2, IN3:REAL; FB: LIB.CORE.V1_0.B48_SMART_AVERAGE; END_VAR FB(IN[1]:=IN1, IN[2]:= IN2); O1:= FB.OUT; END_PROGRAM ===== Library ===== LIB\CORE ===== Version ===== V1.1 ===== Description ===== This block is an extension of the [[en:mervis-ide:35-help:035-software_basic:060-libraries:020-basic-analogue-boxes:015-mathematics:015-avg|AVG]] block. The AVG block calculates just the arithmetic average, which may cause problems in field deployment: At sites with 3 or 4 room temperature sensors, which are averaged to obtain a room temperature as an input for a room controller, a sensor may get broken and feed a bad value, e.g. of 150 °C. The plain average temperature is useless, while the problem is difficult to detect. On the other hand, B48 calculates the most probable average temperature by omitting all "out-of-range" values. This is achieved by calculating a median value, M. All input values (X), which are closer to M than the tolerance (tol), are used for average value calculation, while all values outside of the tolerance band are not taken into account. Output BS gives the sign of the OUT value. If OUT>= 0, then BS=TRUE, else BS=FALSE. The BSN output is a negation of BS. If the number of sensors is 3, the block is able to detect one false value. If the number of sensors is 5, the block detects up to 2 false values, etc. Input signals must be enabled by setting the enable variable INENABLED to TRUE (such as inenabled[1]:=true; for the first input IN1). ===== Inputs ===== |Input |Type |Description |Default value | |IN |[[en:mervis-ide:35-help:035-software_basic:060-libraries:015-proto|MULTIIOREAL]]|Input values|[0,0,...,0] | |INENABLED|[[en:mervis-ide:35-help:035-software_basic:060-libraries:015-proto|MULTIIOBOOL]]|Input enable|[False,...,False]| |IN1 |REAL |Input value | | |IN2 |REAL |Input value | | |TOL |REAL |Tolerance |2 | ===== Outputs ===== |Output|Type|Description | |OUT |REAL|Output signal | |VAL |INT |Number of inputs used when calculating the output signal| |INVAL |INT |Number of omitted outputs | |BS |BOOL|Sign of the output signal | |BSN |BOOL|Negation of bs | ===== Application example ===== {{:en:mervis-ide:35-help:b48_example.png}}