%------------------------------------------------------------------------------------------------
% ASSIGNMENT NO: 06
% TITLE - COMPUTE THE CIRCULAR CONVOLUTION OF THE GIVEN TWO SEQUENCES AND TEST IT FOR LINEAR CONVOLUTION
%------------------------------------------------------------------------------------------------
clc;
clear all;
% initialization of input sequences
x1=[0,1,2,3];
x2=[2,1,1,2];
w1=[0,1,2,3,0,0,0];
w2=[2,1,1,2,0,0,0];
len1=length(x1);
len2=length(x2);
N=len1+len2-1;
% Memory allocation with initializing to zero values
H=zeros(N,N);
m=[0:1:N-1];
w2=w2(mod(-m,N)+1);
% Calculations
for n=1:1:N
H(n,:)=shifting(w2,n-1,N);
end
H
% Circular convolution
y=w1*conj(H\')
% Linear convolution
z=conv(x1,x2)
comment = \'For making the length of circular convolution and linear convolution same we have added necessary zeros in x1 and x2 (zero padding)then we have performed circular convolution then the result of linear and circular convolution will be same\'
%----------FUNCTION TO OBTAIN THE CIRCULAR SEQUENCE OF GIVEN SEQUENCE-----------------
function [h] = shifting(y,m,N)
n=[0:1:N-1];
n=mod(n-m,N);
h=y(n+1);
end