document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. %------------------------------------------------------------------------------------------------
  2. % ASSIGNMENT NO: 06
  3. % TITLE - COMPUTE THE CIRCULAR CONVOLUTION OF THE GIVEN TWO SEQUENCES AND TEST IT FOR LINEAR CONVOLUTION
  4. %------------------------------------------------------------------------------------------------
  5.  
  6. clc;
  7. clear all;
  8.  
  9. % initialization of input sequences
  10. x1=[0,1,2,3];
  11. x2=[2,1,1,2];
  12.  
  13. w1=[0,1,2,3,0,0,0];
  14. w2=[2,1,1,2,0,0,0];
  15.  
  16. len1=length(x1);
  17. len2=length(x2);
  18.  
  19. N=len1+len2-1;
  20.  
  21. % Memory allocation with initializing to zero values
  22. H=zeros(N,N);
  23. m=[0:1:N-1];
  24. w2=w2(mod(-m,N)+1);
  25.  
  26. % Calculations
  27. for n=1:1:N
  28.     H(n,:)=shifting(w2,n-1,N);
  29. end
  30. H
  31.  
  32. % Circular convolution
  33. y=w1*conj(H\')
  34.  
  35. % Linear convolution
  36. z=conv(x1,x2)
  37.  
  38. 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\'
  39.  
  40. %----------FUNCTION TO OBTAIN THE CIRCULAR SEQUENCE OF GIVEN SEQUENCE-----------------
  41.  
  42. function [h] = shifting(y,m,N)
  43.  
  44.     n=[0:1:N-1];
  45.     n=mod(n-m,N);
  46.     h=y(n+1);
  47.  
  48. end
');