Histogram - Generate histogram of input or sequence of inputs

Library

Statistics

dspstat3

Description

The Histogram block computes the frequency distribution of the elements in a vector input, of the elements in each channel of a frame-based matrix input, or of the elements in a sample based N-D array. The Running histogram parameter selects between basic operation and running operation, described below. The Histogram block accepts real and complex fixed-point and floating-point inputs.

The block distributes the elements of the input into the number of discrete bins specified by the Number of bins parameter, n.

y = hist(u,n)					% Equivalent MATLAB code 

Complex fixed-point inputs are distributed according to their magnitude squared values; complex floating-point inputs are distributed by their normalized values.

The histogram value for a given bin represents the frequency of occurrence of the input values bracketed by that bin. You specify the upper boundary of the highest-valued bin in the Upper limit of histogram parameter, BM, and the lower boundary of the lowest-valued bin in the Lower limit of histogram parameter, Bm. The bins have equal width of

and centers located at

Input values that fall on the border between two bins are placed into the lower valued bin; that is, each bin includes its upper boundary. For example, a bin of width 4 centered on the value 5 contains the input value 7, but not the input value 3. Input values greater than the Upper limit of histogram parameter or less than Lower limit of histogram parameter are placed into the highest valued or lowest valued bin, respectively.

The values you enter for the Upper limit of histogram and Lower limit of histogram parameters must be real-valued scalars. NaN and inf are not valid values for the Upper limit of histogram and Lower limit of histogram parameters.

Basic Operation

When the Running histogram check box is not selected, the Histogram block computes the frequency distribution of the current input.

For frame-based M-by-N inputs, (including 1-by-N row vectors and M-by-1 column vectors), the Histogram block computes a histogram for each channel of the M-by-N matrix independently. The block outputs an n-by-N matrix, where n is the Number of bins specified in the Histogram block. The jth column of the output matrix contains the histogram for the data in the jth column of the M-by-N input matrix.

For all sample-based N-D input arrays, including length-M 1-D vectors and 1-by-N row vectors, the Histogram block computes the frequency distribution of the input data. The block outputs an n-by-1 vector, where n is the Number of bins specified in the Histogram block.

Running Operation

When you select the Running histogram check box, the Histogram block computes the frequency distribution of both the past and present data for successive inputs. The block resets the histogram (by emptying all of the bins) when it detects a reset event at the optional Rst port. See Resetting the Running Histogram for more information on how to trigger a reset.

For frame-based M-by-N inputs (including 1-by-N row vectors and M-by-1 column vectors), the Histogram block computes a running histogram for each channel of the M-by-N matrix. The block outputs an n-by-N matrix, where n is the Number of bins specified in the Histogram block. The jth column of the output matrix contains the running histogram for the jth column of the M-by-N input matrix.

For all sample-based N-D input arrays, including length-M 1-D vectors, the Histogram block computes a running histogram for the data in the first dimension of the input. The block outputs an n-by-1 vector, where n is the Number of bins specified in the Histogram block.

Resetting the Running Histogram

The block resets the running histogram whenever a reset event is detected at the optional Rst port. The reset signal and the input data signal must be the same rate.

To enable the Rst port, select the Reset port parameter. You specify the reset event in the Trigger type parameter, and it can be one of the following:

Examples

Real Input Data

The bin boundaries created by the Histogram block are determined by the data type of the input:

The following example shows the differences in the output of the Histogram block based on the data type of the input.

To create this model you need the following blocks.

BlockLibraryQuantity

Constant

Simulink® / Sources library

2

Display

Signal Processing Sinks

2

Histogram

Statistics

2

The parameter settings for the Double Precision Input Constant block are:

The parameter settings for the Fixed-Point Input Constant block are:

The parameter settings for both Histogram blocks are:

Connect the blocks as shown in the following figure, and run your model.

Running this model generates the following warning:

Warning: The bin width resulting from the specified parameters is less than the precision of the input data type. This might cause unexpected results. Since bin width is calculated by ((upper limit - lower limit)/number of bins), you could increase upper limit or decrease lower limit or number of bins.

This warning alerts you that it is not a good use case to have a histogram where 2 or more bin boundaries are the same. As the warning suggests, increasing the range of the limits of the histogram, or decreasing the number of bins, can correct this problem.

The following figures illustrate the different bins that are created by the Histogram block. The top figure shows the histogram for double-precision input, and the bottom figure shows the histogram for fixed-point input. The output of the histogram block differs based on the data type of the input, and the bin boundaries are duplicated in the histogram for the fixed-point input.

Complex Input Data

The bin boundaries created by the Histogram block are determined by the data type of the input.

The following example shows the differences in the bins created by the Histogram block based on the data type of the complex input.

Using the same model you created for the example with real input data, modify the following parameters:

Run your model. It should look similar to the following figure:

In this case, the Histogram block outputs the same result. The figures below illustrate how the Histogram block compares the input values to the bins it creates. The double-precision inputs are normalized for comparison, whereas the fixed-point inputs are placed using their magnitude squared value. The top figure shows the histogram for the double-precision input, and the bottom figure shows the histogram for the fixed-point input.

Dialog Box

The Main pane of the Histogram block dialog appears as follows.

Lower limit of histogram

Enter a real-valued scalar for the lower boundary, Bm, of the lowest-valued bin. NaN and inf are not valid values for Bm. Tunable.

Upper limit of histogram

Enter a real-valued scalar for the upper boundary, BM, of the highest-valued bin. NaN and inf are not valid values for BM. Tunable.

Number of bins

The number of bins, n, in the histogram.

Normalized

When selected, the output vector, v, is normalized such that sum(v) = 1.

Use of this parameter is not supported for fixed-point signals.

Running histogram

Set to enable the running histogram operation, and clear to enable basic histogram operation. For more information, see Basic Operation and Running Operation.

Reset port

Enables the Rst input port when selected. The reset signal and the input data signal must be the same rate. This parameter is enabled only when you set the Running histogram parameter. For more information, see Running Operation.

Trigger type

The type of event that resets the running histogram. For more information, see Resetting the Running Histogram. This parameter is enabled only when you set the Reset port parameter.

The Fixed-point pane of the Histogram block dialog appears as follows.

Rounding mode

Select the rounding mode for fixed-point operations.

Overflow mode

Select the overflow mode for fixed-point operations.

Product output

Use this parameter to specify how you would like to designate the product output word and fraction lengths:

Accumulator

Use this parameter to specify the accumulator word and fraction lengths resulting from a complex-complex multiplication in the block:

Lock scaling against changes by the autoscaling tool

Select this parameter to prevent any fixed-point scaling you specify in this block mask from being overridden by the autoscaling feature of the Fixed-Point Tool. See the fxptdlg reference page for more information.

Supported Data Types

PortSupported Data Types

In

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point (signed and unsigned)

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

Output

  • Double-precision floating point

  • Single-precision floating point

  • 32-bit unsigned integers

Rst

  • Boolean

See Also

SortSignal Processing Blockset
histMATLAB

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS