wextend
Extend vector or matrix
Description
also specifies the location of the extension.yext
= wextend(___,loc
)
Examples
Extend Vector
Extend a vector using a number of different methods.
Create a vector and set the extension length to 2.
len = 2; x = [1 2 3]
x = 1×3
1 2 3
Extend the signal using zero padding. To verify that different forms of the input arguments are possible, perform this extension twice. The result is the same both times.
xextzpd1 = wextend("1","zpd",x,len)
xextzpd1 = 1×7
0 0 1 2 3 0 0
xextzpd2 = wextend("1D","zpd",x,len,"b")
xextzpd2 = 1×7
0 0 1 2 3 0 0
Perform a half-point symmetric extension.
xextsym = wextend("1D","sym",x,len)
xextsym = 1×7
2 1 1 2 3 3 2
Perform a periodic extension. Because the input vector is of odd length, wextend
appends on the right a copy of the last sample before extending using the "ppd"
mode
xextper = wextend("1D","per",x,len)
xextper = 1×8
3 3 1 2 3 3 1 2
Extend Matrix
Extend a small matrix using a number of different methods.
Create a matrix and set the extension length to 2.
len = 2; X = [1 2 3; 4 5 6]
X = 2×3
1 2 3
4 5 6
Extend the matrix using zero padding.
Xextzpd = wextend(2,"zpd",X,len)
Xextzpd = 6×7
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 2 3 0 0
0 0 4 5 6 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
Perform a half-point symmetric extension of the matrix.
Xextsym = wextend("2D","sym",X,len)
Xextsym = 6×7
5 4 4 5 6 6 5
2 1 1 2 3 3 2
2 1 1 2 3 3 2
5 4 4 5 6 6 5
5 4 4 5 6 6 5
2 1 1 2 3 3 2
Observe the effects of symmetric, antisymmetric, and smooth extensions on a uint8
vector when values are at or near the limits of the data type's range.
Symmetric Extensions
The smallest uint8
integer is 0, and the largest is 255. Create a vector of uint8
integers that includes those limits.
dataVector = uint8([0 1 2 253 254 255])
dataVector = 1×6 uint8 row vector
0 1 2 253 254 255
Obtain whole-point and half-point symmetric extensions of the vector. Extend the vector by two values on the left and right. Extending symmetrically never results in values outside the uint8
range.
wholePointSym = wextend("1","symw",dataVector,2)
wholePointSym = 1×10 uint8 row vector
2 1 0 1 2 253 254 255 254 253
halfPointSym = wextend("1","symh",dataVector,2)
halfPointSym = 1×10 uint8 row vector
1 0 0 1 2 253 254 255 255 254
Antisymmetric Extensions
Create a type double
copy of the vector, and then obtain a whole-point antisymmetric extension of the copy. The extension includes negative values and values greater than 255.
dataVectorDouble = double(dataVector); wholePointAsymDouble = wextend("1","asymw",dataVectorDouble,2)
wholePointAsymDouble = 1×10
-2 -1 0 1 2 253 254 255 256 257
Obtain a whole-point antisymmetric extension of the original uint8
vector. Values outside the uint8
range are mapped to the closest uint8
integer, which is 0 for negative values and 255 for values greater than 255.
wholePointAsym = wextend("1","asymw",dataVector,2)
wholePointAsym = 1×10 uint8 row vector
0 0 0 1 2 253 254 255 255 255
Now obtain half-point antisymmetric extensions of the double
copy and the original uint8
vector. As with the whole-point antisymmetric extension, negative values in the extended uint8
data are mapped to 0.
halfPointAsymDouble = wextend("1","asymh",dataVectorDouble,2)
halfPointAsymDouble = 1×10
-1 0 0 1 2 253 254 255 -255 -254
halfPointAsym = wextend("1","asymh",dataVector,2)
halfPointAsym = 1×10 uint8 row vector
0 0 0 1 2 253 254 255 0 0
Smooth Extensions
Obtain order-0 smooth extensions of the double
copy and the original uint8
vector. Results are identical.
smooth0Double = wextend("1","sp0",dataVectorDouble,2)
smooth0Double = 1×10
0 0 0 1 2 253 254 255 255 255
smooth0 = wextend("1","sp0",dataVector,2)
smooth0 = 1×10 uint8 row vector
0 0 0 1 2 253 254 255 255 255
Obtain an order-1 smooth extension of each vector. The values in the double
result that are outside the uint8
range are mapped to the closest uint8
values in the uint8
extension.
smooth1Double = wextend("1","sp1",dataVectorDouble,2)
smooth1Double = 1×10
-2 -1 0 1 2 253 254 255 256 257
smooth1 = wextend("1","sp1",dataVector,2)
smooth1 = 1×10 uint8 row vector
0 0 0 1 2 253 254 255 255 255
Observe the effects of symmetric, antisymmetric, and smooth extensions of int8
data when values are at or near the limits of the data type's range.
Symmetric Extensions
The smallest int8
integer is –128 and the largest is 127. Create a vector of int8
integers that includes those limits.
dataVector = int8([-128 -127 -126 125 126 127])
dataVector = 1×6 int8 row vector
-128 -127 -126 125 126 127
Obtain whole-point and half-point symmetric extensions of the data. Extend the vector by two values on the left and right. Extending symmetrically never results in values outside the int8
range.
wholePointSym = wextend("1","symw",dataVector,2)
wholePointSym = 1×10 int8 row vector
-126 -127 -128 -127 -126 125 126 127 126 125
halfPointSym = wextend("1","symh",dataVector,2)
halfPointSym = 1×10 int8 row vector
-127 -128 -128 -127 -126 125 126 127 127 126
Antisymmetric Extensions
Create a type double
copy of the vector, and then obtain a whole-point antisymmetric extension of the copy. The extension includes negative values less than –128 and values greater than 127.
dataVectorDouble = double(dataVector); wholePointsAsymDouble = wextend("1","asymw",dataVectorDouble,2)
wholePointsAsymDouble = 1×10
-130 -129 -128 -127 -126 125 126 127 128 129
Obtain a whole-point antisymmetric extension of the original int8
vector. Values outside the int8
range are mapped to the closest int8
integer, which is –128 for values less than –128 and 127 for values greater than 127.
wholePointAsym = wextend("1","asymw",dataVector,2)
wholePointAsym = 1×10 int8 row vector
-128 -128 -128 -127 -126 125 126 127 127 127
Now obtain half-point antisymmetric extensions of the double
copy and the original int8
vector. In the double
result, the first value is 127, which can be represented as an int8
integer. The second value is 128, which cannot be represented as an int8
integer. Therefore, in the int8
result, it is being mapped to 127. The remaining values in the type double
result can all be represented as int8
integers.
halfPointAsymDouble = wextend("1","asymh",dataVectorDouble,2)
halfPointAsymDouble = 1×10
127 128 -128 -127 -126 125 126 127 -127 -126
halfPointAsym = wextend("1","asymh",dataVector,2)
halfPointAsym = 1×10 int8 row vector
127 127 -128 -127 -126 125 126 127 -127 -126
Smooth Extensions
Obtain order-0 smooth extensions of the double
copy and the original int8
vector. The results are identical.
smooth0Double = wextend("1","sp0",dataVectorDouble,2)
smooth0Double = 1×10
-128 -128 -128 -127 -126 125 126 127 127 127
smooth0 = wextend("1","sp0",dataVector,2)
smooth0 = 1×10 int8 row vector
-128 -128 -128 -127 -126 125 126 127 127 127
Obtain an order-1 smooth extension of each vector. The values in the double
result outside the int8
range are mapped to the closest int8
values in the int8
extension.
smooth1Double = wextend("1","sp1",dataVectorDouble,2)
smooth1Double = 1×10
-130 -129 -128 -127 -126 125 126 127 128 129
smooth1 = wextend("1","sp1",dataVector,2)
smooth1 = 1×10 int8 row vector
-128 -128 -128 -127 -126 125 126 127 127 127
Input Arguments
Extension method used on the input, specified as one of the values listed here.
type | Description |
---|---|
1 , "1" , "1d" ,
or "1D" | 1-D extension |
2 , "2" , "2d" ,
or "2D" | 2-D extension |
"ar" or
"addrow" | Add rows |
"ac" or
"addcol" | Add columns |
Data Types: double
| char
Specific extension method to use to extend the input, specified as
one of the values listed here. For more information, see dwtmode
.
mode | Description |
---|---|
"zpd" | Zero padding |
"sp0" | Smooth extension of order 0 |
"spd" (or
"sp1" ) | Smooth extension of order 1 |
"sym" or
"symh" | Symmetric padding (half point): boundary value symmetric replication |
"symw" | Symmetric padding (whole point): boundary value symmetric replication |
"asym" or
"asymh" | Antisymmetric padding (half point): boundary value antisymmetric replication |
"asymw" | Antisymmetric padding (whole point): boundary value antisymmetric replication |
"ppd" ,
"per" | Periodized extension If the
signal length is odd, |
For more information on symmetric extension modes, see [1].
Note
The extension modes "sp0"
and
"spd"
(or "sp1"
) cast
the data internally to double precision before performing the
extension. For integer data types, wextend
warns if one of the following occurs.
The conversion to double causes a loss of precision.
The requested extension results in integers beyond the range where double precision numbers can represent consecutive integers exactly.
Data Types: char
Input data, specified as a real-valued vector or matrix.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Length of extension, specified as a nonnegative integer or
two-element vector of nonnegative integers. You can extend a matrix by
expressing LEN
as [LROW,LCOL]
,
where LROW
is the number of rows to add and
LCOL
is the number of columns to add. You can
perform a 2-D extension of a matrix by the same amount in both
directions by specifying LEN
as single
integer.
An extension of length 0 is equivalent to the null extension.
Example: wextend("2D","sym",[1 2 3 4;5 6 7 8],[2
0])
extends only two rows up and two rows
down.
Location of extension, specified as one or a pair of the following:
"l"
— Extension left"u"
— Extension up"r"
— Extension right"d"
— Extension down"b"
— Extension on both sides"n"
— Null extension
The valid and default values for
LOC
, and the behavior of
LEN
, depend on the specified
type
.
type | loc |
---|---|
1, "1", 1d" or
"1D" | "l" , "u" ,
"r" , "d" ,
"b" , or
"n" Example: wextend("1D","zpd",X,3,"r")
extends input vector X three
elements to the
right.Default: "b" LEN
is the length of the extension. |
2, "2", "2d" or
"2D" | [LOCROW,LOCCOL] , where
LOCROW and
LOCCOL are 1-D extension
locations or "n" (none).
Example: wextend("2D","zpd",X,[2
3],"ub") extends input vector or matrix
X two rows up and three columns
on both
sides.Default: "bb" LEN ,
specified as [LROW,LCOL] , is
the number of rows and columns to add. |
"ar" or
"addrow" | "l" , "u" ,
"r" , "d" ,
"b" , or
"n" Example: wextend("addrow","zpd",X,4,"d")
extends input vector or matrix
X four rows
down.Default: "b" LEN
is the number of rows to add. |
"ac" or
"addcol" | "l" , "u" ,
"r" , "d" ,
"b" , or
"n" Example: wextend("addcol","zpd",X,1,"l")
extends input vector or matrix
X one column to the
left.Default: "b" LEN
is the number of columns to add. |
Tips
For most wavelet applications, either a periodic extension or symmetric extension works fine.
Algorithms
When a value is outside the input data type's range, wextend
maps it to the closest value of the input data type. For examples of data being
extended beyond a data type's range, see Extend uint8 Data Beyond Range Limits and Extend int8 Data Beyond Range Limits.
References
[1] Strang, G., and T. Nguyen. Wavelets and Filter Banks. Wellesley, MA: Wellesley-Cambridge Press, 1996.
Extended Capabilities
Usage notes and limitations:
The generated code can return a column vector when MATLAB® returns a row vector if all of the following conditions are true:
type
specifies a 1-D extension.Input
x
is a variable-size vector.Input
x
is not a variable-length row vector (1-by-:).
Code generation does not produce a warning or error message about the shape mismatch. In the output vector that the generated code returns, the values match the values in the output vector that MATLAB returns.
In this case, to generate code that returns a row vector, pass
x(:).'
instead ofx
.Input
x
must be of typedouble
.
The wextend
function
supports GPU array input with these usage notes and limitations:
wextend
supports only the"sym"
and"per"
extension modes.The only syntax supported is
yext = wextend(type,mode,x,len)
.The
loc
input argument is not supported.For one-dimensional extensions, the default location
"b"
is used. For two-dimensional extensions, the default location"bb"
is used.
Only extensions in one dimension are supported.
The
len
input argument must have length equal to one.For one-dimensional extensions, the only supported extension methods are:
1
,"1"
,"1d"
, and"1D"
.For two-dimensional extensions, the only supported extension methods are:
"addrow"
, and"addcol"
.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)