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.

## 6 comments:

nice job

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

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

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

Love it

SoopeR

## Post a Comment