arpit01

Frequency spectrum of a periodic signal

Nov 28th, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. clc
  2. clear all
  3. close all
  4. t=0:0.01:10;
  5. x=[ones(1,201),zeros(1,99),ones(1,201),zeros(1,99),ones(1,201),zeros(1,99),ones(1,101)];
  6. T=3;
  7. w=2*pi/T;
  8.  
  9.  
  10. dtau=0.1;
  11. for k=-10:10
  12. sum = 0;
  13. i=1;
  14. for tau=0:dtau:T
  15. exp_part = exp(-j*w*k*tau)*dtau;
  16. sum = sum + exp_part.*x(i);
  17. i=i+1;
  18. end
  19. a(k+11) = sum;
  20. end
  21. for i=1:21
  22. mag(i) = abs(a(i));
  23. phase(i) = angle(a(i));
  24. end
  25. k=-10:10;
  26. subplot(2,2,[1:2]);
  27. plot(t,x);
  28. title('Input Signal (A Pulse Train)');
  29. xlabel('Time');
  30. ylabel('Amlitudeof the signal');
  31.  
  32.  
  33. subplot(2,2,3);
  34. stem(k,mag);
  35. title('Magnitude Spectra');
  36. xlabel('k \rightarrow');
  37. ylabel('Magnitude');
  38.  
  39.  
  40. subplot(2,2,4);
  41. stem(k,phase,'Linewidth',1.2);
  42. title('Phase Spectra');
  43. xlabel('k \rightarrow');
  44. ylabel('Phase');
Add Comment
Please, Sign In to add comment