Calculate the circular convolution between x(n)= [1,4,-3,2] &
h(n)= [3,5,2,0,-1]. x=input('Enter the first sequence x(n) = '); h=input('Enter the second sequence h(n) = '); n1=length(x); n2=length(h); N=max(n1,n2); %Length of the output sequence x=[x,zeros(1,N-n1)]; h=[h,zeros(1,N-n2)]; for n=1:N %This for loop is for circular shifting y(n)=0; %Initialize the output y(n) for i=1:N %This for loop is for summation j=n-i+1; if j<=0 %This if loop is for circular folding j=N+j; end y(n)=y(n)+x(i)*h(j); end disp('The circular convolution of x and h is'); disp(y); subplot(3,1,1); stem(x); xlabel('--->n'); ylabel('---->x(n)'); title('First sequence'); grid; subplot(3,1,2); stem(h); xlabel('--->n'); ylabel('--->h(n)'); title('Second seq'); grid; subplot(3,1,3); stem(y); xlabel('--->n'); ylabel('--->y(n)'); title('Circular convoluted seq'); grid; RESULT:
Enter the first sequence x(n) = [1 4 -3 2] Enter the second sequence h(n) = [3 5 2 0 -1] The circular convolution of x and h is 3 20 11 -1 3