You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.1KB

  1. %% Squarewave
  2. w0 = 2*pi/T;
  3. amp = 4*A/pi;
  4. tv = 0:T/50:2*T;
  5. ehv = amp*sin(w0*tv);
  6. dhv = (amp/3)*sin(3*w0*tv);
  7. vhv = (amp/5)*sin(5*w0*tv);
  8. blv = A*(sign(ehv));
  9. epdhv = ehv + dhv;
  10. epdpvhv = epdhv + vhv;
  11. maxamp=max(ehv);
  12. mA=ceil(maxamp);
  13. clear ax
  14. figure(1);
  15. set(clf,'PaperType','A4');
  16. set(clf,'Color',[1,1,1]);
  17. ax(1) = subplot(221);
  18. plot(tv, blv, tv, ehv, tv, dhv, tv, vhv);
  19. xlabel('time [ms]','Fontsize',8);
  20. title('first three harmonics','Fontsize',8);
  21. set(gca,'Fontsize',8);
  22. ax(end+1) = subplot(222);
  23. plot(tv, blv, tv, ehv);
  24. xlabel('time [ms]','Fontsize',8);
  25. title('first harmonic','Fontsize',8);
  26. set(gca,'Fontsize',8);
  27. ax(end+1) = subplot(223);
  28. plot(tv, blv, tv, epdhv);
  29. xlabel('time [ms]','Fontsize',8);
  30. title('sum first and third harmonic','Fontsize',8);
  31. set(gca,'Fontsize',8);
  32. ax(end+1) = subplot(224);
  33. plot(tv, blv, tv, epdpvhv);
  34. xlabel('time [ms]','Fontsize',8);
  35. title('sum of all harmonics','Fontsize',8);
  36. set(gca,'Fontsize',8);
  37. linkaxes(ax)
  38. %% Triangular Wave
  39. amp = -(8*B)/(pi^2);
  40. tv = 0:T/50:2*T;
  41. ehv = amp*cos(w0*tv);
  42. dhv = (amp/9)*cos(3*w0*tv);
  43. vhv = (amp/25)*cos(5*w0*tv);
  44. rc = 4*B/T;
  45. T2 = T/2;
  46. T15 = 3*T/2;
  47. drv=[];
  48. for t=tv
  49. if (t<T2) drv=[drv -B+rc*t]; end
  50. if (T2<=t)&&(t<T) drv=[drv 3*B-rc*t]; end
  51. if (T<=t)&&(t<T15) drv=[drv -5*B+rc*t]; end
  52. if (T15<=t) drv=[drv 7*B-rc*t]; end
  53. end
  54. epdhv = ehv + dhv;
  55. epdpvhv = epdhv + vhv;
  56. figure(2);
  57. set(clf,'PaperType','A4');
  58. set(clf,'Color',[1,1,1]);
  59. ax(end+1) = subplot(221);
  60. plot(tv, drv, tv, ehv, tv, dhv, tv, vhv);
  61. xlabel('time [ms]','Fontsize',8);
  62. title('first three harmonics','Fontsize',8);
  63. set(gca,'Fontsize',8);
  64. ax(end+1) = subplot(222);
  65. plot(tv, drv, tv, ehv);
  66. xlabel('time [ms]','Fontsize',8);
  67. title('first harmonic','Fontsize',8);
  68. set(gca,'Fontsize',8);
  69. ax(end+1) = subplot(223);
  70. plot(tv, drv, tv, epdhv);
  71. xlabel('time [ms]','Fontsize',8);
  72. title('sum first and third harmonic','Fontsize',8);
  73. set(gca,'Fontsize',8);
  74. ax(end+1) = subplot(224);
  75. plot(tv, drv, tv, epdpvhv);
  76. xlabel('time [ms]','Fontsize',8);
  77. title('sum of all harmonics','Fontsize',8);
  78. set(gca,'Fontsize',8);
  79. linkaxes(ax(5:8))
  80. arrayfun(@(x) set(x,{'XGrid','YGrid'},{'on','on'}),ax)