Pad

Pad or truncate specified dimension(s)

Library

Signal Operations

dspsigops

  • Pad block

Description

The Pad block extends or crops the dimensions of the input by padding or truncating along its columns, rows, columns and rows, or any dimension(s) you specify. Truncation occurs when you specify output dimensions that are shorter than the corresponding input dimensions. If the input and output lengths are the same, the block is a pass-through.

You can enter the pad value in the block mask or via an input port. You can enter output sizes in the block mask, or have the block pad the specified dimensions until their length is the next highest power of two. The Pad signal at parameter controls whether the specified input dimensions are padded or truncated at their beginning, end, or both. For odd pad or truncation lengths, the extra pad value or truncation is applied to the end of the signal. When the block is in Specified dimensions mode, you can specify either the output size or the pad size.

You can have the block warn or error when an input signal is truncated using the Action when truncation occurs parameter.

Parameters

Pad over

Specify the dimensions over which to pad or truncate: Columns, Rows, Columns and rows, None, or Specified dimensions.

Dimensions to pad

Specify the one-based dimension(s) over which to pad or truncate. The value for this parameter can be a scalar or a vector. For example, specify 1 to pad columns. Specify [1 2] to pad columns and rows. Specify [1 3 5] to pad the first, third, and fifth dimensions.

This parameter is only visible when Specified dimensions is selected for the Pad over parameter.

Pad value source

Choose how you specify the pad value. The pad value can come from an input port or from the dialog:

  • If you select Input port, the PVal port appears on the block icon.

  • If you select Specify via dialog, the Pad value parameter appears.

Pad value

Specify the constant scalar value with which to pad the input. Tunable (Simulink).

This parameter is only visible when Specify via dialog is selected for the Pad value source parameter.

Output column mode

Choose how you specify the column length of the output:

  • If you select User-specified, the Column size parameter appears.

  • If you select Next power of two, the block pads the output columns until their length is the next highest power of two. If the column length is already a power of two, the columns are not padded.

This parameter is only visible when Columns or Columns and rows is selected for the Pad over parameter.

Column size

Specify the column length of the output. If the specified column length is longer than the input column length, the columns are padded. If the specified column length is shorter than the input column length, the columns are truncated. This parameter is only visible when User-specified is selected for the Output column mode parameter.

Output row mode

Choose how you specify the output row length of the output:

  • If you select User-specified, the Row size parameter appears.

  • If you select Next power of two, the block pads the output rows until their length is the next highest power of two. If the row length is already a power of two, the rows are not padded.

This parameter is only visible when Rows or Columns and rows is selected for the Pad over parameter.

Row size

Specify the row length of the output. If the specified row length is longer than the input row length, the rows are padded. If the specified row length is shorter than the input row length, the rows are truncated. This parameter is only visible when User-specified is selected for the Output row mode parameter.

Specify

Choose whether you want to control the output length of the specified dimensions by specifying the pad size or the output size.

This parameter is only visible when Specified dimensions is selected for the Pad over parameter.

Pad size at beginning

Specify how many values to add to the beginning of the input signal along the specified dimension(s). This parameter must be a scalar or a vector with the same number of elements as the Dimensions to pad parameter. Each element in the Pad size at beginning parameter gives the pad length for the beginning of the corresponding dimension in the Dimensions to pad parameter. Values of this parameter must be zero or a positive integer.

This parameter is only visible if Pad size is selected for the Specify parameter.

Pad size at end

Specify how many values to add to the end of the input signal along the specified dimension(s). This parameter must be a scalar or a vector with the same number of elements as the Dimensions to pad parameter. Each element in the Pad size at end parameter gives the pad length for the end of the corresponding dimension in the Dimensions to pad parameter. Values of this parameter must be zero or a positive integer.

This parameter is only visible if Pad size is selected for the Specify parameter.

Output size mode

Choose how you specify the output length of the specified dimensions:

  • If you select User-specified, the Output size parameter appears.

  • If you select Next power of two, the block pads the specified dimensions until their length is the next highest power of two. If the dimension length is already a power of two, no padding occurs in that dimension.

This parameter is only visible if Output size is selected for the Specify parameter.

Output size

Specify the output length of the specified dimension(s). This parameter must be a scalar or a vector with the same number of elements as the Dimensions to pad parameter. Each element in the Output size vector gives the output length for the corresponding dimension in the Dimensions to pad vector. If the specified length is longer than the input length for a given dimensions, that dimension is padded. If the specified length is shorter than the input length for a given dimension, that dimension is truncated.

This parameter is only visible if Output size is selected for the Specify parameter.

Pad signal at

Specify whether to pad or truncate the signal at the Beginning, End, or Beginning and end of the specified dimension(s). When you select Beginning and end, half the pad length is added to the beginning of the signal, and half is added to the end of the signal. For an odd pad length, the extra value is added to the end of the signal. This also applies to truncation. In this mode, an equal number of values are truncated from the beginning and the end of the signal. In the case of an odd truncation length, the extra value is removed from the end of the signal.

Action when truncation occurs

Choose None when you do not want to be notified that the input is truncated. Select Warning to display a warning when the input is truncated. Choose Error when to display an error and terminate the simulation when the input is truncated.

Supported Data Types

PortSupported Data Types

Input

  • Double-precision floating-point

  • Single-precision floating-point

  • Fixed point (signed and unsigned)

  • Boolean

  • 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 (signed and unsigned)

  • Boolean

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

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

See Also

Concatenate (Simulink)Simulink
RepeatDSP System Toolbox
SubmatrixDSP System Toolbox
UpsampleDSP System Toolbox
Variable SelectorDSP System Toolbox

Extended Capabilities

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Introduced before R2006a