Creating Continuous Time Triangle in Matlab

7 views (last 30 days)
Curtis
Curtis on 19 Mar 2013
I need to create a continuous time triangle wave in Matlab that follows the following Pseudo Code:
Triangle = { 1 - abs(t/2) for -2<=t<=2 0 otherwise
Basically, I want a triangle centered on 0, with a max height of 1, that goes from -2 to 2.
I can do it in discrete time with the following code:
a = 2;
t = -a:0.001:a; %define time from -2 to 2
triangle = 1-abs(t/a); %triangle function with max height of 1.
plot(t,triangle)
but I haven't the foggiest how to make this into a continuous time function. Any help would be greatly appreciated.

Answers (1)

Image Analyst
Image Analyst on 19 Mar 2013
Use repmat().
a = 2;
t = -a:0.001:a; %define time from -2 to 2
triangle = 1-abs(t/a); %triangle function with max height of 1.
numberOfReplications = 3;
triangleWave = repmat(triangle, [1, numberOfReplications]);
plot(triangleWave)

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!