Aim: To generate basic signals.
Material Required:
MATLAB
1. Unit step signal
Code-
clear all;
close all;
% Defining the Time Limits and sampling time t1
= input('enter the starting time = ');
t2 = input('enter the ending time = '); t3 =
input('enter the sampling time = '); t =
t1:t3:t2;
% size of the time variable "t"
[m,n] = size(t);
s = zeros(m,n);
for i = 1:n
if t(i) >= 0
s(i) = 1;
else s(i)
= 0;
end
end
stem(t,s);
xlabel('time'); ylabel('amplitude');
title('Discrete Unit Step Signal');
2. Unit impulse signal
Code:
clear all;
close all;
clc;
N=15;
n=-N:1:N;
y=[zeros(1,N),ones(1,1),zeros(1,N)];
stem(n,y);
ylabel('amplitude'); xlabel('number
of samples--->'); title('discrete unit
impulse signal'); display(y);
3. Unit ramp signal
Code-
clc; clear
all; close
all;
t = -2:0.5:5;
[m,n] = size(t);
r = zeros(m,n);
for i = 1:n
if t(i) >= 0
r(i) = t(i);
else
r(i) = 0;
end
end
stem(t,r);
xlabel('time'); ylabel('amplitude');
title('Discrete Unit ramp signal');
4. Exponential signal
Code-
clc; clear
all; close
all; n =
0:20;
% set the collection of z's for plots z
= [-5,-.5,.5,5];
% iterate over the subplots
for plot_n = 1:4
% calculate x[n] for current z x
= z(plot_n).^n;
subplot(2,2,plot_n)
% plot x[n] vs n
stem(n,x)
% title it with current z
title('z(plot_n)')
end
5. Sinusoidal signal
Code-
clc; close
all; clear
all;
n=0:1:10;
a=5; f=.1;
y=a*sin(2*pi*f*n);
stem(n,y); title('sin
function');
xlabel('n');
ylabel('amplitude');
Result: Various signals have been studied.