CJamie

exp4

Oct 11th, 2021
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. clc
  2. clear all
  3. % n= (-10:10);%generating independent variables
  4. x = input('input the first sequence: ')
  5. h = input('input the second sequence:')
  6.  
  7. subplot(3,1,1);
  8. stem(x);
  9. xlabel('n'); %FOR LABELING X AND Y
  10. ylabel('x');
  11. title('x(n)-1019151220');
  12.  
  13. subplot(3,1,2);
  14. stem(h);
  15. xlabel('n'); %FOR LABELING X AND Y
  16. ylabel('h');
  17. title('h(n)-101915122');
  18.  
  19. %for linear convuution length
  20. N1=length(x);
  21. N2=length(h);
  22. N=N1+N2-1;
  23.  
  24. xn=[x,zeros(1,N-N1)];
  25. hn=[h,zeros(1,N-N2)];
  26. y=zeros(1,N);
  27.  
  28. %circular convulution length
  29. for i=0:N-1
  30. for j=0:N-1
  31. z=mod(i-j,N);
  32. y(i+1) = y(i+1) + xn(j+1).*hn(z+1);
  33. end
  34. z;
  35. end
  36. disp('Linear convulution using circular covulution sequence is given as (101915122): ');y
  37. subplot(3,1,3);
  38. stem(y);
  39. xlabel('k'); %FOR LABELING X AND Y
  40. ylabel('y(n)');
  41. title('Linear convulution using circutlar convulution-101915122');
  42. _______________________________________________________________
  43.  
  44. 4b
  45.  
  46. clc
  47. clear all
  48. % n= (-10:10);%generating independent variables
  49. x = input('input the first sequence: ')
  50. h = input('input the second sequence:')
  51.  
  52. subplot(3,1,1);
  53. stem(x);
  54. xlabel('n'); %FOR LABELING X AND Y
  55. ylabel('x');
  56. title('x(n)-1019151220');
  57.  
  58. subplot(3,1,2);
  59. stem(h);
  60. xlabel('n'); %FOR LABELING X AND Y
  61. ylabel('h');
  62. title('h(n)-101915122');
  63.  
  64. %for linear convuution length
  65. N1=length(x);
  66. N2=length(h);
  67. N=N1+N2-1;
  68.  
  69. xn=[x,zeros(1,N-N1)];
  70. hn=[h,zeros(1,N-N2)];
  71. y=zeros(1,N);
  72.  
  73. %circular convulution length
  74. for i=0:N-1
  75. for j=0:N-1
  76. z=mod(i-j,N);
  77. y(i+1) = y(i+1) + xn(j+1).*hn(z+1);
  78. end
  79. z;
  80. end
  81. disp('Linear convulution using circular covulution sequence is given as (101915122): ');
  82. y
  83. subplot(3,1,3);
  84. stem(y);
  85. xlabel('k'); %FOR LABELING X AND Y
  86. ylabel('y(n)');
  87. title('Linear convulution using circutlar convulution-101915122');
  88.  
  89. ______________________________________________________________
  90.  
  91. % 4c
  92.  
  93. clc;
  94. clear all;
  95. % n= (-10:10);%generating independent variables
  96. %humesha start from 1:n array me store krane k liye
  97. x = input('input the first sequence: ')
  98. h = input('input the second sequence:')
  99.  
  100. subplot(4,1,1);
  101. stem(x);
  102. xlabel('n'); %FOR LABELING X AND Y
  103. ylabel('x');
  104. title('x(n)-101915122');
  105.  
  106. subplot(4,1,2);
  107. stem(h);
  108. xlabel('n'); %FOR LABELING X AND Y
  109. ylabel('h');
  110. title('h(n)-101915122');
  111.  
  112. m=length(x);
  113. n=length(h);
  114.  
  115. hn=[h,zeros(1,m-1)];
  116. xn=[x,zeros(1,n-1)];
  117.  
  118. y=zeros(1,m+n-1);
  119.  
  120. for i=1:m+n-1
  121. sum=0;
  122. for j=1:i
  123. sum=sum+(xn(j)*hn(i-j+1));
  124. end
  125. y(i)=sum;
  126. end
  127. % disp('Linear convolution is given as (101915122): ');
  128. y;
  129. subplot(4,1,3);
  130. stem(y);
  131. xlabel('n'); %FOR LABELING X AND Y
  132. ylabel('y(n)');
  133. title('Linear convulution-101915122');
  134.  
  135. %code or circular ---->
  136. %find the linear convulution ----> jitna extra aa rha uuse add krr do pehle dosre (see graph nb) ---->
  137.  
  138. %length of linear convulution peeche se iteration start krrna
  139. N=max(n,m); %defines the output buffer
  140. p=zeros(1,N);
  141. q=zeros(1,N);
  142. z=zeros(1,N);
  143. for i=1:N
  144. %z(i) me store krana
  145. p(i)=y(i);
  146. end
  147. p;
  148. for i=1:m+n-1-N
  149. q(i)=y(N+i);
  150. %add last wala to first circularly
  151. end
  152. q;
  153. for i=1:N
  154. z(i)=p(i)+q(i);
  155. %add last wala to first circularly
  156. end
  157. disp('Circular convolution using linear convolution is given as (101915122): ')
  158. z
  159. subplot(4,1,4);
  160. stem(z);
  161. xlabel('n'); %FOR LABELING X AND Y
  162. ylabel('z(n)');
  163. title('Circular convulution using Linear convulution-101915122');
  164.  
  165.  
  166. % 4d
  167.  
  168. clc;
  169. clear all;
  170. n= (-10:10);%generating independent variables
  171. x = input('input the first sequence: ')
  172. h = input('input the second sequence:')
  173.  
  174. N1=length(x);
  175. N2=length(h);
  176. N=max(N1,N2);
  177.  
  178. disp('dft of x(n)= X(k)')
  179. xf=fft(x,N)
  180. disp('dft of h(n)= H(k)')
  181. hf=fft(h,N)
  182.  
  183. disp('multiplication of X(k) and H(k)= Y(k)')
  184. yk=xf.*hf
  185.  
  186. disp('idft of Y(k) = y(n)')
  187. yn=ifft(yk)
  188.  
  189. disp('circular convulution of x(n) and h(n) (101915122)')
  190. y=cconv(x,h,N)
  191.  
  192. subplot(4,1,1);
  193. stem(x);
  194. xlabel('n'); %FOR LABELING X AND Y
  195. ylabel('x(n)');
  196. title('x(n) - 101915122');
  197.  
  198. subplot(4,1,2);
  199. stem(h);
  200. xlabel('n'); %FOR LABELING X AND Y
  201. ylabel('h(n)');
  202. title('h(n) - 101915122');
  203.  
  204. subplot(4,1,3);
  205. stem(yn);
  206. xlabel('n'); %FOR LABELING X AND Y
  207. ylabel('y(n)');
  208. title('Circular convultion by IDFT-101915122');
  209.  
  210. subplot(4,1,4);
  211. stem(y);
  212. xlabel('n'); %FOR LABELING X AND Y
  213. ylabel('y(n)');
  214. title('Circular convultion by inbuit function-101915122');
Advertisement
Add Comment
Please, Sign In to add comment