Wednesday, July 20, 2011

MATLAB Programs 14: Generating a square wave

Program to generate a square with the required amplitude, duty cycle and frequency. square() function is used to generate the square wave.


%Program to generate a continuous time square wave


close all;
clear all;


a=input('Enter the amplitude of the square wave A = ');
f= input('Enter the frequency of the square wave F = ');
dc=input('Enter the duty cycle of the wave DC = ');
f=f*2*pi;
t=0:.001:1;
y=a*square(f*t,dc);
plot(t,y);
axis([0 1 -2.2 2.2]);


%output


%Enter the amplitude of the square wave A = 2
%Enter the frequency of the square wave F = 10
%Enter the duty cycle of the wave DC = 50


%Program to generate a discrete time square wave

close all;
clear all;

a=input('Enter the amplitude of the square wave A = ');
f= input('Enter the frequency of the square wave F = ');
dc=input('Enter the duty cycle of the wave DC = ');
f=f*2*pi;
t=-10:.01:10;
y=a*square(f*t,dc);
stem(t,y);
axis([0 1 -2.2 2.2]);

%output

%Enter the amplitude of the square wave A = 2
%Enter the frequency of the square wave F = 8
%Enter the duty cycle of the wave DC = 50


29 comments:

missnadira said...

hey there..about the amplitude, what if the square wave has different amplitude how do we put that in the code?

Anil C S said...

Do you mean asymmetric square wave ?

Amit said...

can any one tell me hw to generate digital signal for bits 10111010?

Vee Eee Technologies said...

Excellent pieces. Keep posting such kind of information on your blog. I really impressed by your blog.
Vee Eee Technologies

Pinaki Shankar Panda said...

i need the squre wave according to input i give like 1 0 1 1 1 0 1 1 ...something like that

Atul Singh said...

can anyone tell me how to generate square wave using tangent function?????

Anonymous said...

what are the units for the amplitude axis?

Debasish Kar said...

can it be possible to plot square wave without using the 'square'
function

Anonymous said...

Yes genarate a sine wave. Then plot. Y=1 when x>0 and plot y=-1 when x<0.. U wil get perfect square.

Anonymous said...

ما هذا البرنامج لا يعمل بالشكل المطلوب و لم يكن هناك فائده اذهب الى دحل

Nitesh Kumar said...

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/




GUy said...

Hi,
Why do u multiply t*f?
TNX

anil kumar swain said...

Can anybody send the matlab program for the convolution

anil kumar swain said...

Thanks for the matlab program for square wave generation

anil kumar swain said...

Thanks for the matlab program for square wave generation

Unknown said...
This comment has been removed by the author.
Unknown said...
This comment has been removed by the author.
Electronics communication said...
This comment has been removed by the author.
Electronics communication said...
This comment has been removed by the author.
Electronics communication said...
This comment has been removed by the author.
Electronics communication said...
This comment has been removed by the author.
Anonymous said...

ladies hostel parisarathu ninnu karangunna priyane arum kandittilla athu kond ethrym pettennu avidem vittu marendathanu

Anonymous said...

ravi evide undenkilm ethraym pettan oru set mugm bucketm aayi ethendathann

Electronics communication said...
This comment has been removed by the author.
Electronics communication said...
This comment has been removed by the author.
Anonymous said...

appani revii evide annu

Electronics communication said...
This comment has been removed by the author.
Electronics communication said...
This comment has been removed by the author.
Anonymous said...

suhaib ethrayum petten vittil povendathanu koyi biriyaniyum paalum vellavum ready ah vittil

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

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