Equation for trapezoidal wave equation

空扰寡人 提交于 2019-12-23 12:16:46

问题


I'm writing a c function to generate trapezoidal wave. Does any one know a mathematical equation to generate trapezoidal wave? Very similar idea as y=A*sin(B*x) generates a sin wave for different values of x.


回答1:


A way of sending a single pulse of trapezoidal wave includes using the Heaviside Step Function http://en.wikipedia.org/wiki/Heaviside_step_function

Use it if you want the "pure" mathematical way of representing this kind of function. Just build your function "piece by piece", multiply the first piece by a heaviside that "activates" when x = the beginning of your pulse. For the next piece, first subtract the last function, then add the new piece mathematical function, multiply it by the adequate heaviside function and so on. It should end something like this (if you don't get it, go through the wikipedia article):

H(n) := (x >= n)?1:0;
y := H(0)*(x) + H(1)*(-x + 1) + H(2)*(-(-x + 1) + (3-x));

However, for code simplicity and efficiency, lets use an if statement. Consider a 45-degree trapezoidal wave, with constant unitary velocity.

float trapezoidalWave(float x, float t) {

    float y;

    if ( x <= t + 1 ) {
        // 45 degree ascending line
        y = x - t;
    } else if ( x <= t + 2) {
        // horizontal line
        y = 1;
    } else if (x <= t + 3) {
        // 45 degree descending line
        y = t + 3 - x;
    } else {
        y = 0;
    }

    return y;        

}

If you want a "long wave" and not just one pulse, work with modules (%), if you don't need the time variable, just replace it by 0.




回答2:


There's an equation you can use instead of restrictions.

a/pi(arcsin(sin((pi/m)x+l))+arccos(cos((pi/m)x+l)))-a/2+c
  • a is the amplitude
  • m is the period
  • l is the horizontal transition
  • c is the vertical transition

Plus this is a direct trigonometric function, even though it could be longer,and a little more complicated.



来源:https://stackoverflow.com/questions/11041498/equation-for-trapezoidal-wave-equation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!