0% found this document useful (0 votes)
97 views16 pages

Program No. 1: Unit Ramp

The document contains 8 MATLAB programs that plot various continuous and discrete signals. Program 1 plots unit impulse, unit step, and unit ramp signals continuously. Program 2 plots exponential, rectangular, sine, and cosine waves continuously. Program 3 plots the same signals as Program 1 but discretely. Program 4 plots the same signals as Program 2 but discretely. The remaining programs plot additional functions including the sinc function, exponential-sine waves, Rayleigh and normal distributions, and Poisson distributions.

Uploaded by

lucas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views16 pages

Program No. 1: Unit Ramp

The document contains 8 MATLAB programs that plot various continuous and discrete signals. Program 1 plots unit impulse, unit step, and unit ramp signals continuously. Program 2 plots exponential, rectangular, sine, and cosine waves continuously. Program 3 plots the same signals as Program 1 but discretely. Program 4 plots the same signals as Program 2 but discretely. The remaining programs plot additional functions including the sinc function, exponential-sine waves, Rayleigh and normal distributions, and Poisson distributions.

Uploaded by

lucas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Program No.

1
Question. Write a program in MATLAB for Plotting Continuous Signal of unit impulse, unit step and
unit ramp.

Solution:
a) Unit impulse
>>%unit impulse
>>subplot(2,1,1);
>> t=-2:1:2;
>> y=[zeros(1,2),ones(1,1),zeros(1,2)];
>>plot(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('UNIT IMP');

b) Unit step
>> % unit step
>>subplot(2,1,2);
>> t=-1:1:6;
>> y=[zeros(1,1),ones(1,7)];
>>plot(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('UNIT Step')

c) Unit ramp
>> %unit ramp
>>subplot(2,1,3);
>> t=0:1:3;
>> y=t;
>>plot(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('UNIT RAMP');
Program No. 2
Question. Write a program in MATLAB for Plotting Continuous Signal of exponential wave,
rectangular wave, sine wave, cosine wave and signum function.

Solution:
a) Exponential wave
>> %exponential wave
>>subplot(2,2,1);
>> t=0:0.2:6;
>> y=exp(t);
>>plot(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('Exponential function');

b) Rectangular Wave:
>> %rectangular pulse
>>subplot(2,2,2);
>> t=-2:1:2;
>> y=[ones(1,5)];
>>plot(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('Rectangular pulse');

c) Sine Wave:
>> %sine wave
>>subplot(2,2,3)
>> t=-pi:0.1:pi;
>> y=sin(2*pi*t);
>>plot(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('Sine wave');

d) Cosine fun
>> %Cosine fun
>>subplot(2,2,4);
>> t=-pi:0.1:pi;
>> y=cos(2*pi*t);
>>plot(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('Cosine Wave');
e) Signum function
>> %signum
>>subplot(2,2,5);
>> t=-4:1:4;
>> y=[-ones(1,4),ones(1,5)];
>>plot(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('Signum');
Program No. 3
Question. Write a program in MATLAB for Plotting Discrete Signal of unit impulse, unit step and unit
ramp.

Solution:
a) Unit impulse
>>%unit impulse
>>subplot(2,3,1);
>> t=-2:1:2;
>> y=[zeros(1,2),ones(1,1),zeros(1,2)];
>>stem(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('UNIT IMP');

b) Unit step
>> % unit step
>>subplot(2,3,2);
>> t=-1:1:6;
>> y=[zeros(1,1),ones(1,7)];
>>stem(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('UNIT Step')

c) Unit ramp
>> %unit ramp
>>subplot(2,3,3);
>> t=0:1:3;
>> y=t;
>>stem(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('UNIT RAMP');
Program No. 4
Question. Write a program in MATLAB for Plotting Discrete Signal of exponential wave, rectangular
wave, sine wave, cosine wave and signum function.

Solution:
a) Exponential wave
>> %exponential wave
>>subplot(2,4,1);
>> t=0:0.2:6;
>> y=exp(t);
>>stem(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('Exponential function');

b) Rectangular Wave:
>> %rectangular pulse
>>subplot(2,4,2);
>> t=-2:1:2;
>> y=[ones(1,5)];
>>stem(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('Rectangular pulse');

c) Sine Wave:
>> %sine wave
>>subplot(2,4,3)
>> t=-pi:0.1:pi;
>> y=sin(2*pi*t);
>>stem(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('Sine wave');

d) Cosine fun
>> %Cosine fun
>>subplot(2,4,4);
>> t=-pi:0.1:pi;
>> y=cos(2*pi*t);
>>stem(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('Cosine Wave');
e) Signum function
>> %signum
>>subplot(2,4,5);
>> t=-4:1:4;
>> y=[-ones(1,4),ones(1,5)];
>>stem(t,y);
>>xlabel('Time');
>>ylabel('Amp');
>>title('Signum');
Program No. 5
Question. Write a program in MATLAB to generate and plot sinc function.

Solution:
>>%sinc function
>>subplot(2,5,1);
>> t=(-5*pi):0.01:(5*pi);
>> y=sin(t)./t;
>>plot(t,y);
>>xlabel('Time');
>>ylabel('Amplitude');
>>title('Sinc function');
Program No. 6
Question. Write a program in MATLAB to generate and plot following function
a) exp(-t).sin(pi*t)
b) sin(pi*t) * sin(10*pi*t)
c) cos(pi*t) * cos(10*pi*t)

Solution:
a) exp(-t).sin(pi*t)

>> t= 0:0.05:10;
>>subplot(2,6,1);
>> y1 =exp(-t);
>> y2= sin(pi*t);
>> y= y1.*y2;
>>plot(t,y);
>>xlabel('time');
>>ylabel('Amplitude');
>>title('exp(-t)* sin(pi*t)');

b) sin(pi*t) * sin(10*pi*t)
>> t= 0:0.05:10;
>>subplot(2,6,2);
>> y1= sin(pi*t);
>> y2= sin(10*pi*t);
>> y= y1.*y2;
>>plot(t,y);
>>xlabel('time');
>>ylabel('Amplitude');
>>title('sin(pi*t)* sin(10*pi*t)');

c) cos(pi*t) * cos(10*pi*t)
>>t=0:0.08:10;
>> y1= cos(pi*t);
>> y2= cos(10*pi*t);
>> y= y1.*y2;
>>subplot(2,6,3);
>>plot(t,y);
>>xlabel('time');
>>ylabel('Amplitude');
>>title('cos(pi*t)*cos(10*pi*t)');
Program No. 7
Question. Write a program in MATLAB to generate and plot Following function
a) Plotting of u(t-4)
b) Plotting if 1.3u(t+6)

Solution:
a) Plotting of u(t-4)
>> % plotting of u(t-4)
>> n1=input ('enter the minimum value');
enter the minimum value -10
>> n2=input('enter the maximum value');
enter the maximum value 10
>> d=input('delay');
delay 4
>> t=n1:1:n2;
>> y=[zeros(1,d-n1),ones(1,n2-d+1)];
>>subplot(2,7,1);
>>plot(t,y);
>>xlabel('time');
>>ylabel('amplitude');
>>title('plot of u(t-4)');

b) Plotting if 1.3u(t+6)
>> % plotting of 1.3u(t+6)
>> n1=input('enter the minimum value');
enter the minimum value -8
>> n2=input('enter the maximum value');
enter the maximum value 8
>> d=input('delay');
delay -6
>> t=n1:1:n2;
>> y=1.3*[zeros(1,d-n1),ones(1,n2-d+1)];
>>subplot(2,7,2);
>>plot(t,y);
>>xlabel('time');
>>ylabel('amplitude');
>>title('plot of 1.3u(t+6)');
Program No. 8
Question. MATLAB Program to generate two general sequences with arbitrary distributions, mean and
variations.
a) Rayleigh distribution
b) Normal distribution
c) Poisson Distribution

Solution:
a) Rayleigh distribution with A=0.5
>> %rayleigh distribution with A=0.5
>>subplot(2,8,1);
>> x=0:0.02:4;
>> y=raylpdf(x,0.5);
>>plot(x,y);
>>xlabel('Time');
>>ylabel('Amplitude');
>>title('rayleigh distribution with A=0.5');

b) Rayleigh distribution with A=2


>>%rayleigh distribution with A=2
>>subplot(2,8,2);
>> x=0:0.02:10;
>> y=raylpdf(x,2);
>>plot(x,y);
>>xlabel('Time');
>>ylabel('Amplitude');
>>title('rayleigh distribution with A=2);

c) Normal distribution with D=1


>> %Normal distribution with D=1
>>subplot(2,8,3);
>> x=-10:0.02:10;
>> y=normpdf(x,0,1);
>>plot(x,y);
>>xlabel('Time');
>>ylabel('Amplitude');
>>title('Normal distribution with D=1');

d) Normal distribution with D=0.5


>> %Normal distribution with D=0.5
>>subplot(2,8,4);
>> x=-5:0.02:5;
>> y=normpdf(x,0,0.5);
>>xlabel('Time');
>>ylabel('Amplitude');
>>plot(x,y);
>>title('Normal distribution with D=0.5');
e) Poisson distribution with L=5
>> %Poisson distribution with L=5
>>subplot(2,8,5);
>> x=0:1:20;
>> y=poisspdf(x,5);
>>plot(x,y,'*');
>>xlabel('Time');
>>ylabel('Amplitude');
>>title('Poisson distribution with L=5');

f) Poisson distribution with L=15


>> %Poisson distribution with L=15
>>subplot(2,8,6);
>> x=0:1:30;
>> y=poisspdf(x,15);
>>plot(x,y,'*');
>>xlabel('Time');
>>ylabel('Amplitude');
>>title('Poisson distribution with L=15');

You might also like