Guest User

Untitled

a guest
Nov 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. //PWM of sine signal
  2. const n = 12;
  3. const maxAngle_rad = 3 * Math.PI;
  4. const dAngle_rad = maxAngle_rad / n;
  5. var sum = 0;
  6. for (let i = 0; i < n; i++) {
  7. const angle_rad = dAngle_rad * (i + 1);
  8. const sinp1 = 1 + Math.sin(angle_rad); //normalized so that minimum value of sine signal is between [0, 2]
  9. const dutyCyle = sinp1 / 2; //PWM duty cycle
  10. //sum += sinp1 * 2 * Math.PI / n;
  11. sum += dutyCyle;
  12. console.log(angle_rad * 180 / Math.PI + ", " + sinp1 + ", " + dutyCyle);
  13. }
  14. console.log("\nsum: " + sum);
  15. const integralOfSinePlus1 = (maxAngle_rad - 0) - (Math.cos(maxAngle_rad) - Math.cos(0)); //t-cos(t) [0, maxAngle]
  16. console.log("diff from integral: " + (integralOfSinePlus1/dAngle_rad/2.0 - sum));
Add Comment
Please, Sign In to add comment