Prev Next zeropad

Zeropad a Matrix in Row Direction
Syntax y = zeropad(x, Nout)
Syntax y = zeropad(x, Nout, padtype)
Include: include spt\zeropad.oms
See Also

ARGUMENTS:
   INPUTS:
      x       = INPUT, MATRIX, any numerical type.
      Nout    = INPUT, any numerical type. Coerced to INTEGER for internal processing.
      padtype = INPUT, STRING. One of:
                "AFTER"    = zeros placed behind input
                "INTERNAL" = zeros distributed as evenly as
                             possible between elements of
                             input. Nout should be an
                             integral multiple of x's length
                             for typical result.
   RETURN: MATRIX, same precision as input, zero-padded.

Description

Increase the row dimension of a matrix by padding extra columular elements with 0s(zeros). Input may be any numerical type. 'Nout' is the requested resultant row dimension; must be greater than or equal to the input row dimension. 'Nout' is coerced to INTEGER before local processing. (Nout<rowdim(x)) returns 'novalue'. padtype' is a string argument that specifies how the additional zeros are to be placed; one of 'AFTER'|'INTERNAL'. The default padding scheme is 'AFTER'. An illegal 'padtype' will return 'novalue'. For the special case of a row vector being input the vector is treated as a column vector with a row vector return.

Return type is same type as input. 'INTERNAL' zeropadding with a requested length that is not an integer multiple of the input dimension produces an inexact distribution, i.e., all original elements will not be separated by the identically same number of zeros.

Zeropadding can be used to increase a vector length to the next power-of-2 to take advantage of the efficiency of the FFT. (NOTE: Since zero-padding does not change the sampling rate of a waveform, the waveforms' basic resolution is unchanged.) Zero-padding (internally) may also be used as part of a simple interpolation scheme.

Example

For Row Vectors:

O>zeropad([4,5,6],6)
[  4 ,  5 ,  6 ,  0 ,  0 ,  0 ] 
O>zeropad([4,5,6],6,"internal")
[  4 ,  0 ,  5 ,  0 ,  6 ,  0 ] 

For Column Vectors:

O>zeropad(seq(3),9)
{
 1
 2
 3
 0
 0
 0
 0
 0
 0
}

For Matrices:

O>x = seq(3)*seq(3)'
O>x
{
[  1 ,  2 ,  3 ]
[  2 ,  4 ,  6 ]
[  3 ,  6 ,  9 ]
}

O>zeropad(x,9,"internal")
{
[  1 ,  2 ,  3 ]
[  0 ,  0 ,  0 ]
[  0 ,  0 ,  0 ]
[  2 ,  4 ,  6 ]
[  0 ,  0 ,  0 ]
[  0 ,  0 ,  0 ]
[  3 ,  6 ,  9 ]
[  0 ,  0 ,  0 ]
[  0 ,  0 ,  0 ]
}