| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Signal Processing Blockset |
| Contents | Index |
| Learn more about Signal Processing Blockset |
Statistics
dspstat3
The Median block computes the median value of each row or column of the input, along vectors of a specified dimension of the input, or of the entire input. The median of a set of input values is calculated as follows:
The values are sorted.
If the number of values is odd, the median is the middle value.
If the number of values is even, the median is the average of the two middle values.
For a given input u, the size of the output array y depends on the setting of the Find the median value over parameter. For example, consider a 3-dimensional input signal of size M-by-N-by-P:
Entire input — The output at each sample time is a scalar that contains the median value of the M-by-N-by-P input matrix. In this mode, the block output is always sample based.
y = median(u(:)) % Equivalent MATLAB code
Each row — The output at each sample time consists of an M-by-1-by-P array, where each element contains the median value of each vector over the second dimension of the input. For an input that is an M-by-N matrix, the output is an M-by-1 column vector. In this mode, the frame status of the output is the same as that of the input.
y = median(u,2) % Equivalent MATLAB code
Each column — The output at each sample time consists of a 1-by-N-by-P array, where each element contains the median value of each vector over the first dimension of the input. For an input that is an M-by-N matrix, the output at each sample time is a 1-by-N row vector. In this mode, the frame status of the output is the same as that of the input.
y = median(u) % Equivalent MATLAB code
For convenience, length-M 1-D vector inputs are treated as M-by-1 column vectors when the block is in this mode. Sample-based length-M row vector inputs are also treated as M-by-1 column vectors when the Treat sample-based row input as a column check box is selected.
Specified dimension — The output at each sample time depends on Dimension. If Dimension is set to 1, the output is the same as when you select Each column. If Dimension is set to 2, the output is the same as when you select Each row. If Dimension is set to 3, the output at each sample time is an M-by-N matrix containing the median value of each vector over the third dimension of the input. In this mode, the frame status of the output is the same as that of the input.
y = median(u,Dimension) % Equivalent MATLAB code
Complex inputs are sorted by magnitude squared. For complex
value
, the magnitude
squared is a2+b2.
The Median block accepts real and complex fixed-point and floating-point inputs.
For fixed-point inputs, you can specify accumulator, product output, and output data types as discussed in Dialog Box. Not all these fixed-point parameters are applicable for all types of fixed-point inputs. The following table shows when each kind of data type and scaling is used.
| Output data type | Accumulator data type | Product output data type | |
|---|---|---|---|
X | X | ||
X |
| ||
X | X | X | |
X | X | X |
The accumulator and output data types and scalings are used for fixed-point signals when M is even. The result of the sum performed while calculating the average of the two central rows of the input matrix is stored in the accumulator data type and scaling. The total result of the average is then put into the output data type and scaling.
The accumulator and product output parameters are used for complex fixed-point inputs. The sum of the squares of the real and imaginary parts of such an input are formed before the input elements are sorted, as described in Description. The results of the squares of the real and imaginary parts are placed into the product output data type and scaling. The result of the sum of the squares is placed into the accumulator data type and scaling.
For fixed-point inputs that are both complex and have even M, the data types are used in all of the ways described. Therefore, in such cases, the accumulator type is used in two different ways.
The Main pane of the Median block dialog appears as follows.

Specify whether to sort the elements of the input using a Quick sort or an Insertion sort algorithm.
Specify whether to find the median value along rows, columns, entire input, or the dimension specified in the Dimension parameter. For more information, see Description.
Select to treat sample-based length-M row vector inputs as M-by-1 column vectors. This parameter is only visible when the Find the median value over parameter is set to Each column.
Specify the dimension (one-based value) of the input signal, over which the median is computed. The value of this parameter cannot exceed the number of dimensions in the input signal. This parameter is only visible when the Find the median value over parameter is set to Specified dimension.
The Data type attributes pane of the Median block dialog appears as follows.

Note Floating-point inheritance takes precedence over the data type settings defined on this pane. When inputs are floating point, the block ignores these settings, and all internal data types are floating point. |
Select the rounding mode for fixed-point operations.
Select the overflow mode for fixed-point operations.
Specify the product output data type. See Fixed-Point Data Types and Multiplication Data Types for illustrations depicting the use of the product output data type in this block. You can set it to:
A rule that inherits a data type, for example, Inherit: Same as input
An expression that evaluates to a valid data type, for example, fixdt([],16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Product
output data type parameter.
See Using the Data Type Assistant for more information.
Specify the accumulator data type. See Fixed-Point Data Types for illustrations depicting the use of the accumulator data type in this block. You can set this parameter to:
A rule that inherits a data type, for example, Inherit: Same as product output
An expression that evaluates to a valid data type, for example, fixdt([],16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Accumulator
data type parameter.
See Using the Data Type Assistant for more information.
Specify the output data type. See Fixed-Point Data Types for illustrations depicting the use of the output data type in this block. You can set it to:
A rule that inherits a data type, for example, Inherit: Same as accumulator
An expression that evaluates to a valid data type, for example, fixdt([],16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Output
data type parameter.
See Specifying Block Output Data Types for more information.
Specify the minimum value that the block should output. The default value, [], is equivalent to -Inf. Simulink software uses this value to perform:
Simulation range checking (see Checking Signal Ranges)
Automatic scaling of fixed-point data types
Specify the maximum value that the block should output. The default value, [], is equivalent to Inf. Simulink software uses this value to perform:
Simulation range checking (see Checking Signal Ranges)
Automatic scaling of fixed-point data types
Select this parameter to prevent any fixed-point scaling you specify in this block mask from being overridden by the autoscaling tool in the Fixed-Point Tool.
| Port | Supported Data Types |
|---|---|
Input |
|
Output |
|
| Maximum | Signal Processing Blockset |
| Mean | Signal Processing Blockset |
| Minimum | Signal Processing Blockset |
| Sort | Signal Processing Blockset |
| Standard Deviation | Signal Processing Blockset |
| Variance | Signal Processing Blockset |
| median | MATLAB |
![]() | Mean | Minimum | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |