# LGF_Histogram_DInt (FB / 3.0.3)

Overview

Author: Siemens Digital Industry

## Short description

The histogram shows the frequency distribution of a sample by class. A class describes a value interval in which the individual frequencies are added together. After specifying the number of classes, the class width and the respective class center are calculated. The number of classes is limited to 15.

The distribution is represented as a rectangle around the class mean with the class width and the cumulated frequency as height.

Figure: Distribution

### WinCC-Control

To visualize the Boxplot, the Siemens Industry Online Support offers you a Net-Control, which you can use in conjunction with WinCC Runtime Professional. You can find the controls in the `UserFiles` folder of this library.

Figure: .Net Control "Histogram"

### Block Interface

| LGF_Histogram_DInt (FB) |
--- | --- | ---
Bool |  |  | execute |  | error |  |  | Bool
UInt |  |  | numberOfClasses |  | status |  |  | Word
|  |  |  |  | subFunctionStatus |  |  | Word
|  |  |  |  | histValues |  |  | Array[0..1, 0..#CLASSES_COUNTER_UP_LIMIT] of LReal
|  |  |  |  | axis |  |  | Array[0..3] of LReal
|  |  |  |  | classWidth |  |  | LReal
Array[*] of DInt |  |  | values |  |  | Array[*] of DInt

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
execute | Bool | FALSE | Activation of the calculation with each positive edge.
numberOfClasses | UInt | 0 | Number of desired classes.

### Output parameter

Identifier | Data type | Description
--- | --- | ---
error | Bool | FALSE: No error TRUE: An error occurred during the execution of the FB
status | Word | 16#0000-16#7FFF: Status of the FB 16#8000-16#FFFF: Error identification (see following Table)
subFunctionStatus | Word | Status or return value of called FB's, FC's and system blocks
histValues | Array[0..1, 0..#CLASSES_COUNTER_UP_LIMIT] of LReal | Outputs the calculated values in a two-dimensional array. • `histValues[0,0..14]` displays the relative frequency of the individual classes. • `histValues[1,0..14]` displays the class centers. • If fewer than 15 classes are desired, the array elements that are not required are output with 0.
axis | Array[0..3] of LReal | Specifies the axis values: • Lower X axis value • Upper X axis value • Lower Y axis value • Upper Y axis value
classWidth | LReal | Returns the calculated class width.

### In/Out parameter

Identifier | Data type | Description
--- | --- | ---
values | Array[*] of DInt | The array containing the data series that is to be used for the calculation

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#0000 | STATUS_EXECUTION_FINISHED Status: Execution finished without errors
16#7000 | STATUS_NO_CALL Status: No call of FB. The block waits for activation through the parameter `enable`.
16#7001 | STATUS_FIRST_CALL Status: First call of FB after enabling
16#8600 | ERR_SHELL_SORT Error: Error in command `LGF_ShellSort_DInt`. Check `subFunctionStatus` code
16#9101 | ERR_WRONG_NO_CLASSES Error: Incorrect number of classes. Give the parameter `numberOfClasses` a valid value (1 to 15).

## Functional description

The block sorts the transferred data and calculates the general class width using the transferred class count and data range. The block then counts the values that lie within a class. In order to draw a histogram, the block also calculates the necessary X and Y coordinates.

The elements of the passed array `values` are sorted in ascending order by the block. The `LGF_Shellsort_UDInt` block is used for sorting.

The number of classes can be specified using the following rule of thumb:

Number~of~classes = \sqrt{number~of~elements}

e.g. 100 values --> Number~of~classes = \sqrt{100} = 10

### Formulas

The block uses the following formula to calculate the class width:

classWidth = \frac{max - min}{Number~of~classes}

## Change log

Version & Date | Change description
--- | ---
| 1.0.0 | Siemens Industry Online Support
| 23.11.2018 | First released version
| 2.0.0 | Simatic Systems Support
| 06.11.2019 | Code refactoring, comments added
| 3.0.0 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 3.0.1 | Simatic Systems Support
| 06.04.2021 | Insert documentation
| 3.0.2 | Simatic Systems Support
| 19.11.2024 | Fixed bug for histValues Array
| 3.0.3 | Simatic Systems Support
| 16.07.2025 | Fixed comments and block info header