conv
Convolution and polynomial multiplication
Description
returns the convolution of vectors w = conv(u,v)u and v. If
u and v are vectors of polynomial coefficients,
convolving them is equivalent to multiplying the two polynomials.
Examples
Create vectors u and v containing the coefficients of the polynomials and .
u = [1 0 1]; v = [2 7];
Use convolution to multiply the polynomials.
w = conv(u,v)
w = 1×4
2 7 2 7
w contains the polynomial coefficients for .
Create two vectors and convolve them.
u = [1 1 1]; v = [1 1 0 0 0 1 1]; w = conv(u,v)
w = 1×9
1 2 2 1 0 1 2 2 1
The length of w is length(u)+length(v)-1, which in this example is 9.
Create two vectors. Find the central part of the convolution of u and v that is the same size as u.
u = [-1 2 3 -2 0 1 2];
v = [2 4 -1 1];
w = conv(u,v,"same")w = 1×7
15 5 -9 7 6 7 -1
w has a length of 7. The full convolution would be of length length(u)+length(v)-1, which in this example would be 10.
Input Arguments
Input vectors, specified as either row or column vectors. The vectors u and
v can be different lengths or data types.
When u or v are of type single,
then the output is of type single. Otherwise, conv converts
inputs to type double and returns type double.
Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical
Complex Number Support: Yes
Subsection of the convolution, specified as "full",
"same", or "valid".
"full" | Full convolution (default). |
"same" | Central part of the convolution of the same size as |
"valid"
| Only those parts of the convolution that are computed
without the zero-padded edges. Using this option, |
Output Arguments
Convolved vector, returned as a row or column vector.
More About
The convolution of two vectors, u and v,
represents the area of overlap under the points as v slides
across u. Algebraically, convolution is the same
operation as multiplying polynomials whose coefficients are the elements
of u and v.
Let m = length(u) and n = length(v). Then
w is the vector of length m+n-1 whose
kth element is
The sum is over all the values of j that
lead to legal subscripts for u(j) and v(k-j+1),
specifically j = max(1,k+1-n):1:min(k,m).
When m = n,
this gives
w(1) = u(1)*v(1) w(2) = u(1)*v(2)+u(2)*v(1) w(3) = u(1)*v(3)+u(2)*v(2)+u(3)*v(1) ... w(n) = u(1)*v(n)+u(2)*v(n-1)+ ... +u(n)*v(1) ... w(2*n-1) = u(n)*v(n)
Using this definition, conv calculates the direct convolution of two
vectors, rather than the FFT-based convolution.
Extended Capabilities
The
conv function supports tall arrays with the following usage
notes and limitations:
The inputs
uandvmust be column vectors.If
shapeis"full"(default), then only one ofuorvcan be a tall array.If
shapeis"same"or"valid", thenvcannot be a tall array.
For more information, see Tall Arrays.
Usage notes and limitations:
If used, the
shapeargument must be a constant at code generation time.For input arguments
uandv:You must specify the input vector as a fixed-size or variable-length vector at code generation time. Either the first or the second dimension of the vector can be variable size. All other dimensions must have a fixed size of 1.
Input vectors
uandvmust have the same orientation.
Refer to the usage notes and limitations in the C/C++ Code Generation section. The same usage notes and limitations apply to GPU code generation.
The conv function fully supports
thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
The conv function
fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
The conv function fully supports
distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006aWhen you compute a full convolution using w = conv(u,v) or w =
conv(u,v,"full"), the output w is a row vector unless both input
vectors u and v are column vectors.
For example, if you convolve a row vector and a column vector, the output is a row vector.
u = [1 0 1]; v = [2; 7; 4]; w = conv(u,v)
w =
2 7 6 7 4u = [1; 0; 1]; v = [2; 7; 4]; w = conv(u,v)
w =
2
7
6
7
4For comparison, when computing a full convolution in previous releases, the
conv function returned either a row or column vector depending on the
orientations and lengths of u and v.
For example, in previous releases, conv returned the full convolution of
a 1-by-3 row vector and a 3-by-1 column vector as a 5-by-1 column
vector.
u = [1 0 1]; v = [2; 7; 4]; w = conv(u,v)
w =
2
7
6
7
4conv returned the full convolution of a
1-by-3 row vector and a 2-by-1 column vector as a 1-by-4 row
vector.u = [1 0 1]; v = [2; 7]; w = conv(u,v)
w =
2 7 2 7There are no changes to the output of w = conv(u,v,"same") or w
= conv(u,v,"valid"), where the output still follows the orientation of the first
input vector u.
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: .
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)