Equation for trapezoidal wave equation

I am writing a c-function for generating a trapezoidal wave. Does anyone know the mathematical equation for generating a trapezoidal wave? A very similar idea with y = A * sin (B * x) generates a sin wave for different values ​​of x.

+4
source share
2 answers

A method of sending a single trapezoidal wave pulse involves using the Heisiside step function http://en.wikipedia.org/wiki/Heaviside_step_function

Use it if you want a β€œclean” mathematical way of representing this kind of function. Just create your function "in parts", multiply the first part by the body, which is "activated" when x = the beginning of your impulse. For the next fragment, first subtract the last function, then add the mathematical function of the new piece, multiply it by the adequate gravity function, and so on. This should end up with something like this (if you do not understand this, check out 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 simplicity and efficiency, you can use the if statement. Consider a trapezoidal wave of 45 degrees with a constant unitary speed.

 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 need a "long wave", and not just one pulse, work with modules (%), if you do not need a time variable, just replace it with 0.

+2
source

There is an equation that 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 - period
  • l is the horizontal transition
  • c - vertical transition

Plus, this is a direct trigonometric function, although it can be longer and a bit more complicated.

+2
source

All Articles