Products & Services Solutions Academia Support User Community Company

Learn more about Signal Processing Blockset   

Difference - Compute element-to-element difference along specified dimension of input

Library

Math Functions / Math Operations

dspmathops

Description

The Difference block computes the difference between adjacent elements in rows, columns, or a specified dimension of the input array u. This block accepts real and complex fixed-point and floating-point inputs, except for complex unsigned fixed-point inputs.

Columnwise Differencing

When the Difference along parameter is set to Columns, the block computes differences between adjacent elements along each column.

y = diff(u)						% Equivalent MATLAB code

For sample-based inputs, the output is a sample-based (M-1)-by-N matrix whose jth column has elements

For convenience, length-M 1-D vector inputs are treated as M-by-1 column vectors for columnwise differencing, and the output is 1-D.

For example, the following figure shows the block output for sample-based inputs:

For frame-based inputs, the output is a frame-based M-by-N matrix whose jth column has elements

The first element of the output for each column is the first input element minus the last input element of the previous frame. For the first frame, zero is subtracted from the first input element.

For example, the following figure shows the second frame of the block output for a frame-based input:

Rowwise Differencing

When the Difference along parameter is set to Rows, the block computes differences between adjacent elements along each row. The result is the same regardless of the frame status of the input signal.

y = diff(u,[],2)						% Equivalent MATLAB code

The output is an M-by-(N-1) matrix whose ith row has elements

The frame status of the output is the same as the input. For convenience, length-N 1-D vector inputs are treated as 1-by-N row vectors for rowwise differencing, and the output is 1-D.

For example, the following figure shows the block output for sample-based inputs. The output is the same for frame-based inputs:

Differencing Along Arbitrary Dimensions

When the Difference along parameter is set to Specified dimension, the behavior of the block is an extension of the rowwise differencing described earlier. The block computes differences between adjacent elements along the dimension specified by the Dimension parameter.

y = diff(u,[],d) % Equivalent MATLAB code where d is the dimension

The output is an array whose length in the specified dimension is one less than that of the input, and whose lengths in other dimensions are unchanged. For example, consider an M-by-N-by-P-by-R input array with elements u(i,j,k,l) and assume that Dimension is 3. The output of the block is an M-by-N-by-(P–1)-by-R array with elements

Fixed-Point Data Types

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

You can set the accumulator and output data types in the block dialog as discussed in Dialog Box .

Dialog Box

The Main pane of the Difference block appears as follows.

Difference along

Specify whether the block performs columnwise differencing, rowwise differencing, or differencing along a specified dimension.

Dimension

Specify the one-based dimension along which to compute element-to-element differences.

This parameter is only visible when you select Specified dimension for the Difference along parameter.

The Data Types pane of the Difference block appears as follows.

Rounding mode

Select the rounding mode for fixed-point operations.

Overflow mode

Select the overflow mode for fixed-point operations.

Accumulator data type

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: Inherit via internal rule

  • 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.

Output data type

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.

Minimum

Specify the minimum value that the block should output. The default value, [], is equivalent to -Inf. Simulink software uses this value to perform:

Maximum

Specify the maximum value that the block should output. The default value, [], is equivalent to Inf. Simulink software uses this value to perform:

Lock data type settings against changes by the fixed-point tools

Select this parameter to prevent the fixed-point tools from overriding the data types you specify on the block mask.

Supported Data Types

PortSupported Data Types

Input

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point

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

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

Output

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point

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

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

See Also

Cumulative SumSignal Processing Blockset
diffMATLAB

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

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