You are on page 1of 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.

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

OUTPUT

## 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.