How to Generate Unit Step, Sinusoidal and Exponential Signal in MATLAB?


These three types of signals (unit step, sinusoidal, and exponential) are basic signals used in analyzing different types of systems.

  • A unit step signal has a step of magnitude one after a specific time instant.

  • A sinusoidal signal is a type of signal which has either a sine or cosine waveform.

  • A exponential signal is a type of signal that rises or decays exponentially with time.

We can use MATLAB to generate all these types of signals. In this tutorial, I am going to explain how you can generate unit step, sinusoidal, and exponential signal in MATLAB.

Before going to learn about generating unit step, sinusoidal, and exponential signals using MATLAB, let us first understand a bit more about these signals individually.

What is a Unit Step Signal?

A signal which has a magnitude equal to 0 for all time instants before a specific time instant and has a magnitude equal to 1 for all time instants after that specific time instant is called a unit step signal.

Mathematically, the unit step signal is defined as,

$$\mathrm{u(t)=\ _{1\:for\:t\geq 0} ^{0\:for\:t > 0}}$$

Here, the signal u(t) is 0 for all time instants before "t = 0" and it is 1 for all time instants after "t ≥ 0".

Hence, there is a sudden transition from 0 to 1. This signal is suitable to analyze the behavior of a system for sudden transition from one state to another.

What is a Sinusoidal Signal?

A type of signal which has either sine or cosine waveform, is referred to as a sinusoidal signal. It is a type of periodic signal which has a constant frequency and time period.

Mathematically, a sinusoidal signal is defined as follows,

$$\mathrm{x(t)=A × \sin(2\pi ft)… Sine \:wave}$$

Or,

$$\mathrm{x(t)=A × cos(2\pi ft)… Cosine \:wave}$$

Here, "A" is the peak value of the signal, "f" is the frequency, and "t" is the time instant

It is the most widely used signal in the field of electrical and electronics engineering.

What is an Exponential Signal?

A signal that grows and decays exponentially with time is termed as an exponential signal.

Mathematically, the exponential signal is defined as follows −

$$\mathrm{x(t)=Ae^{\pm at}}$$

Here, "A" is the amplitude of the signal, "a" is the growth or decay factor of the signal, and "t" is the time instant.

In this signal, if the exponent is positive, the signal will be a growing exponential signal, and if the exponent is negative, the signal will be a decaying exponential signal.

This is all about the three basic types of signals namely, unit step, sinusoidal, and exponential signals. Now, let us learn how to generate these signals in MATLAB.

How to Generate Unit Step Signal in MATLAB?

To generate a unit step signal in MATLAB, we need to write the definition of the signal in MATLAB programming.

Example

The following example program explains how we can generate the unit step signal in MATLAB.

% MATLAB code to generate unit step signal
% Specify the signal time limits
t = -5 : 0.1 : 5;
% Generate a unit step signal having
% Values 0 for t < 0 and 1 for t >= 0
% Set the initial value of the signal to zero
u1 = zeros(size(t));
% Set the values of signal to 1 after t >= 0
u1(t >= 0) = 1;
% Generate a unit step signal having
% Values 0 for t < 2 and 1 for t >= 2
% Set the initial value of the signal to zero
u2 = zeros(size(t));
% Set the values of signal to 1 after t >= 2
u2(t >= 2) = 1;
% Display the generated unit step signal
figure;
subplot(2, 1, 1);
plot(t, u1);
xlabel('Time');
ylabel('Amplitude');
title('Unit Step Signal (t>=0)');
subplot(2, 1, 2);
plot(t, u2);
xlabel('Time');
ylabel('Amplitude');
title('Unit Step Signal (t>=2)');

Output

When you run this code, it will produce the following output −

How to Generate Sinusoidal Signal in MATLAB?

The sinusoidal signal is one of the most commonly used signals. A sinusoidal signal has either a sine waveform or a cosine waveform

In MATLAB, we can use two built-in functions namely, "sin()" and "cos()" to produce a sine wave and cosine wave sinusoidal signals respectively.

Example

The following example program demonstrates the process of generating the sinusoidal signal in MATLAB.

% MATLAB program to generate sinusoidal signal
% Specify the frequency of the signal
f = 5; % Frequency (5 Hz)
% Calculate the time period of the signal
T = 1/f;
% Specify the time limit to plot the signal
t = 0 : 0.0001 : T;
% Specify the signal amplitude
A = 2;
% Generate the sinusoidal signals
x = A * sin(2*pi*f*t); % Sine waveform
y = A * cos(2*pi*f*t); % Cosine waveform
% Plot the generated sinusoidal signals
figure;
subplot(2, 1, 1);
plot(t, x, 'r');
xlabel('Time');
ylabel('Amplitude');
title('Sine Wave Signal');
subplot(2, 1, 2);
plot(t, y, 'r');
xlabel('Time');
ylabel('Amplitude');
title('Cosine Wave Signal');

Output

When you run this code, it will produce the following output −

How to Generate Exponential Signal in MATLAB?

An exponential signal is one that grows or decays exponentially with time. In MATLAB, there is a built-in function "exp" which can be used to generate an exponential signal.

Example

Here is an example that demonstrates the process of generating exponential signal using MATLAB.

% MATLAB code to generate exponential signal
% Specify the time limit for the signal
t = 0 : 0.001 : 4;
% Specify the amplitude of the signal
A = 5;
% Specify the growth and decay constants
a = 0.7; % Growth constant
b = 0.6; % Decay constant
% Generate the exponential signal
x = A * exp(a * t); % Growing signal
y = A * exp(-b * t); % Decaying signal
% Plot the generated exponential signals
figure;
subplot(2, 1, 1);
plot(t, x);
xlabel('Time');
ylabel('Amplitude');
title('Growing Exponential Signal');
subplot(2, 1, 2);
plot(t, y);
xlabel('Time');
ylabel('Amplitude');
title('Decaying Exponential Signal');

Output

When you run this code, it will produce the following output −

Conclusion

In conclusion, MATLAB can be used to generate different types of signals either by defining the signal in MATLAB programming or by using built-in functions. In this tutorial, I explained how you can general a unit step signal, a sinusoidal signal, and an exponential signal in MATLAB with the help of examples.

Updated on: 05-Oct-2023

201 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements