Advertisement
Guest User

632 lab 4 AB

a guest
Mar 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.94 KB | None | 0 0
  1. %% Part A
  2. %problem 1
  3. xn=[1 6/7 5/7 4/7 3/7 2/7 1/7 zeros(1,121)];
  4. n=0:127;
  5. xf=fft(xn);
  6. xf=fftshift(xf);
  7. plot(n.*2*pi/128,abs(xf));
  8. title("fft calculated magnitude plot");
  9. figure;
  10. plot(n.*2*pi/128,angle(xf));
  11. title("fft calculated phase plot");
  12.  
  13. %problem 2
  14. %{
  15. xf2=zeros(1,128);
  16. omega=linspace(-pi,pi,128);
  17. temp=1;
  18. for omega= linspace(-pi,pi,128)
  19.     xf2(temp)=sum(xn.*exp(-1i*omega*n));
  20.     temp=temp+1;
  21. end
  22. %}
  23. xomega=@(o) exp(-0i.*o) + (6/7)*exp(-i.*o) + (5/7)*exp(-2i.*o) + (4/7)*exp(-3i.*o) + (3/7)*exp(-4i.*o) + (2/7)*exp(-5i.*o) + (1/7)*exp(-6i.*o);
  24. figure;
  25. omega=n.*2*pi/128;
  26. xf2=xomega(omega);
  27. xf2=fftshift(xf2);
  28. plot(omega,abs(xf2));
  29. title("Manually calculated magnitude plot");
  30. figure;
  31. plot(omega,angle(xf2));
  32. title("Manually calculated phase plot");
  33.  
  34. %Problem 3
  35. Xn=ifft(xf);
  36. figure;
  37. stem(n,Xn);
  38. title("original signal without abs function");
  39. figure;
  40. stem(n,abs(Xn));
  41. title("original signal with abs function");
  42.  
  43. %% Part B
  44.  
  45. un= @(n) 1.0.*(n>=0);
  46. und= @(n) un(n).*(mod(n,1)==0);  
  47. n=[0:15];
  48. xn=sin(2*pi.*n/10).*(und(n)-und(n-10));
  49. omega=linspace(-pi,pi,1001);
  50. W_omega1=exp(-j).^((0:length(xn)-1)'*omega);
  51. X1=(xn*W_omega1);
  52. plot(omega, abs(X1));
  53. title("magnitude of x[n] FT");
  54. figure;
  55. plot(omega, angle(X1));
  56. title("phase of x[n] FT");
  57. figure;
  58. hn=und(n)-und(n-10);
  59. W_omega2=exp(-j).^((0:length(hn)-1)'*omega);
  60. X2=(hn*W_omega2);
  61. plot(omega, abs(X2));
  62. title("magnitude of h[n] FT");
  63. figure;
  64. plot(omega, angle(X2));
  65. title("phase of h[n] FT");
  66. figure;
  67. yf=X1.*X2;
  68. plot(omega,abs(yf));
  69. title("magnitude of X[\Omega]H[\Omega]");
  70. figure;
  71. plot(omega, angle(yf));
  72. title("phase of X[\Omega]H[\Omega]");
  73. yn=conv(xn,hn);
  74. W_omega3=exp(-j).^((0:length(yn)-1)'*omega);
  75. X3=(yn*W_omega3);
  76. figure;
  77. plot(omega,abs(X3));
  78. title("magnitude of y[n]");
  79. figure;
  80. plot(omega,angle(X3));
  81. title("phase of y[n]");
  82.  
  83. disp("convolution in the time domain is the same thing as multiplication in the frequency domain");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement