0% found this document useful (0 votes)
6 views9 pages

Signal and Systems Lab

The document provides an overview of basic signal types in the context of MATLAB programming, including continuous-time and discrete-time signals. It describes various signal types such as ramp, unit-step, unit impulse, signum, sinusoidal, and exponential signals, along with their mathematical representations. Additionally, it includes MATLAB code examples for plotting these signals, demonstrating how to visualize both continuous and discrete representations.

Uploaded by

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

Signal and Systems Lab

The document provides an overview of basic signal types in the context of MATLAB programming, including continuous-time and discrete-time signals. It describes various signal types such as ramp, unit-step, unit impulse, signum, sinusoidal, and exponential signals, along with their mathematical representations. Additionally, it includes MATLAB code examples for plotting these signals, demonstrating how to visualize both continuous and discrete representations.

Uploaded by

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

Plotting Basic Signals Using MATLAB

Introduction
Signals may be defined as a function of one or more independent variables that convey informa-
tion about the behavior or nature of some phenomenon. It can also be understood as a function
of some independent variable that results due to some physical processes. Some signals in our
daily life are music, speech, picture and video signals. Based upon the nature and characteristics
of signals in the time domain, signals may be broadly classified as:

1. Continuous-time signals

2. Discrete-time signals

Continuous-time signals
A continuous-time signal may be defined as a mathematical continuous function. This function
is defined continuously in the time domain for continuous time signals; the independent variable
is time,t. For a continuous time signal, we will enclose the independent variable in parentheses
() as x(t). A continuous-time signal has a value defined at each point in time.Speech signals and
the temperature of the room are examples of continuous-time signals.

Discrete-time signals
A discrete-time signal is defined only at certain time-instants. For discrete-time signal,the am-
plitude between two time instants is just not defined. For discrete-time signals,the independent
variable is time,n. For a discrete-time signal,we will enclose the independent variable in square
brackets[] as x[n]. Discrete-time signals can be obtained by periodic sampling of continuous time
signals. For example the crime rate, budget of the country is represented in discrete form.

Basic Type of Signals


Ramp Signal
Signal increasing linearly with the the time is called as ”Ramp Signal”.Continuous time ramp
signal is represented by r(t) and discrete time ramp signal is represented by r[n].
Mathematically, continuous time ramp signal is represented as,


t x≥a
r(t) =
0 t<0

Mathematically , discrete time ramp signal is represented as ,


n n≥0
r[n] =
0 n<0

1
Unit-step Signal
Signal that begins from the time instant’0’ and goes up to time instant ’+∞’ with the
constant amplitude of unity is called as ”Unit-step signal”. Continuous time unit step
signal is represented by u(t) and discrete time unit step signal as u[n].
Mathematically, continuous time unit step signal is represented as ,


1 t≥0
u(t) =
0 t<0
Mathematically, discrete-time unit step signal is represented as ,


1 n≥0
u[n] =
0 n<0

Unit Impulse Signal


Signal that exists only at the time instant zero with amplitude of unity is called as ”Unit
Impulse Signal”.Unit Impulse signal is represented as δ(t) in continuous time and δ[n] in
discrete time respectively.
Mathematically,continuous time unit impulse signal is represented as,


1 t=0
δ(t) =
̸ 0
0 t=
Mathematically, discrete time unit impulse signal is represented as,


1 n=0
δ[n] =
̸ 0
0 n=

Signum Signal
Signum Function can be represented in continuous time as ,


 −1 t < 0
sgn(t) = 0 t=0
1 t>0

In discrete time as ,


 −1 n < 0
sgn[n] = 0 n=0
1 n>0

Sinusoidal Signals
The signals varying with sine function of time or cosine function of time are called as
Sinusoidal signals. The general expression for continuous time sinusoidal signal may be
written is ,
x(t) = Acos(ωt + ϕ)

2
Exponential Signals
In continuous time , a real exponential signal may be written as,

x(t) = ceat

Where, both c and a are real numbers.


The exponential signal came into an existence from the mathematical function exponent.
There are two types of exponential Signals.
a)Exponentially growing Signal(a > 0)
b)Exponentially decaying Signal(a < 0)

Programming With MATLAB


Program 1

clc ; clear ; close all ;

% Continuous - Time Ramp Function


t = -2:0.01:5; % Time vector for continuous signal
ramp_ct = max (0 , t ) ; % Ramp function : r ( t ) = t for t >= 0 ,
else 0

% Discrete - Time Ramp Function


n = -2:1:5; % Discrete - time index
ramp_dt = max (0 , n ) ; % Discrete version of the ramp function

% Plot Continuous - Time Ramp Function


figure ;
subplot (2 ,1 ,1) ;
plot (t , ramp_ct , 'b ' , ' LineWidth ' , 2) ; % Continuous ramp
xlabel ( 't ') ; ylabel ( 'r ( t ) ') ;
title ( ' Continuous - Time Ramp Function ') ;
grid on ; axis ([ -2 5 -0.5 5]) ; % Adjust axes

% Plot Discrete - Time Ramp Function


subplot (2 ,1 ,2) ;
stem (n , ramp_dt , 'r ' , ' filled ' , ' LineWidth ' , 1.5) ; % Discrete
ramp
xlabel ( 'n ') ; ylabel ( 'r [ n ] ') ;
title ( ' Discrete - Time Ramp Function ') ;
grid on ; axis ([ -2 5 -0.5 5]) ; % Adjust axes

3
Output

Program 2

clc ; clear ; close all ;

% Continuous - Time Unit Step Function


t = -5:0.01:5; % Time vector for continuous signal
unit_step_ct = t >= 0; % Unit step function : u ( t ) = 1 for t
>= 0 , else 0

% Discrete - Time Unit Step Function


n = -5:1:5; % Discrete - time index
unit_step_dt = n >= 0; % Discrete version of the unit step
function

% Plot Continuous - Time Unit Step Function


figure ;
subplot (2 ,1 ,1) ;
plot (t , unit_step_ct , 'b ' , ' LineWidth ' , 2) ;
xlabel ( 't ') ; ylabel ( 'u ( t ) ') ;
title ( ' Continuous - Time Unit Step Function ') ;
grid on ; axis ([ -5 5 -0.2 1.2]) ; % Adjust axes
ylim ([ -0.2 , 1.2]) ; % Set Y - axis limits

% Plot Discrete - Time Unit Step Function


subplot (2 ,1 ,2) ;
stem (n , unit_step_dt , 'r ' , ' filled ' , ' LineWidth ' , 1.5) ;
xlabel ( 'n ') ; ylabel ( 'u [ n ] ') ;
title ( ' Discrete - Time Unit Step Function ') ;
grid on ; axis ([ -5 5 -0.2 1.2]) ; % Adjust axes
ylim ([ -0.2 , 1.2]) ; % Set Y - axis limits

4
Output

Program 3

clc ; clear ; close all ;

% Continuous - Time Approximation of Unit Impulse


t = -5:0.01:5; % Time vector for continuous signal
delta_t = ( t == 0) ; % Ideal impulse ( Dirac delta
approximation )

% Discrete - Time Unit Impulse Function


n = -5:1:5; % Discrete - time index
delta_n = ( n == 0) ; % Discrete impulse function ( Kronecker
delta )

% Plot Continuous - Time Approximate Unit Impulse Function


figure ;
subplot (2 ,1 ,1) ;
stem (t , delta_t , 'b ' , ' filled ' , ' LineWidth ' , 1.5) ; %
Approximation using stem
xlabel ( 't ') ; ylabel ( '\ delta ( t ) ') ;
title ( ' Continuous - Time Approximate Unit Impulse Function ') ;
grid on ; axis ([ -5 5 -0.2 1.2]) ;

% Plot Discrete - Time Unit Impulse Function


subplot (2 ,1 ,2) ;
stem (n , delta_n , 'r ' , ' filled ' , ' LineWidth ' , 1.5) ;
xlabel ( 'n ') ; ylabel ( '\ delta [ n ] ') ;
title ( ' Discrete - Time Unit Impulse Function ') ;
grid on ; axis ([ -5 5 -0.2 1.2]) ;

5
Output

Program 4

clc ; clear ; close all ;

% Define the time range for continuous signal


t = -5:0.01:5; % Continuous - time range
sgn_t = sign ( t ) ; % Signum function for continuous time

% Define discrete time range


n = -5:1:5; % Discrete - time index
sgn_n = sign ( n ) ; % Signum function for discrete time

% Plot Continuous - Time Signum Function


figure ;
subplot (2 ,1 ,1) ;
plot (t , sgn_t , 'b ' , ' LineWidth ' , 2) ; % Continuous function
xlabel ( 't ') ; ylabel ( ' sgn ( t ) ') ;
title ( ' Continuous - Time Signum Function ') ;
grid on ; axis ([ -5 5 -1.5 1.5]) ; % Adjust axis limits
ylim ([ -1.5 , 1.5]) ;
hold on ;
plot (0 , 0 , ' ro ' , ' MarkerSize ' , 8 , ' LineWidth ' , 1.5) ; % Mark
discontinuity at t =0

% Plot Discrete - Time Signum Function


subplot (2 ,1 ,2) ;
stem (n , sgn_n , 'r ' , ' filled ' , ' LineWidth ' , 1.5) ; % Discrete
function
xlabel ( 'n ') ; ylabel ( ' sgn [ n ] ') ;
title ( ' Discrete - Time Signum Function ') ;
grid on ; axis ([ -5 5 -1.5 1.5]) ;
ylim ([ -1.5 , 1.5]) ;

6
hold on ;
stem (0 , 0 , ' ro ' , ' filled ') ; % Mark discontinuity at n =0

Output

Program 5

clc ; clear ; close all ;

% Define parameters
A = 2; % Amplitude
f = 1; % Frequency in Hz
phi = 0; % Phase shift in radians
Fs = 20; % Sampling frequency ( for discrete - time )
Ts = 1/ Fs ; % Sampling period

t = 0:0.01:5; % Continuous time range


n = 0:1:20; % Discrete - time index
t_n = n * Ts ; % Time instances for discrete signal

% Compute sinusoidal function


x_t = A * sin (2 * pi * f * t + phi ) ; % Continuous signal
x_n = A * sin (2 * pi * f * t_n + phi ) ; % discrete signal (
sampled version )

% Plot Continuous - Time Sinusoidal Function


figure ;
subplot (2 ,1 ,1) ;
plot (t , x_t , 'b ' , ' LineWidth ' , 2) ;
xlabel ( ' Time ( t ) ') ;
ylabel ( 'x ( t ) ') ;
title ( ' Continuous - Time Sinusoidal Function ') ;
grid on ;

7
ylim ([ -A -1 A +1]) ;

% Plot Discrete - Time Sinusoidal Function


subplot (2 ,1 ,2) ;
stem ( t_n , x_n , 'r ' , ' filled ' , ' LineWidth ' , 1.5) ;
xlabel ( ' Time ( t_n ) ') ;
ylabel ( 'x [ n ] ') ;
title ( ' Discrete - Time Sinusoidal Function ( Sampled ) ') ;
grid on ;
ylim ([ -A -1 A +1]) ;

Output

Program 6

clc ; clear ; close all ;

% Define parameters
A = 2; % Amplitude
lambda = 0.5; % Growth ( if positive ) / Decay ( if negative )
rate

t = -2:0.01:5; % Continuous time range


n = -2:1:5; % Discrete time indices

% Compute exponential function


x_t = A * exp ( lambda * t ) ; % Continuous - time signal
x_n = A * exp ( lambda * n ) ; % Discrete - time signal

% Plot Continuous - Time Exponential Function


figure ;
subplot (2 ,1 ,1) ;
plot (t , x_t , 'b ' , ' LineWidth ' , 2) ;

8
xlabel ( ' Time ( t ) ') ;
ylabel ( 'x ( t ) ') ;
title ( ' Continuous - Time Exponential Function ') ;
grid on ;
ylim ([0 A * exp ( lambda * max ( t ) ) +1]) ; % Adjust axis

% Plot Discrete - Time Exponential Function


subplot (2 ,1 ,2) ;
stem (n , x_n , 'r ' , ' filled ' , ' LineWidth ' , 1.5) ;
xlabel ( 'n ') ;
ylabel ( 'x [ n ] ') ;
title ( ' Discrete - Time Exponential Function ') ;
grid on ;
ylim ([0 A * exp ( lambda * max ( n ) ) +1]) ; % Adjust axis

Output

You might also like