c = cconv(a,b,n)
circularly convolves vectors a and b.
n is the length of the resulting vector.
You can also use cconv to compute the circular
cross-correlation of two sequences.
Generate two complex sequences. Use cconv to compute their circular cross-correlation. Flip and conjugate the second operand to comply with the definition of cross-correlation. Specify an output vector length of 7.
a = [1 2 2 1]+1i;
b = [1 3 4 1]-2*1i;
c = cconv(a,conj(fliplr(b)),7);
Compare the result to the cross-correlation computed using xcorr.
The following example requires Parallel Computing Toolbox™ software. Refer to GPU Support by Release (Parallel Computing Toolbox) to see what GPUs are supported.
Create two signals consisting of a 1 kHz sine wave in additive white Gaussian noise. The sample rate is 10 kHz
Fs = 1e4;
t = 0:1/Fs:10-(1/Fs);
x = cos(2*pi*1e3*t)+randn(size(t));
y = sin(2*pi*1e3*t)+randn(size(t));
Put x and y on the GPU using gpuArray. Obtain the circular convolution using the GPU.
x = gpuArray(x);
y = gpuArray(y);
cirC = cconv(x,y,length(x)+length(y)-1);
Compare the result to the linear convolution of x and y.
linC = conv(x,y);
norm(linC-cirC,2)
ans =
1.4047e-08
Return the circular convolution, cirC, to the MATLAB® workspace using gather.
Input array, specified as vectors or gpuArray objects. See
Run MATLAB Functions on a GPU (Parallel Computing Toolbox) for details
on gpuArray objects. Using cconv with
gpuArray objects requires Parallel Computing Toolbox™ software. Refer to GPU Support by Release (Parallel Computing Toolbox) to see what GPUs
are supported.
Example: sin(2*pi*(0:9)/10) + randn([1 10])/10 specifies a noisy
sinusoid as a row vector.
Example: gpuArray(sin(2*pi*(0:9)/10) + randn([1 10])/10) specifies
a noisy sinusoid as a gpuArray
object.
Data Types: single | double Complex Number Support: Yes
n — Convolution length positive integer
Convolution length, specified as a positive integer. If you do not specify
n, then the convolution has length
length(a)+length(b)-1.
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.