Convolution of two signals
The dsp.Convolver
System object™ convolves the first dimension of an N-D input array,
u, with the first dimension of an N-D input array,
v. You can convolve the inputs in the time domain or frequency domain. In
the time domain, the object convolves the first input with the second input. In the frequency
domain, the object multiplies the Fourier transforms of both the inputs, and computes the
inverse Fourier transform of the product. In this domain, depending on the input length, the
object can require fewer computations. For more information on the two computation methods,
see Algorithms.
To convolve two inputs:
Create the dsp.Convolver
object and set its properties.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects?.
creates a convolution
System object, cnv
= dsp.Convolvercnv
, to convolve two inputs in the time domain or
frequency domain.
creates a convolution System object, cnv
= dsp.Convolver(Name,Value
)cnv
, with each specified property set to the specified
value. Enclose each property name in single quotes.
cnv = dsp.Convolver('Method','Frequency
Domain')
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release
function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects.
Method
— Domain for computing convolutions'Time Domain'
(default) | 'Frequency Domain'
| 'Fastest'
Domain in which the System object computes convolutions, specified as one of the following:
'Time Domain'
–– Computes the convolutions in the time
domain, which minimizes memory usage. For more information, see Time-Domain Computation.
'Frequency Domain'
–– Computes the convolutions in the
frequency domain, which can require fewer computations depending on the input
length. For more information, see Frequency-Domain Computation.
'Fastest'
–– Computes the convolutions in the domain that
minimizes the number of computations.
Note
Fixed-point signals are supported for the time domain only. To use the following
fixed-point properties, set Method
to 'Time
Domain'
.
FullPrecisionOverride
— Full-precision override for fixed-point arithmetictrue
(default) | false
Flag to use full-precision rules for fixed-point arithmetic, specified as one of the following:
true
–– The object computes all internal arithmetic and
output data types using the full-precision rules. These rules provide the most
accurate fixed-point numerics. In this mode, other fixed-point properties do not
apply. No quantization occurs within the object. Bits are added, as needed, to
ensure that no roundoff or overflow occurs.
false
–– Fixed-point data types are controlled through
individual fixed-point property settings.
For more information, see Full Precision for Fixed-Point System Objects and Set System Object Fixed-Point Properties.
RoundingMethod
— Rounding method'Floor'
(default) | 'Ceiling'
| 'Convergent'
| 'Nearest'
| 'Round'
| 'Simplest'
| 'Zero'
Select the rounding mode for fixed-point operations.
This property applies when you set the FullprecisionOverride
property to false
and at least one of the
ProductDataType
, AccumulatorDataType
, and
OutputDataType
properties to any option other than
'Full precision'
.
OverflowAction
— Overflow action'Wrap'
(default) | 'Saturate'
The overflow action for fixed-point operations, specified as one of the following:
'Wrap'
–– The object wraps the result of its fixed-point
operations.
'Saturate'
–– The object saturates the result of its
fixed-point operations.
For more details on overflow actions, see overflow mode for fixed-point operations.
This property applies when you set the FullprecisionOverride
property to false
and at least one of the
ProductDataType
, AccumulatorDataType
, and
OutputDataType
properties to any option other than
'Full precision'
.
ProductDataType
— Product output data type'Full precision'
(default) | 'Custom'
| 'Same as first input'
Data type of the output of a product operation in the
dsp.Convolver
object, specified as one of the following:
'Full precision'
–– The object computes the product output
data type using the full-precision rules. These rules provide the most accurate
fixed-point numerics. No quantization occurs. Bits are added, as needed, to ensure
that no roundoff or overflow occurs.
'Custom'
–– The product output data type is specified as a
custom numeric type through the CustomProductDataType
property. The rounding method and the overflow action are specified through the
RoundingMethod
and OverflowAction
properties.
'Same as first input'
–– The object specifies the product
output data type to be the same as the first input data type.
For more information on the product output data type, see the Fixed Point section.
CustomProductDataType
— Product word and fraction lengthsnumerictype([],32,30)
(default)The product output data type, specified as an autosigned numeric type with a word length of 32 and a fraction length of 30.
This property applies only when you set ProductDataType
to
'Custom'
.
AccumulatorDataType
— Accumulator data type'Full precision'
(default) | 'Custom'
| 'Same as first input'
| 'Same as product'
Data type of the output of an accumulation operation in the
dsp.Convolver
object, specified as one of the following:
'Full precision'
–– The object computes the accumulator
data type using the full precision rules. These rules provide the most accurate
fixed-point numerics. No quantization occurs. Bits are added, as needed, to ensure
that no roundoff or overflow occurs.
'Custom'
–– The accumulator data type is specified as a
custom numeric type through the CustomAccumulatorDataType
property. The rounding method and the overflow action are specified through the
RoundingMethod
and the OverflowAction
properties.
'Same as first input'
–– The object specifies the
accumulator data type to be the same as the first input data type.
'Same as product'
–– The object specifies the accumulator
data type to be the same as the product data type.
For more information on the accumulator data type, see the Fixed Point section.
CustomAccumulatorDataType
— Accumulator word and fraction lengthsnumerictype([],32,30)
(default)The accumulator data type, specified as an auto signed numeric type with a word length of 32 and a fraction length of 30.
This property applies only when you set AccumulatorDataType
to 'Custom'
.
OutputDataType
— Output data type'Same as accumulator'
(default) | 'Custom'
| 'Same as first input'
| 'Same as product'
Data type of the output of the dsp.Convolver
object, specified as
one of the following:
'Same as accumulator'
–– The object specifies the output
data type to be the same as the accumulator data type. For more details on the
accumulator data type, see the AccumulatorDataType property.
'Custom'
–– The output data type is specified as a custom
numeric type through the CustomOutputDataType
property. The
rounding method and the overflow action are specified through the
RoundingMethod
and the OverflowAction
properties.
'Same as first input'
–– The object specifies the output
data type to be the same as the first input data type.
'Same as product'
–– The object specifies the output data
type to be the same as the product data type.
For more information on the output data type, see the Fixed Point section.
CustomOutputDataType
— Output word and fraction lengthsnumerictype([],16,15)
(default)The output data type, specified as an autosigned numeric type with a word length of 16 and a fraction length of 15.
This property applies only when you set OutputDataType
to
'Custom'
.
input1
— First data inputFirst data input, specified as a vector, matrix, or N-D array. If the input is a matrix or an array, all the dimensions of both the inputs, except for the first dimension, must be the same.
Example: ones(10,3,2)
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| fi
Complex Number Support: Yes
input2
— Second data inputSecond data input, specified as a vector, matrix, or N-D array. If the input is a matrix or an array, all the dimensions of both the inputs, except for the first dimension, must be the same.
Example: randn(4,3,2)
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| fi
Complex Number Support: Yes
cnvOut
— Convolved outputThe convolved output of the two inputs, returned as a vector, matrix, or N-D array.
When both inputs are N-D arrays, the size of their first dimension can differ, but the size of all other dimensions must be equal. For example, when u is an Mu-by-N-by-P array, and v is an Mv-by-N-by-P array, the output is an (Mu+Mv–1)-by-N-by-P array.
When one input is a column vector and the other is an N-D array, the object independently convolves the vector with the first dimension of the N-D input array. For example, when u is an Mu-by-1 column vector and v is an Mv-by-N matrix, the output is an (Mu+Mv–1)-by-N matrix.
When u and v are column vectors with lengths Mu and Mv, the object performs the vector convolution. The output is an (Mu+Mv–1)-by-1 column vector.
When both the inputs are real, the output is real. When one or both inputs are complex, the output is complex.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| fi
Complex Number Support: Yes
To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named obj
, use
this syntax:
release(obj)
Note: If you are using R2016a or earlier, replace each call to the object with the equivalent step syntax. For example, obj(x)
becomes step(obj,x)
.
Create a dsp.Convolver
object.
conv = dsp.Convolver
conv = dsp.Convolver with properties: Method: 'Time Domain' Show all properties
Convolve two rectangular sequences.
x = ones(10,1); y = conv(x,x);
Plot the resulting convolved sequence, which is a triangular sequence.
plot(y)
The convolution of two signals is the integral that measures the amount of overlap of one signal as it is shifted over another signal.
The convolution of two discrete time sequences, u[n] and v[n], is given by the following equation:
When you set the computation domain to time, the algorithm computes the convolution of the two inputs in the time domain.
When the two inputs, u and v, are of size Mu-by-N and Mv-by-N respectively, the jth column of the convolution output is given by the following equation:
Inputs u and v are zero when they are indexed outside their valid ranges.
When u is an Mu-by-1 column and v an Mv-by-N matrix, the output is an (Mu+Mv–1)-by-N matrix whose jth column is computed using the following equation:
When both the inputs are column vectors with lengths Mu and Mv, the object performs the vector convolution given by the following equation:
The output is an (Mu+Mv–1)-by-1 column vector.
When you set the computation domain to frequency, the algorithm computes the convolution in the frequency domain.
In this domain, the algorithm computes the convolution sequence by taking the Fourier transform of both the input signals, multiplying the Fourier transforms, and taking the inverse Fourier transform of the product. In this domain, depending on the input length, the algorithm can require fewer computations.
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).
The following diagram shows the data types used within the
dsp.Convolver
System object for fixed-point signals.
Fixed-point signals are supported for the time domain only.
The output of the multiplier is in the product output data type when the input is real. When the input is complex, the result of the multiplication is in the accumulator data type. For details on the complex multiplication performed, see Multiplication Data Types.
When one or both of the inputs are signed fixed-point signals, all internal object data types are signed fixed point. The internal data types are unsigned fixed point only when both inputs are unsigned fixed-point signals.
You have a modified version of this example. Do you want to open this example with your edits?