0% found this document useful (0 votes)
16 views

Convolution

The document contains code to perform both circular and linear convolution on input sequences. For both circular and linear convolution, the code takes in input sequences, displays them, pads them with zeros if needed to be the same length, transposes them, and shifts them to calculate their convolution, which is displayed.

Uploaded by

Poojasree Sankar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Convolution

The document contains code to perform both circular and linear convolution on input sequences. For both circular and linear convolution, the code takes in input sequences, displays them, pads them with zeros if needed to be the same length, transposes them, and shifts them to calculate their convolution, which is displayed.

Uploaded by

Poojasree Sankar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

% circular convolution

n1=input('enter the positive range');


n2=input('entet the negative range');
u1=input('enter the sequence');
subplot(3,1,1)
stem(n2:n1,u1)
n3=input('enter the positive range');
n4=input('entet the negative range');
u2=input('enter the sequence');
subplot(3,1,2)
stem(n4:n3,u2)
if (length(u1)>length(u2))
u2=[u2,zeros(1,length(u1)-length(u2))]
u2=transpose(u2)
u1=transpose(u1)
for i=2:length(u1)
u1(1,i)=u1(length(u1),i-1)
for j=2:length(u1)
u1(j,i)=u1(j-1,i-1)
end
end
end
if (length(u1)<length(u2))
u1=[u1,zeros(1,length(u2)-length(u1))]
u2=transpose(u2)
u1=transpose(u1)
for i=2:length(u1)
u1(1,i)=u1(length(u1),i-1)
for j=2:length(u1)
u1(j,i)=u1(j-1,i-1)
end
end
end
if (length(u1)==length(u2))
u2=transpose(u2)
u1=transpose(u1)
for i=2:length(u1)
u1(1,i)=u1(length(u1),i-1)
for j=2:length(u1)
u1(j,i)=u1(j-1,i-1)
end
end
end
z=u1*u2
subplot(3,1,3);

% linear convolution
n1=input('enter the positive range')
n2=input('entet the negative range')
u1=input('enter the sequence')
subplot(3,1,1)
stem(n2:n1,u1)
n3=input('enter the positive range')
n4=input('entet the negative range')
u2=input('enter the sequence')
subplot(3,1,2)
stem(n4:n3,u2)
N=n2+n4:n1+n3;
c1=length(u1)-1
c2=length(u2)-1
u1=[u1,zeros(1,c2)]
u2=[u2,zeros(1,c1)]
u2=transpose(u2)
u1=transpose(u1)
for i=2:length(N)
u1(1,i)=u1(length(u1),i-1)
for j=2:length(N)
u1(j,i)=u1(j-1,i-1)
end;
end;
z=u1*u2
subplot(3,1,3);
stem(N,z)

You might also like