# How to create triangular waveform with variable phase shift

**URL:** <https://forum.plexim.com/t/how-to-create-triangular-waveform-with-variable-phase-shift/316>\
**Category:** PLECS\
**Tags:** triangular-waveform, variable-phase\
**Created:** [March 27, 2018, 10:00am UTC](https://forum.plexim.com/t/how-to-create-triangular-waveform-with-variable-phase-shift/316 "2018-03-27T10:00:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![wolfgang](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/wolfgang/32/7_2.png) [@wolfgang](https://forum.plexim.com/u/wolfgang)\
**Post date:** [March 27, 2018, 10:27am UTC](https://forum.plexim.com/t/how-to-create-triangular-waveform-with-variable-phase-shift/316/2 "2018-03-27T10:27:27Z")

</div>

Please find attached a PLECS model that creates a set of triangular waveforms with variable phase shift in two stages:

First a reference ramp signal is generated, which is phase-shifted by subtracting a (vertical) offset and wrapping the result back to the interval [0, 1]. The trick here is to add a “Hit Crossing” block so that a variable-step solver will make a simulation step at the instant when the shifted ramp resets to zero.Map the ramp signals to a symmetrical triangle using a simple 1D Look-up Table. Again, the trick is to add a “Hit Crossing” block so that a variable-step solver will make a simulation step when the triangle signal reaches its maximum. (The minimum will be hit automatically because it coincides with the reset of the ramp signals.)

[TrianglePhaseShift.plecs](https://forum.plexim.com/uploads/short-url/73vj28FnGcJssXLpuroP7RaqAi7.plecs) (23.1 KB)

---

_[View the full topic](https://forum.plexim.com/t/how-to-create-triangular-waveform-with-variable-phase-shift/316)._
