Advertisement
makispaiktis

PSES_DFT_rekanos

Nov 2nd, 2020 (edited)
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.08 KB | None | 0 0
  1. clear all
  2. clc
  3.  
  4. % ******************************************************************
  5. % 1. LATHOS TROPOS NA VRW TIN Y
  6. % ******************************************************************
  7.  
  8. x = cos(0.5 * [1:1:20]);
  9. h = 0.1 * abs([1:1:20] - 10);
  10. y = conv(x, h)      % 39 deigmata = 20+20-1 - SWSTO
  11. X = fft(x);     % Complex me 20 deigmata opws kai h x[n]
  12. H = fft(h);             % Complex me 20 deigmata opws kai h h[n]
  13. Ytest = X .* H;         % Diastasi Ytest = 20, logw ginomenou X .* H
  14. ytest = ifft(Ytest);    % Ytest me 20 ----> ytest me 20 ----> Lathos
  15. Y = fft(y);
  16.  
  17. % PLOT 1
  18. plot(x, 'red');
  19. hold on
  20. plot(h, 'blue');
  21. hold on
  22. plot(y, 'green')            % Swsti h synelixi me 39
  23. hold on
  24. plot(ytest, 'black');       % Lathos me 20 stoixeia
  25. title('Samples in time');
  26. legend('red=sample1', 'blue=sample2', 'black=WRONG', 'green=CORRECT');
  27.  
  28. % PLOT 2
  29. figure
  30. plot(abs(X), 'red');
  31. hold on
  32. plot(abs(H), 'blue');
  33. hold on
  34. plot(abs(Ytest), 'black');
  35. hold on
  36. plot(abs(Y), 'green');
  37. title('Black=ifft(fft(product)) vs Convolution');
  38.  
  39. % Nai, alla to mauro fasma Ytest einai o DFT tou y = x synelixi h?
  40. % Kati tetoio den isxyei
  41. % Tha to dw to lathos me ifft
  42. % To ytest einai lathos exei 20 anti 39
  43.  
  44.  
  45. % ******************************************************************
  46. % ZERO PANTING = SWSTOS TROPOS NA TO VRW
  47. % ******************************************************************
  48.  
  49. xx = zeros(1,39);       % xx me 39 deigmata
  50. xx(1:20) = x;
  51. hh = zeros(1,39);       % hh me 39 deigmata
  52. hh(1:20) = h;
  53. XX = fft(xx);           % 39
  54. HH = fft(hh);           % 39
  55. YY = XX .* HH;          % 39
  56. yy = real(ifft(YY));        % H yy exei kai ayti 39 (afou exei 39 kai h YY) = swsto = iso me tin synelixi tou plot 1 me to mauro
  57. % Gia ypologistikes astoxies to real()
  58.  
  59. % PLOT 3
  60. figure
  61. plot(xx, 'red');
  62. hold on
  63. plot(hh, 'blue');
  64. plot(yy, 'green')           % ******** PREPEI AYTIN H MAYRI yy tou plot 3 na einai idia me tin swsti SYNELIXI tou plot 1 ********
  65. title('Zero padding (19)');
  66.  
  67. % PLOT 4
  68. figure
  69. plot(abs(XX), 'red');
  70. hold on
  71. plot(abs(HH), 'blue');
  72. hold on
  73. plot(abs(YY), 'green');
  74. title('Zero padding CORRECT with ifft(fft(product))');
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement