Advertisement
regzarr

l7 dsp

Mar 30th, 2021 (edited)
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.26 KB | None | 0 0
  1. function [] = dft()
  2.  
  3. % 1 sin-wave 10Hz, amp 15, phase angle -pi/4
  4. % 1 sin-wave 30Hz, amp 20
  5. % 1 sin-wave 70Hz, amp 35, phase angle 3pi/4
  6.  
  7. Fs = 1000; % samples per second
  8. dT = 1/Fs; % seconds per sample
  9. stopTime = 0.2;
  10. t = (0:dT:stopTime-dT)';
  11.  
  12. Fc1 = 10;
  13. Fc2 = 30;
  14. Fc3 = 70;
  15. amp1 = 15;
  16. amp2 = 20;
  17. amp3 = 35;
  18. phaseAngle1 = (-pi / 4);
  19. phaseAngle3 = ((3 * pi) / 4);
  20.  
  21. y1 = amp1 * sin(2 * pi * Fc1 * t + phaseAngle1);
  22. y2 = amp2 * sin(2 * pi * Fc2 * t);
  23. y3 = amp3 * sin(2 * pi * Fc3 * t + phaseAngle3);
  24.  
  25. % figure;
  26. % plot(t,y1);
  27. % xlabel('Time (s)');
  28. % title('First wave vs time');
  29. %
  30. % figure;
  31. % plot(t,y2);
  32. % xlabel('Time (s)');
  33. % title('Second wave vs time');
  34. %
  35. % figure;
  36. % plot(t,y3);
  37. % xlabel('Time (s)');
  38. % title('Third wave vs time');
  39.  
  40. S = y1 + y2 + y3;
  41.  
  42. figure;
  43. plot(t,S);
  44. xlabel('Time (s)');
  45. ylabel('Amplitude');
  46. title('Input wave vs time');
  47.  
  48. S_fft = fft(S);
  49.  
  50. for i = 1:length(S_fft)
  51.     if (abs(S_fft(i)) < (10 ^ (-5)))
  52.         S_fft(i) = 0;
  53.     end
  54. end
  55.  
  56. freq = ((0:length(S_fft)-1) * Fs) / length(S_fft);
  57.  
  58. figure;
  59. plot(freq,abs(S_fft));
  60. xlabel('Frequency (Hz)');
  61. ylabel('Magnitude');
  62. title('FFT magnitude');
  63.  
  64. figure;
  65. plot(freq,angle(S_fft));
  66. xlabel('Frequency (Hz)');
  67. ylabel('Phase');
  68. title('FFT phase');
  69.  
  70. zoom xon;
  71. end
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement