Program No. 1: Unit Ramp
Program No. 1: Unit Ramp
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');