Thursday, 20 November 2008

BASIC MATLAB PROGRAMS

WAVEFORM GENERATIONS

1. SINUSOIDAL SIGNALS
%program starts.
a=input("Enter amplitude=");
f=input("Enter frequency=");
t=0:0.01:1
y=a*sin(2*pi*f*t);
plot(t,y) %gives analog plot
xlabel("TIME");
ylabel("AMPLITUDE");
title("SINE WAVE");

2. RAMP SIGNAL

%program starts
n=input("Enter the Length of Sequence=");
t=0:1:n
stem(t,t) %gives discrete plot
xlabel("TIME");
ylabel(AMPLITUDE");
titile("DISCRETE RAMP SIGNAL");

3. SINE & COSINE WAVEFORMS IN A SINGLE PLOT

%program starts.
a=input("Enter amplitude=");
f=input("Enter frequency=");
t=0:0.01:1
y=a*sin(2*pi*f*t);
z=a*cos(2*pi*f*t);
plot(t,y,z) %gives analog plot of sin & cos in single graph
xlabel("TIME");
ylabel("AMPLITUDE");
title("SINE AND COSINE WAVE");

4. SQUARE WAVE

a=input("Enter amplitude=");
f=input("Enter frequency=");
t=0:0.01:1
y=a*square(2*pi*f*t);
plot(t,y) %gives analog plot
xlabel("TIME");
ylabel("AMPLITUDE");
title("SQUARE WAVE");

5. UNIT STEP AND UNIT IMPULSE FUNCTION AS SUBPLOTS

%subplot means different functions are shown on a single window
%as different graphs.
%subplot(x1,x2,p) means the window is divided into an x1 X x2 matrix.
%and the function is plotted on pth subplot

a=input("Enter amplitude=");
t=-2:1:a-1
y=[zeros(1,2),ones(1,a)];
z=[zer0s(1,20,ones(1,1),zeros(1,a)];
subplot(2,1,1)
stem(t,y)
xlabel("TIME");
ylabel("AMPLITUDE");
title("UNIT STEP SEQUENCE");
subplot(2,1,2)
stem(t,z)
xlabel("TIME");
ylabel("AMPLITUDE");
title("UNIT IMPLUSE SEQUENCE");



querrymail@gmail.com

2 comments:

Anonymous said...

Hi...da its gr8

ankit said...

hey sukunath just want to say great blog can u please include the basic questions asked in viva of matlab