Advertisement
_Mizanur

code

Nov 2nd, 2021
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.15 KB | None | 0 0
  1. lab5:
  2. clc;
  3. clear all;
  4. close all;
  5. x=input('Enter the sequence of 1st signal:');
  6. n1=input('Enter the time sample:');
  7. y=input('Enter the sequence of 2nd signal:');
  8. n2=input('Enter the time sample');
  9. z=input('Enter the sequence of 3rd signal:');
  10. n3=input('Enter the time sample:');
  11. u=min(min(n1),min(n2));
  12. t=max(max(n1),max(n2));
  13. n=u:1:t;
  14. z1=[];
  15. temp=1;
  16.  
  17. for i=1:length(n)
  18.     if (n(i)<min(n1) || n(i)>max(n1)) %make length of 1st signal equal to n with padding 0;
  19.         z1=[z1 0];
  20.     else
  21.         z1=[z1 x(temp)];%otherwise take same element
  22.         temp=temp+1;
  23.     end
  24. end
  25.  
  26. z2=[];
  27. temp=1;
  28. for i=1:length(n)
  29.     if (n(i)<min(n2) || n(i)>max(n2))
  30.         z2=[z2 0];
  31.     else
  32.         z2=[z2 y(temp)];
  33.         temp=temp+1;
  34.     end
  35. end
  36. subplot(5,1,1);
  37. stem(n1,x);
  38. subplot(5,1,2);
  39. stem(n2,y);
  40. %Addition
  41. p=z1+z2;
  42. subplot(5,1,3);
  43. stem(n,p);
  44. subplot(5,1,4);
  45. stem(n3,z);
  46. %folding
  47. subplot(5,1,5);
  48. stem(-n3,z);  
  49.  
  50. lab6:
  51.  
  52. clc;
  53. clear all;
  54. close all;
  55. n1=input('Enter the time range of 1st signal:');
  56. x=input('Enter the sequence:');
  57. n2=input('Enter the time range of 2nd signal:');
  58. y=input('Enter the sequence:');
  59. n3=input('Enter the time range of 3rd signal:');
  60. z=input('Enter the sequence:');
  61. u=min(min(n1),min(n2));
  62. t=max(max(n1),max(n2));
  63. n=u:1:t;
  64. z1=[];
  65. temp=1;
  66. for i=1:length(n)
  67.     if (n(i)<min(n1) || n(i)>max(n1))
  68.         z1=[z1 0];
  69.     else
  70.         z1=[z1 x(temp)];
  71.         temp=temp+1;
  72.     end
  73. end
  74.  
  75. z2=[];
  76. temp=1;
  77. for i=1:length(n)
  78.     if (n(i)<min(n2) || n(i)>max(n2))
  79.         z2=[z2 0];
  80.     else
  81.         z2=[z2 y(temp)];
  82.         temp=temp+1;
  83.     end
  84. end
  85. %multiplication
  86. m=z1.*z2;
  87. subplot(5,1,1);
  88. stem(n1,x);
  89. subplot(5,1,2);
  90. stem(n2,y);
  91. subplot(5,1,3);
  92. stem(n,m);
  93. subplot(5,1,4);
  94. stem(n3,x);
  95. %right shift with 2 unit
  96. n3=n3+2;
  97. subplot(5,1,5);
  98. stem(n3,x);
  99.  
  100. lab10:
  101.  
  102. clc;
  103. clear all;
  104. close all;
  105. x=input('Enter the sequence:');
  106. n=input('Enter the time range:');
  107. N=input('Enter the number of point:');
  108. if N>length(x)
  109.     for i=1:N-length(x)
  110.         x=[x 0];
  111.     end
  112. end
  113. X=[];
  114. xx=0;
  115. for n=0:N-1
  116.     for k=0:N-1
  117.         xx=xx+x(k+1)*exp(j*2*pi*n*k/N);
  118.     end
  119.     X=[X 1/N*(xx)];
  120.     xx=0;
  121. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement