| 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 |
Math Functions / Math Operations
dspmathops

The Cumulative Sum block computes the cumulative sum of the elements in each channel, column, or row of the M-by-N input matrix.
The inputs can be sample-based or frame-based vectors and matrices. The output always has the same dimensions, rate, frame status, data type, and complexity as the input.
The Cumulative Sum block accepts real and complex fixed-point and floating-point inputs except for complex unsigned fixed-point inputs.
The block computes the cumulative sum of both sample- and frame-based vector and matrix inputs. Inputs can be real or complex. When summing along channels or columns, 1-D unoriented vectors are treated as column vectors. When summing along rows, 1-D vectors are treated as row vectors.
The optional reset port, Rst, accepts scalar values, which can be any built-in Simulink data type including boolean. The rate of the reset signal must be a positive integer multiple of the rate of the data signal input.
The output always has the same dimensions, rate, frame status, data type, and complexity as the data signal input.
When the Sum input along parameter is set to Channels (running sum), the block computes the cumulative sum of the elements in each input channel. The running sum of the current input takes into account the running sum of all previous inputs. See the following sections for more information:
For frame-based inputs, the block treats each input column as an independent channel. As the following figure and equation illustrate, the output has the following 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 sum of the first row of the current input (time t), and the last row of the previous output (time t - Tf, where Tf is the frame period).
The output has the same size, dimension, frame status, data type, and complexity as the input.
Given an M-by-N frame-based input, u, the output, y, is a frame-based M-by-N matrix whose first row has elements
![]()

For sample-based inputs, the block treats each element of the input matrix as an independent channel. As the following figure and equation illustrate, the output has the following characteristics:
The first output is the same as the first input.
Each subsequent output is the sum of the current input (time t) and the previous output (time t - Ts, where Ts is the sample period).
The output has the same size, dimension, frame status, data type, and complexity as the input.
Given an M-by-N sample-based input, u, the output, y, is a sample-based M-by-N matrix with the elements
![]()

When you set the Sum input along parameter to Channels (running sum), you can set the block to reset the running sum whenever it detects a reset event at the optional Rst port. The reset sample time must be a positive integer multiple of the input sample time. The input to the Rst port can be of the boolean data type.
When the block is reset for sample-based inputs, the block initializes the current output to the values of the current input. For frame-based inputs, 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 the Rst 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 the following figure)

Falling edge — Triggers a reset operation when the Rst 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 the following figure)

Either edge — Triggers a reset operation when the Rst input is a Rising edge or Falling edge (as described above)
Non-zero sample — Triggers a reset operation at each sample time that the Rst input is not zero
Note When running simulations in the Simulink MultiTasking mode, reset signals have a one-sample latency. Therefore, when the block detects a reset event, there is a one-sample delay 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 the topic on models with multiple sample rates in the Real-Time Workshop documentation. |
When the Sum input along parameter is set to Columns, the block computes the cumulative sum of each column of the input, where the current cumulative sum is independent of the cumulative sums of previous inputs.
y = cumsum(u) % Equivalent MATLAB code
The output has the same size, dimension, frame status, data type, and complexity as the input. The mth output row is the sum of the first m input rows.
Given an M-by-N input, u, the output, y, is an M-by-N matrix whose jth column has elements

The block treats length-M 1-D vector inputs as M-by-1 column vectors when summing along columns.

When the Sum input along parameter is set to Rows, the block computes the cumulative sum of the row elements, where the current cumulative sum is independent of the cumulative sums of previous inputs.
y = cumsum(u,2) % Equivalent MATLAB code
The output has the same size, dimension, frame status, and data type as the input. The nth output column is the sum of the first n input columns.
Given an M-by-N input, u, the output, y, is an M-by-N matrix whose ith row has elements

The block treats length-N 1-D vector inputs as 1-by-N row vectors when summing along rows.

The following diagram shows the data types used within the Cumulative Sum block for fixed-point signals.

You can set the accumulator and output data types in the block dialog as discussed in Dialog Box.
The Main pane of the Cumulative Sum block dialog appears as follows.

The dimension along which to compute the cumulative summations. The options allow you to sum along Channels (running sum), Columns, and Rows. For more information, see the following sections:
Determines the reset event that causes the block to reset the sum along channels. The rate of the reset signal must be a positive integer multiple of the rate of the data signal input. This parameter is enabled only when you set the Sum input along parameter to Channels (running sum). For more information, see Resetting the Cumulative Sum Along Channels.
The Data type attributes pane of the Cumulative Sum 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 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 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 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.
| Input and Output Ports | Supported Data Types |
|---|---|
Data input port, In |
|
Reset input port, Rst | All built-in Simulink data types:
|
Output port |
|
| Cumulative Product | Signal Processing Blockset |
| Difference | Signal Processing Blockset |
| Matrix Sum | Signal Processing Blockset |
| cumsum | MATLAB |
![]() | Cumulative Product | Data Type Conversion | ![]() |

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 |