主要内容

CCONV

Modulo-n circular convolution

Description

example

c= cconv(a,b)卷积矢量ab

example

c= cconv(a,b,n)circularly convolves vectorsabnis the length of the resulting vector. You can also useCCONV计算两个序列的圆形互相关。

Examples

collapse all

Generate two signals of different lengths. Compare their circular convolution and their linear convolution. Use the default value forn

a = [1 2 -1 1]; b = [1 1 2 1 2 2 1 1]; c = cconv(a,b);%圆形卷积cref = conv(a,b);%线性卷积dif = norm(c-cref)
dif = 9.7422e-16

The resulting norm is virtually zero, which shows that the two convolutions produce the same result to machine precision.

Generate two vectors and compute their modulo-4 circular convolution.

a = [2 1 2 1]; b = [1 2 3 4]; c = cconv(a,b,4)
C =1×414 16 14 16

Generate two complex sequences. UseCCONV计算它们的圆形互相关。翻转并结合第二个操作数以符合互相关的定义。指定输出向量长度为​​7。

a = [1 2 2 1]+1i; b = [1 3 4 1]-2*1i; c = cconv(a,conj(fliplr(b)),7);

将结果与使用的互相关进行比较xcorr

cref = xcorr(a,b); dif = norm(c-cref)
DIF = 3.3565E-15

生成两个信号:一个五样本三角波形和带有响应的一阶Fir滤波器 H ( z ) = 1 - z - 1

x1 = conv([1 1 1],[1 1 1])
x1 =1×51 2 3 2 1
x2 = [-1 1]
x2 =1×2-1 1

用默认输出长度计算其圆形卷积。结果等效于两个信号的线性卷积。

ccnv = cconv(x1,x2)
ccnv =1×6-1.0000 -1.0000 -1.0000 1.0000 1.0000 1.0000
lcnv = conv(x1,x2)
lcnv =1×6-1 -1 -1 1 1 1

The modulo-2 circular convolution is equivalent to splitting the linear convolution into two-element arrays and summing the arrays.

ccn2 =CCONV(x1,x2,2)
ccn2 =1×2-1 1
nl = numel(lcnv); mod2 = sum(reshape(lcnv,2,nl/2)')
mod2 =1×2-1 1

Compute the modulo-3 circular convolution and compare it to the aliased linear convolution.

ccn3 = cconv(x1,x2,3)
ccn3 =1×30 0 0
mod3 = sum(reshape(lcnv,3,nl/3)')
mod3 =1×30 0 0

If the output length is smaller than the convolution length and does not divide it exactly, pad the convolution with zeros before adding.

C =5; z = zeros(c*ceil(nl/c),1); z(1:nl) = lcnv; ccnc = cconv(x1,x2,c)
ccnc =1×50.0000 -1.0000 -1.0000 1.0000 1.0000
modc = sum(reshape(z,c,numel(z)/c)')
modc =1×50 -1 -1 1 1

如果输出长度等于或大于卷积长度,请填充卷积,不要添加。

d = 13; z = zeros(d*ceil(nl/d),1); z(1:nl) = lcnv; ccnd = cconv(x1,x2,d)
ccnd =1×13-1.0000 -1.0000 -1.0000 1.0000 1.0000 1.00000.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000
modd =z'
modd =1×13-1 -1 -1 1 1 1 0 0 0 0 0 0 0

The following example requires Parallel Computing Toolbox™ software. Refer toGPU Support by Release(Parallel Computing Toolbox)看看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));

Putxyon the GPU usinggpuArray。Obtain the circular convolution using the GPU.

x = gpuarray(x);y = gpuarray(y);circ = cconv(x,y,长度(x)+长度(y)-1);

将结果与x和y的线性卷积进行比较。

linc = conv(x,y);规范(linc-cir,2)
ANS = 1.4047E-08

Return the circular convolution,cirC,使用Matlab®工作区gather

circ =聚集(circ);

Input Arguments

collapse all

Input array, specified as vectors orgpuArray对象。SeeRun MATLAB Functions on a GPU(Parallel Computing Toolbox)for details ongpuArray对象。使用CCONVwithgpuArrayobjects requires Parallel Computing Toolbox™ software. Refer toGPU Support by Release(Parallel Computing Toolbox)看看GPUs are supported.

例子:sin(2*pi*(0:9)/10) + randn([1 10])/10指定嘈杂的正弦曲线为行矢量。

例子:gpuarray(sin(2*pi*(0:9)/10) + randn([1 10])/10)specifies a noisy sinusoid as agpuArray目的。

Data Types:single|double
Complex Number Support:Yes

卷积长度, specified as a positive integer. If you do not specifyn,然后卷积长度length(a)+length(b)-1

Output Arguments

collapse all

输入向量的循环卷积,作为向量返回或gpuArray

提示

For long sequences, circular convolution can be faster than linear convolution.

参考

[1] Orfanidis,Sophocles J.信号处理简介。新泽西州Englewood Cliffs:Prentice-Hall,1996年,第524–529页。

Extended Capabilities

C/C++ Code Generation
使用MATLAB®CODER™生成C和C ++代码。

See Also

|

Introduced in R2007a