Advertisement
V15H4L

Lab8

Oct 31st, 2023
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.73 KB | None | 0 0
  1. %------------------------------------------Task1
  2. clc;
  3. clear all;
  4.  
  5. x = [1,2];
  6. N = 2;
  7.  
  8. X = zeros(1,2);
  9.  
  10. X(1) = x(1) + x(2);
  11. X(2) = x(1) - x(2);
  12.  
  13. y = fft(x);
  14.  
  15. figure
  16. plot(x);
  17. figure
  18. plot(y);
  19.  
  20.  
  21. %-------------------------------------------Task2
  22. clc;
  23. clear all;
  24. close all;
  25. x = [1,2,3,4];
  26. N = length(x);
  27. k = [0,1,2,3];
  28. Wkn = zeros(1,length(k));
  29. for i = 1 : length(x)
  30.     Wkn(i) = exp(-2*1i*pi*k(i)/N);
  31. end
  32. X = zeros(1,4);
  33. V11 =  x(1) + Wkn(1)*x(3);
  34. V12 =  x(1) - Wkn(1)*x(3);
  35. V13 =  x(2) + Wkn(1)*x(4);
  36. V14 =  x(2) - Wkn(1)*x(4);
  37. X(1) =  V11 + Wkn(1)*V13;
  38. X(2) = V12 + Wkn(2)*V14;
  39. X(3) =  V11 - V13;
  40. X(4) =  V14*Wkn(2) + V12;
  41. Y = fft(x);
  42. subplot(2,1,1)
  43. stem(X);
  44. title('My FFT');
  45. subplot(2,1,2);
  46. stem(Y);
  47. title("In-built FFT");
  48.  
  49. %---------------------------------------------Task3
  50. clc;
  51. clear all;
  52. close all;
  53. x = [1, 2, 3, 4];
  54. X=x;
  55. N = length(x);
  56. Half = 1;
  57. V = log2(N);
  58. butterfly_no = N/2;
  59. x = [x, zeros(1, 2^V -N)];
  60. x = bitrevorder(x);
  61. for level = 1: V
  62. for index = 0: 2^level:N-1
  63. for n = 0 : (Half -1)
  64. position = n + index + 1;
  65. power = (2^(V-level))*n;
  66. w = exp(-2*1i* pi * power /N);
  67. a = x(position) + x(position + Half).*w;
  68. b = x(position) - x(position + Half).*w;
  69. x(position) = a;
  70. x(position + Half) = b;
  71. end
  72. end
  73. Half = Half * 2;
  74. end
  75. subplot(3, 1, 1)
  76. stem(X);
  77. title('Input Signal');
  78. subplot(3,1, 2)
  79. stem(abs(x));
  80. title('myFFT');
  81. subplot(3,1,3)
  82. Y = fft(X)
  83. stem(abs(Y));
  84. title('In-built FFT');
  85.  
  86. %---------------------------------------------Task4
  87. clc;
  88. clear all;
  89. close all;
  90. n=[2 4 8 16 32 64 128];
  91. N=length(n);
  92. speed=zeros(1,N);
  93. for i=1:N
  94.     speed(i)=(n(i)*n(i))/((n(i)/2)*log2(n(i)));
  95. end    
  96. stem(n,speed);
  97. ylabel('Speed-factor');
  98. xlabel('n');
  99. title('Speed-factor V/s N - 21ucc030');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement