Cumulative Product
Cumulative product of channel, column, or row elements
Libraries:
DSP System Toolbox /
Math Functions /
Math Operations
Description
The Cumulative Product block computes the cumulative product along the specified dimension of the input or across time (running product).
Ports
Input
In — Input signal
vector  matrix
Specify the input signal as a vector or a matrix.
This port is unnamed until you set the Reset port parameter to any
value other than None
.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
 fixed point
Complex Number Support: Yes
Rst — Reset port
scalar
The optional reset port, Rst, accepts scalar values, which can be
any builtin Simulink^{®} numeric data type including boolean
.
The rate of the input to the Rst port must be the
same or slower than that of the input data signal. The sample time of
the input to the Rst port must be a positive
integer multiple of the input sample time.
For more information on this port, see Resetting Running Product.
Dependencies
This port is unnamed until you set the Reset
port parameter to any value other than
None
.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
 Boolean
Output
Out — Cumulative product
vector  matrix
Cumulative product of the signal, returned as a vector or a matrix.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
 fixed point
Complex Number Support: Yes
Parameters
Main Tab
Multiply input along — Dimension to multiply input along
Channels (running
product)
(default)  Columns
 Rows
Specify the dimension along which to compute the cumulative product. You can set this parameter to one of these options:
Channels (running product)
Columns
Rows
For more information, see the following sections:
Input processing — Input processing
Columns as channels (frame
based)
(default)  Elements as channels (sample
based)
Specify how the block should process the input when computing the running product along the channels of the input. You can set this parameter to one of the following options:
Columns as channels (frame based)
— The block treats each column of the input as a separate channel.Elements as channels (sample based)
— The block treats each element of the input as a separate channel.
For more information, see Computing Running Product Along Channels of Input.
Dependencies
To enable this parameter, set the Multiply input
along parameter to Channels (running
product)
.
Reset port — Reset type
None
(default)  Rising edge
 Falling edge
 Either edge
 Nonzero sample
Specify the reset event that causes the block to reset the product along channels. You can set this parameter to one of these options:
None
Rising edge
Falling edge
Either edge
Nonzero sample
For more information on these options, see Resetting Running Product.
Dependencies
To enable this parameter, set the Multiply input
along parameter to Channels (running
product)
.
Data Types Tab
Note
Floatingpoint 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.
Rounding mode — Rounding mode
Floor
(default)  Ceiling
 Convergent
 Nearest
 Round
 Simplest
 Zero
Specify the rounding mode for fixedpoint operations as one of the following:
Floor
Ceiling
Convergent
Nearest
Round
Simplest
Zero
For more details, see rounding mode.
Saturate on integer overflow — Saturate on integer overflow
off
(default)  on
When you select this parameter, the block saturates the result of its
fixedpoint operation. When you clear this parameter, the block wraps
the result of its fixedpoint operation. For details on
saturate
and wrap
, see overflow
mode for fixedpoint operations.
Intermediate product — Intermediate product
Inherit: Same as
input
(default)  fixdt([],16,0)
Specify the intermediate product data type. As shown in FixedPoint Data Types, the output of the multiplier is cast to the intermediate product data type before the next element of the input is multiplied into it. 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 parameter.
See Specify Data Types Using Data Type Assistant (Simulink) for more information.
Product output — Product output
Inherit: Same as
input
(default)  fixdt([],16,0)
Specify the product output data type. See FixedPoint 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 parameter.
See Specify Data Types Using Data Type Assistant (Simulink) for more information.
Accumulator — Accumulator
Inherit: Same as
input
(default)  Inherit: Same as product output
 fixdt([],16,0)
Specify the accumulator data type. See FixedPoint 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 input
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 parameter.
See Specify Data Types Using Data Type Assistant (Simulink) for more information.
Output — Output
Inherit: Same as
input
(default)  Inherit: Same as product output
 fixdt([],16,0)
Specify the output data type. See FixedPoint 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 input
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)
If both inputs are unsigned, all data types including the output data type is unsigned. If one of the inputs is signed, internal and output data types are signed.
Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Output parameter.
See Control Data Types of Signals (Simulink) for more information.
Output Minimum — Minimum
[]
(default)
Specify the minimum value that the block must output. The default value is
[]
(unspecified). Simulink uses this value to perform:
Simulation range checking (see Specify Signal Ranges (Simulink))
Automatic scaling of fixedpoint data types
Output Maximum — Maximum
[]
(default)
Specify the maximum value that the block must output. The default value is
[]
(unspecified). Simulink uses this value to perform:
Simulation range checking (see Specify Signal Ranges (Simulink))
Automatic scaling of fixedpoint data types
Lock data type settings against changes by the fixedpoint tools — Prevent fixedpoint tools from overriding data types
off
(default)  on
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify in the block dialog box.
Block Characteristics
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

More About
Computing Running Product Along Channels of Input
When you set the Multiply input along parameter to
Channels (running product)
, the block computes the
cumulative product of the elements in each input channel. The running product of the
current input takes into account the running product of all previous inputs. In this
mode, you must also specify a value for the Input processing
parameter. When you set the Input processing parameter to
Columns as channels (frame based)
, the block computes
the running product along each column of the current input. When you set the
Input processing parameter to Elements as
channels (sample based)
, the block computes a running product for
each element of the input across time. See the following sections for more
information.
When you set the Input processing parameter to Columns
as channels (frame based)
, the block treats each input column
as an independent channel. As the following figure and equation illustrate, the
output has these characteristics:
The first row of the first output is the same as the first row of the first input.
The first row of each subsequent output is the elementwise product of the first row of the current input (time t), and the last row of the previous output (time t  T_{f}, where T_{f} is the frame period).
The output has the same size, dimension, data type, and complexity as the input.
Given an MbyN matrix input u, the output y is an MbyN matrix whose first row has elements
$${y}_{1,j}\left(t\right)={u}_{1,j}\left(t\right)\cdot {y}_{M,j}\left(t{T}_{f}\right).$$
When you set the Input processing parameter to Elements
as channels (sample based)
, the block treats each element of
the input matrix as an independent channel. As the following figure and equation
illustrate, the output has these characteristics:
The first output is the same as the first input.
Each subsequent output is the elementwise product of the current input (time t) and the previous output (time t  T_{s}, where T_{s} is the sample period).
The output has the same size, dimension, data type, and complexity as the input.
Given an MbyN matrix input u, the output y is an MbyN matrix with the elements
$${y}_{i,j}(t)={u}_{i,j}(t)\cdot {y}_{i,j}(t{T}_{s})\text{\hspace{0.17em}}\text{\hspace{0.17em}}\begin{array}{c}1\le i\le M\\ 1\le j\le N\end{array}.$$
For convenience, the block treats lengthM unoriented vector inputs as Mby1 column vectors when multiplying along channels. In such cases, the output is a lengthM unoriented vector.
Resetting Running Product
When you are computing the running product, you can configure the block to reset the running product whenever it detects a reset event at the optional Rst port. The rate of the input to the Rst port must be the same or slower than that of the input data signal. The sample time of the input to the Rst port must be a positive integer multiple of the input sample time. The input to the Rst port can be of the Boolean data type.
If a reset event occurs while the block is performing samplebased processing, the block initializes the current output to the values of the current input. If a reset event occurs while the block is performing framebased processing, the block initializes the first row of the current output to the values in the first row of the current input.
The Reset port parameter specifies the reset event, which can be one of the following:
None
disables the Rst port.Rising edge
— Triggers a reset operation when theRst
input does one of the following:Rises from a negative value to a positive value or zero
Rises from zero to a positive value, where the rise is not a continuation of a rise from a negative value to zero (see figure)
Falling edge
— Triggers a reset operation when theRst
input does one of the following:Falls from a positive value to a negative value or zero
Falls from zero to a negative value, where the fall is not a continuation of a fall from a positive value to zero (see figure)
Either edge
— Triggers a reset operation when theRst
input is aRising edge
orFalling edge
(as described above)Nonzero sample
— Triggers a reset operation at each sample time that theRst
input is not zero
Note
When you run simulations in Simulink
MultiTasking
mode, reset signals have a onesample
latency. When the block detects a reset event, a onesample delay occurs at the
reset port rate before the block applies the reset. For more information on
latency and the Simulink tasking modes, see Excess Algorithmic Delay (Tasking Latency) and TimeBased Scheduling and Code Generation (Simulink Coder).
Multiplying Along Columns
When you set the Multiply input along parameter to
Columns
, the block computes the cumulative product of
each column of the input. In this mode, the current cumulative product is
independent of the cumulative products of previous inputs.
The equivalent MATLAB^{®} code is
y = cumprod(u).
The output has the same size, dimension, data type, and complexity as the input. The mth output row is the elementwise product of the first m input rows.
Given an MbyN input u, the output y is an MbyN matrix whose jth column has elements
$${y}_{i,j}={\displaystyle \prod _{k=1}^{i}{u}_{k,j}}\text{}1\le i\le M.$$
When multiplying along columns, the block treats lengthM unoriented vector inputs as Mby1 column vectors.
Multiplying Along Rows
When you set the Multiply input along parameter to
Rows
, the block computes the cumulative product of
the row elements. In this mode, the current cumulative product is independent of the
cumulative products of previous inputs.
The equivalent MATLAB code is
y = cumprod(u,2).
The output has the same size, dimension, and data type as the input. The nth output column is the elementwise product of the first n input columns.
Given an MbyN matrix input u, the output y is an MbyN matrix whose ith row has elements
$${y}_{i,j}={\displaystyle \prod _{k=1}^{j}{u}_{i,k}}\text{}1\le j\le N.$$
When you multiply along rows, the block treats lengthN unoriented vector inputs as 1byN row vectors.
FixedPoint Data Types
This diagram shows the data types used within the Cumulative Product block for fixedpoint signals.
The output of the multiplier is in the product output data type when at least one of the inputs to the multiplier is real. When both of the inputs to the multiplier are complex, the result of the multiplication is in the accumulator data type. For details on the complex multiplication performed, see Multiplication Data Types. You can set the accumulator, product output, intermediate product, and output data types in the block dialog box.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Generated code relies on the memcpy
or
memset
function (string.h
) under certain
conditions.
FixedPoint Conversion
Design and simulate fixedpoint systems using FixedPoint Designer™.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)