You are on page 1of 7

Experiment No: 02

Aim: Using the MATLAB functions plot sawtooth, square, sine, cosine, rectangular pulse, triangular pulse, sinc function and signum function. The time axis should span t = -5 to 5. Give frequency, amplitude and width(if necessary) user define value. Program: clc; clear all; close all; a= input('enter the amplitude'); f=input('enter the freq.'); t=-10:0.0001:10; w= input('enter the width'); % sine s=a*sin(2*pi*f*t); subplot(2,2,1); plot(t,s); grid on; axis([-10 10 -a-1 a+1]) title('sine wave'); xlabel ('time'); ylabel ('Amplitude');

PRADEEP BORSE /09EC004/DSP MANUAL/CGPIT

Page 1

% cosine c=a*cos(2*pi*f*t); subplot(2,2,2); plot(t,c); grid on; axis([-10 10 -a-1 a+1]) title('cosine wave'); xlabel ('time'); ylabel ('Amplitude');

% sawtooth saw=a*sawtooth(2*pi*f*t); subplot(2,2,3); plot(t,saw); grid on; axis([-10 10 -a-1 a+1]) title('sawtooth wave'); xlabel ('time'); ylabel ('Amplitude');

% square squ=a*square(2*pi*f*t); PRADEEP BORSE /09EC004/DSP MANUAL/CGPIT Page 2

subplot(2,2,4); plot(t,squ); grid on; axis([-10 10 -a-1 a+1]) title('square wave'); xlabel ('time'); ylabel ('Amplitude'); figure();

% sinc snc=a*sinc(2*pi*f*t); subplot(2,2,1); plot(t,snc); grid on; axis([-10 10 -a-1 a+1]) title('sinc wave'); xlabel ('time'); ylabel ('Amplitude');

% triangular pulse trp=a*tripuls(t,w); subplot(2,2,2); PRADEEP BORSE /09EC004/DSP MANUAL/CGPIT Page 3

plot(t,trp); grid on; axis([-10 10 -a-1 a+1]) title('triangular wave'); xlabel ('time'); ylabel ('Amplitude');

% rectangular rec=a*rectpuls(t,w); subplot(2,2,3); plot(t,rec); grid on; axis([-10 10 -a-1 a+1]) title('rectangular wave'); xlabel ('time'); ylabel ('Amplitude');

% signam su=a*sign(t); subplot(2,2,4); plot(t,su); grid on; axis([-10 10 -a-1 a+1]) title('signam wave'); PRADEEP BORSE /09EC004/DSP MANUAL/CGPIT Page 4

xlabel ('time'); ylabel ('Amplitude');

PRADEEP BORSE /09EC004/DSP MANUAL/CGPIT

Page 5

Output: Command window:

Figure :

PRADEEP BORSE /09EC004/DSP MANUAL/CGPIT

Page 6

PRADEEP BORSE /09EC004/DSP MANUAL/CGPIT

Page 7

You might also like