OBJECT: To write a program to compute “Circular convolution” of two sequences x(n) and h(n).
x(n) = { 1, -1, -2, 3, -1 } and h(n) = { 1, 2, 3 }
Procedure: Here we have used two user defined functions:
This is circular convolution function
function [y] = circonv(x,h,N) for k=1:N y(k)=0; for i=1:N j=k-i+1 if(j<=0) j=N+j; end; y(k)=y(k)+x(i)*h(j); end; end;
This is zero padding function
function [x,h] = zeropadding(x,h,N); N1=length(x); N2=length(h); if(N==N1) h=[h zeros(1,(N-N2))]; else x=[x zeros(1,(N-N1))]; end;
main program
x=[1 -1 -2 3 -1]; h=[1 2 3]; L=max(length(x), length(h)); [x,h]=zeropadding(x,h,L); [y]=circonv(x,h,L); n=0:1:(L-1); stem(n,y); grid on; title('CIRCULAR CONVOLUTION'); xlabel('TIME INDEX'); ylabel('AMPLITUDE');
PROGRAM 2:
OBJECT: To find “circular convolution” using “DFT” and “IDFT” methods (using fft and ifft commands). Sequences are as given below:
x(n) = { 3, 4 , -2 , 0 , 1 , -4 } and h(n) = { 1 , -3 , 0 , 4 }
SOURCE CODE:
x=[3 4 -2 0 1 -4]; h=[1 -3 0 4]; l_x=length(x); l_h=length(h); L=max(l_x,l_h); [x,h]=zeropadding(x,h,L); %This will called "zeropadding" function written in previous program. X=fft(x); H=fft(h); y1=X.*H; y=ifft(y1); n=0:1:(L-1); stem(n,y); grid on; title('CIRCULAR CONVOLUTION USING DFT AND IDFT'); xlabel('TIME INDEX'); ylabel('AMPLITUDE');
RESULT:
y =
15 -1 -30 18 17 -15
OUTPUT GRAPH:
Index of DSP Lab Manual.