| 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 Fixed-point pane of the Median block dialog appears as follows.

Select the rounding mode for fixed-point operations.
Select the overflow mode for fixed-point operations.
Note The product output, accumulator, and output parameters listed are only used in certain cases. See Fixed-Point Data Types for more information. |
Use this parameter to specify how you want to designate the product output word and fraction lengths:
When you select Same as input, these characteristics match those of the input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the product output, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the product output. This block requires power-of-two slope and a bias of zero.
Use this parameter to specify the accumulator word and fraction lengths resulting from a complex-complex multiplication in the block:
When you select Same as product output, these characteristics match those of the product output
When you select Same as input, these characteristics match those of the input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the accumulator, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the accumulator. This block requires power-of-two slope and a bias of zero.
Choose how you specify the output word length and fraction length:
When you select Same as accumulator, these characteristics match those of the accumulator.
When you select Same as product output, these characteristics match those of the product output.
When you select Same as input, these characteristics match those of the input to the block.
When you select Binary point scaling, you can enter the word length and the fraction length of the output, in bits.
When you select Slope and bias scaling, you can enter the word length, in bits, and the slope of the output. This block requires power-of-two slope and a bias of zero.
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.
| 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 | ![]() |
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |