Escolar Documentos
Profissional Documentos
Cultura Documentos
AIM: To write a program in MATLAB to generation of random signals and plot the same as a waveform.
PROGRAMS:
%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