Saturday, June 25, 2011

MATLAB Programs 06: Generating a triangular waveform without using a sawtooth function

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


%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:

Anonymous said...

nice job

Anonymous said...

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

Anonymous said...

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

raj said...

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

Anonymous said...

Love it

S.P.Bharath Kumar said...

SoopeR

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes