0% found this document useful (0 votes)
386 views6 pages

MATLAB Signal Generation Guide

This document describes code to generate various basic signals in MATLAB, including unit step, unit impulse, unit ramp, exponential, and sinusoidal signals. The code provides the MATLAB code to generate each type of signal by defining the necessary variables, using for loops or vector operations to calculate the signal values over time, and plotting the results on a stem plot with labeled axes. The goal is to generate these fundamental signal types as basic examples.

Uploaded by

Tushar Raghav
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)
386 views6 pages

MATLAB Signal Generation Guide

This document describes code to generate various basic signals in MATLAB, including unit step, unit impulse, unit ramp, exponential, and sinusoidal signals. The code provides the MATLAB code to generate each type of signal by defining the necessary variables, using for loops or vector operations to calculate the signal values over time, and plotting the results on a stem plot with labeled axes. The goal is to generate these fundamental signal types as basic examples.

Uploaded by

Tushar Raghav
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/ 6

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.

You might also like