Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PWM of sine signal
- const n = 12;
- const maxAngle_rad = 3 * Math.PI;
- const dAngle_rad = maxAngle_rad / n;
- var sum = 0;
- for (let i = 0; i < n; i++) {
- const angle_rad = dAngle_rad * (i + 1);
- const sinp1 = 1 + Math.sin(angle_rad); //normalized so that minimum value of sine signal is between [0, 2]
- const dutyCyle = sinp1 / 2; //PWM duty cycle
- //sum += sinp1 * 2 * Math.PI / n;
- sum += dutyCyle;
- console.log(angle_rad * 180 / Math.PI + ", " + sinp1 + ", " + dutyCyle);
- }
- console.log("\nsum: " + sum);
- const integralOfSinePlus1 = (maxAngle_rad - 0) - (Math.cos(maxAngle_rad) - Math.cos(0)); //t-cos(t) [0, maxAngle]
- console.log("diff from integral: " + (integralOfSinePlus1/dAngle_rad/2.0 - sum));
Add Comment
Please, Sign In to add comment