CJamie

exp5

Oct 11th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. clc; clear all;
  2.  
  3. M = 25;
  4. v = 0:1:M-1;
  5. rec = zeros(length(M-1));
  6. tr = zeros(length(M-1));
  7. ham = zeros(length(M-1));
  8. han = zeros(length(M-1));
  9. blk = zeros(length(M-1));
  10. for n=0:1:M-1
  11. rec(n+1)=1;
  12. ham(n+1) = 0.54-(0.46*cos((2*pi*n)/(M-1)));
  13. han(n+1) = 0.5*(1-cos((2*pi*n)/(M-1)));
  14. blk(n+1) = 0.42-(0.5*cos((2*pi*n)/(M-1)))+(0.08*cos((4*pi*n)/(M-1)));
  15. if n<=(M-1)/2
  16. tr(n+1)=(2*n)/(M-1);
  17. elseif n>(M-1)/2 && n<=M-1
  18. tr(n+1)=2-((2*n)/(M-1));
  19. end
  20. end
  21. figure
  22. title('Time domain response for fixed windows(101915122)');
  23. subplot(2,3,1)
  24. plot(v,rec,'b')
  25. title('rectangular 101915122')
  26. xlabel('t')
  27. ylabel('Amplitude')
  28.  
  29. subplot(2,3,2)
  30. plot(v,tr,'m')
  31. title('triangular')
  32. xlabel('t')
  33. ylabel('Amplitude')
  34.  
  35.  
  36. subplot(2,3,3)
  37. plot(v,ham,'c')
  38. title('hamming')
  39. xlabel('t')
  40. ylabel('Amplitude')
  41.  
  42.  
  43.  
  44. subplot(2,3,4)
  45. plot(v,han,'r')
  46. title('hanning')
  47. xlabel('t')
  48. ylabel('Amplitude')
  49.  
  50. subplot(2,3,5)
  51. plot(v,blk,'g')
  52. title('blackman')
  53. xlabel('t')
  54. ylabel('Amplitude')
  55.  
  56. xlim([0,M+2]);
  57. ylim([0,1.1]);
  58.  
  59. N=1024
  60. xaxis= 0:1/N:(N-1)/N
  61. figure
  62. title('Frequency domain response for fixed windows(101915122)');
  63. subplot(2,3,1)
  64. fftrec= fft(rec,N)
  65. fyaxis= abs(fftrec/max(fftrec))
  66. yaxis= 20*log(fyaxis)
  67. plot(xaxis,fftshift(yaxis),'b')
  68. title('rectangular 101915122')
  69. xlabel('freq')
  70. ylabel('magnitude(db)')
  71.  
  72.  
  73. subplot(2,3,2)
  74. ffttr= fft(tr,N)
  75. fyaxis= abs(ffttr/max(ffttr))
  76. yaxis= 20*log(fyaxis)
  77. plot(xaxis,fftshift(yaxis),'m')
  78. title('triangular')
  79. xlabel('freq')
  80. ylabel('magnitude(db)')
  81.  
  82.  
  83. subplot(2,3,3)
  84. fftham= fft(ham,N)
  85. fyaxis= abs(fftham/max(fftham))
  86. yaxis= 20*log(fyaxis)
  87. plot(xaxis,fftshift(yaxis),'c')
  88. title('hamming')
  89. xlabel('freq')
  90. ylabel('magnitude(db)')
  91.  
  92.  
  93. subplot(2,3,4)
  94. ffthan= fft(han,N)
  95. fyaxis= abs(ffthan/max(ffthan))
  96. yaxis= 20*log(fyaxis)
  97. plot(xaxis,fftshift(yaxis),'r')
  98. title('hanning')
  99. xlabel('freq')
  100. ylabel('magnitude(db)')
  101.  
  102.  
  103. subplot(2,3,5)
  104. fftblk= fft(blk,N)
  105. fyaxis= abs(fftblk/max(fftblk))
  106. yaxis= 20*log(fyaxis)
  107. plot(xaxis,fftshift(yaxis),'g')
  108. title('blackman')
  109. xlabel('freq')
  110. ylabel('magnitude(db)')
  111.  
Advertisement
Add Comment
Please, Sign In to add comment