function [ y ] = cyclic_conv( xn0,hn0,N )
%cyclic_conv 循环卷积运算
%计算xn与yn的N点循环卷积
%xn0-序列,hn0-序列,N-循环卷积点数
xn1=[xn0,zeros(1,N-length(xn0))]; %补零
hn=[hn0,zeros(1,N-length(hn0))]';
xn2=fliplr(xn1); %元素按索引倒序排列
for i=1:N
xn(i,:)=circshift(xn2,[1,-(N-i)]); %循环卷积矩阵
end
y=xn*hn;
end
测试代码如下:
xn=[1 2 3 4];
hn=[1 1 1 1];
N1=4;
N2=8;
y1=cyclic_conv(xn,hn,N1)
y2=cyclic_conv(xn,hn,N2)