Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %syms p q % needed only when poly2sym() is used
- run_loop=1;
- while run_loop==1
- x=input('enter 1st sequence');
- h=input('enter 2nd sequence');
- x_str=char(int2str(x));
- h_str=char(int2str(h));
- %x_str=char(poly2sym(x,p)); %this returns the sequence as a polynomial
- %h_str=char(poly2sym(h,q));
- N1=length(x);
- N2=length(h);
- %N=max(N1,N2)
- N=(N1+N2-1) % circular convolution using N=max(N1,N2) will result in aliasing of (N2-1) points if N1 not=N2
- y=conv(x,h)
- yc=cconv(x,h,N)
- n=0:1:N1-1;
- subplot(2,2,1);
- stem(n,x)
- xlabel('No. of samples');
- ylabel('amplitude');
- title(['First sequence:',x_str]);
- n=0:1:N2-1;
- subplot(2,2,2);
- stem(n,h)
- xlabel('No. of samples');
- ylabel('amplitude');
- title(['Second sequence:',h_str]);
- n=0:1:(N1+N2)-2;
- subplot(2,2,3);
- stem(n,y)
- xlabel('No. of samples');
- ylabel('amplitude');
- title('Sequence for linear convolution');
- n=0:1:N-1;
- subplot(2,2,4);
- stem(n,yc)
- xlabel('No. of samples');
- ylabel('amplitude');
- title('Sequence for circular convolution');
- run_loop=input('continue with another convolution? 1(YES), 0(NO):')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement