0% found this document useful (0 votes)
252 views7 pages

DSP Lab 1

1. The document describes a MATLAB program to generate and plot various random signals as waveforms, including unit impulse, unit step, unit ramp, sinusoidal, square, sawtooth, triangular, and sinc functions. 2. The program uses functions like plot, stem, subplot to generate the waveforms and display the signals as continuous and discrete time plots. 3. It also allows the user to specify parameters like number of samples, periods, to generate signals like sine, square and sawtooth waves.

Uploaded by

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

DSP Lab 1

1. The document describes a MATLAB program to generate and plot various random signals as waveforms, including unit impulse, unit step, unit ramp, sinusoidal, square, sawtooth, triangular, and sinc functions. 2. The program uses functions like plot, stem, subplot to generate the waveforms and display the signals as continuous and discrete time plots. 3. It also allows the user to specify parameters like number of samples, periods, to generate signals like sine, square and sawtooth waves.

Uploaded by

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

1. Generation of random signal and plot the same as a waveform showing all the specifications.

AIM: To write a program in MATLAB to generation of random signals and plot the same as a waveform.

APPARATUS REQUIRED : MATLAB SOFTWARE.

PROGRAMS:

%unit impulse function%


clc;
clear all;
close all;
t=-10:1:10;
x=(t==0);
Subplot (2, 1, 1);
Plot (t,x,'g');
xlabel ('time');
ylabel ('amplitude');
title('unit impulse function');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('unit impulse discrete function');

%unit step function%


clc;
clear all;
close all;
N=100;
t=1:100;
x=ones(1,N);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('unit step function');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('unit step discrete function');

%unit ramp function%


clc;
clear all;
close all;
t=0:20;
x=t;
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('unit ramp function');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('unit ramp discrete function');

%sinusoidal function%
clc;
clear all;
close all;
t=0:0.01:2;
x=sin(2*pi*t);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('sinusoidal signal');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('sinusoidal sequence');

(or)
clc;
clear all;
close all;
disp('SINE SIGNAL');
N=input('Enter Number of Samples : ');
n=0:.1:N
x=sin(n)
stem(n,x);
xlabel('time');
ylabel('Amplitude');
title('sine Signal');

%square function%
clc;
clear all;
close all;
t=0:0.01:2;
x=square(2*pi*t);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('square signal');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('square sequence');
(OR)

clear all;
close all;
clc;
N = input('Enter the number of cycles in a square wave....:: ');
M = input('Enter the period of the square wave ....:: ');
y=0:0.001:2;
for j=0:M/2:M*N;
x=y;
plot(j,x,'r');
hold on;
end
for k=0:M:M*N;
x=k+y;
m=2;
plot(x,m,'r');
hold on
end
for k=2:M:M*N;
x=k+y;
m=0;
plot(x,m,'r');
hold on;
end
hold off
axis([0 12 -0.5 2.5])
xlabel('time---->');
ylabel('Amplitude--->');
title ('Square wave');

%sawtooth function%
clc;
clear all;
close all;
t=0:0.01:2;
x=sawtooth(2*pi*5*t);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('sawtooth signal');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('sawtooth sequence');
%trianguler function%
clc;
clear all;
close all;
t=0:0.01:2;
x=sawtooth(2*pi*5*t,0.5);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('triangular signal');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('triangular sequence');

%sinc function%
clc;
clear all;
close all;
t=linspace(-5,5);
x=sinc(t);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('sinc signal');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('sinc sequence');
OUTPUT: SINE SIGNAL

Enter Number of Samples : 16

OUTPUT

Enter the number of cycles in a square wave....:: 3

Enter the period of the square wave ....:: 4


RESULT:-
Thus the Generation of continuous time signals like unit step, sawtooth, triangular, sinusoidal, ramp and
sinc functions are successfully completed by using MATLAB.

You might also like