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:

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

Do you mean asymmetric square wave ?

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

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

Vee Eee Technologies

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

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

what are the units for the amplitude axis?

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

function

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

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

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/

Hi,

Why do u multiply t*f?

TNX

Can anybody send the matlab program for the convolution

Thanks for the matlab program for square wave generation

Thanks for the matlab program for square wave generation

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

ravi evide undenkilm ethraym pettan oru set mugm bucketm aayi ethendathann

appani revii evide annu

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

## Post a Comment