Saturday, June 25, 2011

MATLAB Programs 04: Generating a sawtooth/triangular waveform

Below given is program to generate sawtooth waveform.


%Program to generate sawtooth waveform


n=input ('Enter the length of the sequence N= ');
t=0:.0001:n;
y=sawtooth(t);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
TITLE ('Sawtooth waveform');


Now to generate a triangular waveform we need only to change the duty cycle of the sawtooth waveform to 50% as shown in the program given below. 

%Program to generate triangular waveform

n=input ('Enter the length of the sequence N= ');
t=0:.0001:n;
y=sawtooth(t,.5); %sawtooth with 50% duty cycle (triangular) 
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
TITLE ('Triangular waveform');






6 comments:

Avishek said...

Kindly make an effort to post sawtooth without function of sawtooth in it ...

Anonymous said...

Not running

Anonymous said...

maghiya bando biya

Kolou Rubestine said...

not running.....

Anonymous said...

Hi I am so delighted I found your weblog, I really found you by mistake, while I was searching on Yahoo for something else, Anyhow I am here now
and would just like to say thanks a lot for a marvelous post and a
all round exciting blog (I also love the theme/design), I don’t
have time to read it all at the moment but I have saved it and also added in your RSS feeds, so
when I have time I will be back to read a great deal more, Please do keep up the great b.


Visit my weblog - how to play piano

Abhishek Dipu said...

function sawtooth(T)
i=2;
x(1)=1;
t=1:1000;
while(i<1000)
if mod(i,T)==0
x(i)=0;
else
x(i)=x(i-1)+2;
end;
i=i+1;
end;
plot(t,x)

now in command window
>>sawtooth(200) [Enter]

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

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