Below given is a program to generate the triangular waveform without using the sawtooth function.

In the above program the concept of ramp signal is used. The slope of the ramp is changed alternatively to generate a triangular waveform. If two successive ramps are considered then one will be a positive going ramp and other will be a negative going ramp. Y signal i.e. the amplitude is expressed as the product of time index 't' and power of -1 raised to time index. Thus for even time index the slope will be positive and for odd time index slope will be negative. Thus a triangular waveform is generated.

**%Program to generate triangular waveform**

**n=input ('Enter the length of the sequence N= ');****t=0:n;****y=(-1).^t;****plot(t,y);****ylabel ('Amplitude');****xlabel ('Time Index');****TITLE ('Triangular waveform');**

In the above program the concept of ramp signal is used. The slope of the ramp is changed alternatively to generate a triangular waveform. If two successive ramps are considered then one will be a positive going ramp and other will be a negative going ramp. Y signal i.e. the amplitude is expressed as the product of time index 't' and power of -1 raised to time index. Thus for even time index the slope will be positive and for odd time index slope will be negative. Thus a triangular waveform is generated.

Now replace plot() with stem() and observe the result. You will not get the expected wave form. Think about the reason for it.

If you cannot make it out just post a comment here.

## 9 comments:

nice job

very helpful.....frm PESCOE,A'bad

thanks..............pretty usefull

IF I WANT SYMMETRICAL DISCRETE TRAINGULAR MEANS.............

Love it

SoopeR

if we want at higher frequencies it cannot show then how we can proceed for higher frequencies around 1000hZ

I need code for stepped frequency continous waveform

I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in MATLAB, kindly contact us http://www.maxmunus.com/contact

MaxMunus Offer World Class Virtual Instructor led training on MATLAB. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.

For Demo Contact us.

Nitesh Kumar

MaxMunus

E-mail: nitesh@maxmunus.com

Skype id: nitesh_maxmunus

Ph:(+91) 8553912023

http://www.maxmunus.com/

## Post a Comment