How can I generate triangular wave with random period ?

4 views (last 30 days)
Hi I need a help for generating a traingle wave with a Random period in Simulinik or code Matlab ???

Accepted Answer

Jonas
Jonas on 8 Jul 2019
Edited: Jonas on 8 Jul 2019
Use an Integrator block which you reset each time it becomes lower than zero, and use a random - but constant - input. Reset another time it reaches the level of the period corresponding with the random input. For this second reset, change the sign of the input.
  3 Comments
Jonas
Jonas on 31 Jul 2019
Hi
Allow me to elaborate on my suggested answer.
Assume you have a simulation with a discrete sample time of 1 seconds. If you use the Discrete Time Integrator with a gain of 1, it's output will be 0 initially. In case you would give it an input of 1, after one second the output will be 1, and after two seconds the output will be 2. If you would give it an input of 2, the output will be 2 after one second, and 4 after two seconds. So if you want to create the rising edge of the triangle, you should use an Integrator block with gain 1, and use a random input.
So now the integrator is creating a rising flank with a random steepness. You should now reset the integrator (you can have an External Reset) when the output of the integrator reaches 1. This means we have reached the top of the triangle.
Now we want to create the downwards-going flank of the triangle wave. We should now give the integrator the same input, but with a negative sign such that it creates a downwards going flank. Also, the initial value should be 1, otherwise it will start going down starting from 0. The input should be the same as for the upwards going flank so you might want to save it in memory.
When the integrator now reaches 0, we have completed the triangle wave (we went up, to 1, and down again to 0). We want to reser the integrator and start all over again by using a new random input again.
With kind regards,
Jonas
debojit sharma
debojit sharma on 24 May 2021
How can I generate sawtooth wave with random period in matlab version 2014a? please help me with the matlab code

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!