ramytamer

Untitled

May 26th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.50 KB | None | 0 0
  1. % *******************************************************************
  2. %                          DSP Project #4
  3. % *******************************************************************
  4.  
  5. FS = 2000; startp = 0; endp = 10;
  6. N = startp:1/FS:endp;
  7.  
  8. % ========================
  9. %            A
  10. % ========================
  11.  
  12. xA = unitstep(0, startp, endp) - unitstep(6, startp, endp);
  13. yA = (1/FS) * fftshift(fft(xA));
  14. fA = linspace(-FS/2, FS/2, length(yA));
  15. figure;
  16. subplot(1,2,1);
  17. plot(fA, abs(yA));
  18. subplot(1,2,2);
  19. plot(fA, angle(yA));
  20.  
  21. % ========================
  22. %            B
  23. % ========================
  24.  
  25. xB = 2.^N .* linspace(0, 0, length(N));
  26. yB = (1/FS) * fftshift(fft(xB));
  27. fB = linspace(-FS/2, FS/2, length(yB));
  28. figure;
  29. subplot(1,2,1);
  30. plot(fB, abs(yB));
  31. subplot(1,2,2);
  32. plot(fB, angle(yB));
  33. % reflected unitstep from 0 -> 10 will be 0
  34. % So akid kolo 7ikon zero -_-
  35.  
  36. % ========================
  37. %            C
  38. % ========================
  39.  
  40. xC = (1/4).^N .* linspace(1, 1, length(N));
  41. yC = (1/FS) * fftshift(fft(xC));
  42. fC = linspace(-FS/2, FS/2, length(yC));
  43. figure;
  44. subplot(1,2,1);
  45. plot(fC, abs(yC));
  46. subplot(1,2,2);
  47. plot(fC, angle(yC));
  48. % Unit step start before the start point
  49. % So from -4 or (0 -> startpoint) till the end = 1
  50.  
  51. % ========================
  52. %            D
  53. % ========================
  54.  
  55. xD11 = (0.25 .^ N);
  56. xD12 = sin(2 * pi * 0.25 * N);
  57. xD1  = xD11 .* xD12;
  58. xD2  = linspace(1, 1, length(N));
  59. xD   = xD1 .* xD2;
  60. yD   = (1/FS) * fftshift(fft(xD));
  61. fD   = linspace(-FS/2, FS/2, length(yD));
  62. figure;
  63. subplot(1,2,1);
  64. plot(fD, abs(yD));
  65. subplot(1,2,2);
  66. plot(fD, angle(yD));
  67.  
  68. % ========================
  69. %            E
  70. % ========================
  71.  
  72. xE11 = (0.5 .^ N);
  73. xE12 = sin(2 * pi * 0.25 * N);
  74. xE  = xE11 .* xE12;
  75. yE   = (1/FS) * fftshift(fft(xE));
  76. fE   = linspace(-FS/2, FS/2, length(yE));
  77. figure;
  78. subplot(1,2,1);
  79. plot(fE, abs(yE));
  80. subplot(1,2,2);
  81. plot(fE, angle(yE));
  82.  
  83. % ========================
  84. %            F
  85. % ========================
  86.  
  87. startp = -4; endp = 4;
  88. N  = startp:1/FS:endp;
  89. xF = 2-(0.5 .* N);
  90. yF = (1/FS) * fftshift(fft(xF));
  91. fF = linspace(-FS/2, FS/2, length(yF));
  92. figure;
  93. subplot(1,2,1);
  94. plot(fF, abs(yF));
  95. subplot(1,2,2);
  96. plot(fF, angle(yF));
  97.  
  98. % ========================
  99. %            G
  100. % ========================
  101.  
  102. startp = -2; endp = 2;
  103. FS = 1;
  104. N  = startp:1/FS:endp;
  105. xG = [-2 -1 0 1 2];
  106. yG = fftshift(fft(xG));
  107. fG = linspace(-1/2, 1/2, length(yG));
  108. figure;
  109. subplot(1,2,1);
  110. plot(fG, abs(yG));
  111. subplot(1,2,2);
  112. plot(fG, angle(yG));
Advertisement
Add Comment
Please, Sign In to add comment