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:

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

Not running

maghiya bando biya

not running.....

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

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