function y=circular_convolution(x,h) x= input ('enter the first sequence'); h= input ('enter the second sequence'); N1= length(x); N2= length(h); N=max(N1,N2);%length of sequence x=[x zeros(1,N-N1)]; %modified first sequence h=[h zeros(1,N-N2)]; %modified second sequence for n=0:N-1; y(n+1)=0; for i=0:N-1 j=mod(n-i,N); y(n+1)=y(n+1)+x(i+1)*h(j+1); %shifting and adding end end %to display and plot circular convolution n=1:N; disp('output sequence of circular convolution'); disp(y);%to view output in command window pause; stem(n,y);%plotting circular convolution grid minor; xlabel('time index'); ylabel('amplitude'); title('circular convolution sequence of x and h');

OUTPUT WAVEFORM

can u explain me how the mod command works for positive and negative values

ReplyDeleteit is just a remainder value.............there is no sign included

Deletehttp://mathforum.org/library/drmath/view/52343.html

ReplyDeleteI guess this would give the answer to your query@DHANESHBABU

This comment has been removed by the author.

ReplyDeleteThanks Quiz Champion. It appears to work fine for short vectors. On the other hand, for huge vectors like those coming from sampling a sound wave at 44.1 kHz the algorithm gets bogged down. Have to use Matlab's cconv in that case. Perhaps an alternative version using indexing might be in order. In any case, an interesting illustration of how the circular convolution is defined.

ReplyDeleteThanks dude.. You're a life saver..

ReplyDelete