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 Fixed-point 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

Use this parameter to specify how you would like to designate the accumulator word and fraction lengths:

Output

Choose how you specify the output word length and fraction length:

Lock scaling against changes by the autoscaling tool

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.

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

  


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