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

MATLAB Lab Experiments for Engineering Students

The document outlines the MATLAB Lab experiments for Electronics and Communication Engineering students at Prestige Institute of Engineering Management & Research, Indore. It includes a list of experiments focusing on MATLAB functionalities such as arithmetic operations, matrix generation, and signal processing. Each experiment provides instructions and examples for students to follow, emphasizing the practical applications of MATLAB in engineering.
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 views27 pages

MATLAB Lab Experiments for Engineering Students

The document outlines the MATLAB Lab experiments for Electronics and Communication Engineering students at Prestige Institute of Engineering Management & Research, Indore. It includes a list of experiments focusing on MATLAB functionalities such as arithmetic operations, matrix generation, and signal processing. Each experiment provides instructions and examples for students to follow, emphasizing the practical applications of MATLAB in engineering.
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

Prestige Institute of Engineering Management & Research, Indore

ELECTRONICS AND COMMUNICATION ENGG. LIST OF


EXPERIMENTS
Name:___________________________ Enroll No. ____________________

Subject: MATLAB Lab Branch__________ Year__________ Semester__________

[Link] LIST OF PROGRAMS PAGE NO. STAFF’ S SIGN


1 Introduction Of MATLAB
2 Arithmetic Operations
3 Matrix Generation
4 Generation of Causal Signal and Message Signal
5 Generating Sine and Cosine wave through Simulink
6 Arithmetic Operations in Simulink.
7 Procedure of installation of Support Package of Arduino
Uno setup in MATLAB
8 Procedure of installation of Support Package of Raspberry
Pi setup in MATLAB
9 Interface sensors with a microcontroller and capture real-
time data.
Prestige Institute of Engineering Management & Research, Indore

Name of Student: ____________________________Roll No: __________________________

Subject: ___________________________ Branch: __________ Year: ________ Sem: __________

Date of Experiment: ____________ Date of Submission: ___________ Teacher Signature

Experiment: 1

Introduction
The name MATLAB stands for MATrix LABoratory. MATLAB was written
originally to provide easy access to matrix software developed by the LINPACK (linear system
package) and EISPACK (Eigen system package) projects.

MATLAB [1] is a high-performance language for technical computing. It integrates computation,


visualization, and programming environment. Furthermore, MATLAB is a modern programming
language environment: it has sophisticated data structures, contains built-in editing and debugging
tools, and supports object-oriented programming. These factors make MATLAB an excellent tool for
teaching and research.
MATLAB has many advantages compared to conventional computer languages (e.g.,
C, FORTRAN) for solving technical problems. MATLAB is an interactive system whose
basic data element is an array that does not require dimensioning. The software package has
been commercially available since 1984 and is now considered as a standard tool at most
universities and industries worldwide.

Figure 1.1: The graphical interface to the MATLAB workspace


Prestige Institute of Engineering Management & Research, Indore

Name of Student: ____________________________Roll No: __________________________

Subject: ___________________________ Branch: __________ Year: ________ Sem: __________

Date of Experiment: ____________ Date of Submission: ___________ Teacher Signature

Experiment: 2
Using MATLAB as a calculator
As an example of a simple interactive calculation, just type the expression you want to
evaluate. Let’s start at the very beginning. For example, let’s suppose you want to calculate
the expression, 1 + 2 × 3. You type it at the prompt command (>>) as follows,

>> 1+2*3
Ans = 7

You will have noticed that if you do not specify an output variable, MATLAB uses a
default variable ans, short for answer, to store the results of the current calculation. Note that
the variable ans is created (or overwritten, if it is already existed). To avoid this, you may
assign a value to a variable or output argument name. For example,

>> x = 1+2*3

Ans = 7

will result in x being given the value 1 + 2 3 =×7. This variable name can always be used to
refer to the results of the previous computations. Therefore, computing 4x will result in

>>4*x

Ans= 28.000

Table 1.1: Basic arithmetic operators


SYMBOL OPERATION EXAMPLE
+ Addition 2+3
− Subtraction 2− 3
∗ Multiplication 2∗ 3
/ Division 2/3
Prestige Institute of Engineering Management & Research, Indore

Name of Student: ____________________________Roll No: __________________________

Subject: ___________________________ Branch: __________ Year: ________ Sem: __________

Date of Experiment: ____________ Date of Submission: ___________ Teacher Signature

Experiment: 3

2.1 Matrix generation


Matrices are fundamental to MATLAB. Therefore, we need to become familiar with matrix
generation and manipulation. Matrices can be generated in several ways.

Entering a vector
A vector is a special case of a matrix. The purpose of this section is to show how to create
vectors and matrices in MATLAB. As discussed earlier, an array of dimension 1 × n is called
a row vector, whereas an array of dimension m × 1 is called a column vector. The elements of
vectors in MATLAB are enclosed by square brackets and are separated by spaces or by
commas. For example, to enter a row vector, v, type

>> v = [1 4 7 10 13]
v =
1 4 7 10 13

Column vectors are created in a similar way, however, semicolon (;) must separate the
components of a column vector,

>> w = [1;4;7;10;13]
w =
1
4
7
10
13

Thus, v(1) is the first element of vector v, v(2) its second element, and so forth.
Furthermore, to access blocks of elements, we use MATLAB’s colon notation (:). For exam-
ple, to access the first three elements of v, we write,
Prestige Institute of Engineering Management & Research, Indore

>> v(1:3)
ans =
1 4 7

Or, all elements from the third through the last elements,

>> v(3,end)

Ans = 7 10 13

Entering a matrix
A matrix is an array of numbers. To type a matrix into MATLAB you must

• begin with a square bracket, [


• separate elements in a row with spaces or commas (,)
• use a semicolon (;) to separate rows
• end the matrix with another square bracket, ].

Here is a typical example. To enter a matrix A, such as,


1 2 3
A= 4 5 6 (2.1)
7 8 9
type,

>> A = [1 2 3; 4 5 6; 7 8 9]

MATLAB then displays the 3 × 3 matrix as follows,

A =
1 2 3
4 5 6
7 8 9
Prestige Institute of Engineering Management & Research, Indore

2.1.1 Creating a sub-matrix


To extract a submatrix B consisting of rows 2 and 3 and columns 1 and 2 of the matrix A,
do the following

>> B = A([2 3],[1


2]) B=
4 5
7 8

To interchange rows 1 and 2 of A, use the vector of row indices together with the colon
operator.

>> = A([2 1 3],:)


C =
C
4 5 6
1 2 3
7 8 0

Deleting row or column


To delete a row or column of a matrix, use the empty vector operator, [ ].

>> A(3,:) =
[] A =
1 2 3
4 5 6

Third row of matrix A is now deleted. To restore the third row, we use a technique for
creating a matrix

>> A = [A(1,:);A(2,:);[7 8 0]]


A =
1 2 3
4 5 6
7 8 0

Matrix A is now restored to its original form.


Prestige Institute of Engineering Management & Research, Indore

2.1.2 Dimension
To determine the dimensions of a matrix or vector, use the command size. For example,

>> size(A)
ans =
3 3

means 3 rows and 3 columns.


Or more explicitly with,

>> [m,n]=size(A)

Transposing a matrix
The transpose operation is denoted by an apostrophe or a single quote (’). It flips a matrix
about its main diagonal and it turns a row vector into a column vector. Thus,

>>
A’
ans =
1 4 7
2 5 8
3 6 0

By using linear algebra notation, the transpose of m n×real matrix A is the n m×matrix that
results from interchanging the rows and columns of A. The transpose matrix is denoted AT .

Matrix generators
MATLAB provides functions that generates elementary matrices. The matrix of zeros, the
matrix of ones, and the identity matrix are returned by the functions zeros, ones, and eye,
respectively.

Table 2.4: Elementary matrices


eye(m,n) Returns an m-by-n matrix with 1 on the main diagonal
eye(n) Returns an n-by-n square identity matrix
zeros(m,n) Returns an m-by-n matrix of zeros
ones(m,n) Returns an m-by-n matrix of ones
diag(A) Extracts the diagonal of matrix A
rand(m,n) Returns an m-by-n matrix of random numbers
Prestige Institute of Engineering Management & Research, Indore

For a complete list of elementary matrices and matrix manipulations, type help elmat
or doc elmat. Here are some examples:

1. >> b=ones(3,1)
b =
1
1
1

Transposing a matrix
The transpose operation is denoted by an apostrophe or a single quote (’). It flips a matrix
about its main diagonal and it turns a row vector into a column vector. Thus,

>> A’
ans =
1 4 7
2 5 8
3 6 0

By using linear algebra notation, the transpose of m n×real matrix A is the n m×matrix that
results from interchanging the rows and columns of A. The transpose matrix is denoted AT .

Matrix generators
MATLAB provides functions that generates elementary matrices. The matrix of zeros, the
matrix of ones, and the identity matrix are returned by the functions zeros, ones, and eye,
respectively.

Table 2.4: Elementary matrices


eye(m,n) Returns an m-by-n matrix with 1 on the main diagonal
eye(n) Returns an n-by-n square identity matrix
zeros(m,n) Returns an m-by-n matrix of zeros
ones(m,n) Returns an m-by-n matrix of ones
diag(A) Extracts the diagonal of matrix A
rand(m,n) Returns an m-by-n matrix of random numbers

For a complete list of elementary matrices and matrix manipulations, type help elmat
or doc elmat. Here are some examples:

1. >> b=ones(3,1)
Prestige Institute of Engineering Management & Research, Indore

b =
1
1
1

Equivalently, we can define b as >> b=[1;1;1]

2. >> eye(3)
ans =
1 0 0
0 1 0
0 0 1

3. >> c=zeros(2,3)
c =
0 0 0
0 0 0

In addition, it is important to remember that the three elementary operations of ad- dition
(+), subtraction ( ), and multiplication
— ( ) apply also∗to matrices whenever the dimensions are
compatible.
Two other important matrix generation functions are rand and randn, which generate
matrices of (pseudo-)random numbers using the same syntax as eye.
In addition, matrices can be constructed in a block form. With C defined by C = [1
2; 3 4], we may create a matrix D as follows

>> = [C zeros(2); ones(2) eye(2)]


D
D =
1 2 0 0
3 4 0 0
1 1 1 0
1 1 0 1

Matrix inverse
Let’s consider the same matrix A.

1 2 3
A= 4 5 6
7 8 0

Calculating the inverse of A manually is probably not a pleasant work. Here the hand-
Prestige Institute of Engineering Management & Research, Indore

calculation of A−1 gives as a final result:

−16 8 −1
1
A−1 = 14 −7 2
9 −1 2 −1

In MATLAB, however, it becomes as simple as the following commands:

>> A = [1 3; 4 5 6; 7 8 0];
2
>> inv(A)
ans =
-1.7778 0.8889 -0.1111
1.5556 -0.7778 0.2222
-0.1111 0.2222 -0.1111

which is similar to: −16 8 −1


−1 1

A = 14 −7 2
9 −1 2 −1
and the determinant of A is

>>
det(A)
ans= 27
Prestige Institute of Engineering Management & Research, Indore

Name of Student: ____________________________Roll No: __________________________

Subject: ___________________________ Branch: __________ Year: ________ Sem: __________

Date of Experiment: ____________ Date of Submission: ___________ Teacher Signature

Experiment: 4
(1) Generate two causal signals and perform convolution of them.

MATLAB CODE:

% Define the causal signals


n1 = 0:10; % Time indices for first signal
n2 = 0:10; % Time indices for second signal

x1 = n1; % First causal signal (ramp signal)


x2 = ones(1, length(n2)); % Second causal signal (step signal)

% Perform convolution
y = conv(x1, x2);

% Time indices for the convolution result


n3 = 0:(length(y) - 1);

% Plot the signals


figure;

subplot(3, 1, 1);
stem(n1, x1, 'b', 'LineWidth', 1.5);
title('First Causal Signal x1[n] (Ramp)');
xlabel('n');
ylabel('Amplitude');
grid on;
Prestige Institute of Engineering Management & Research, Indore

subplot(3, 1, 2);
stem(n2, x2, 'r', 'LineWidth', 1.5);
title('Second Causal Signal x2[n] (Step)');
xlabel('n');
ylabel('Amplitude');
grid on;

subplot(3, 1, 3);
stem(n3, y, 'k', 'LineWidth', 1.5);
title('Convolution Result y[n]');
xlabel('n');
ylabel('Amplitude');
grid on;

RESULT:
Prestige Institute of Engineering Management & Research, Indore
(2) Generate a message signal of 500 Hz (0-5V) (consider square or triangular) and
amplitude modulate the sinusoidal carrier of 10 Kz (10V).

MATLAB CODE:

% Parameters
Fs = 1e6; % Sampling frequency
t = 0:1/Fs:0.01; % Time vector (10 ms duration)

% Message Signal (500 Hz, triangular waveform, 0-5V)


f_message = 500; % Frequency of message signal
A_message = 5; % Amplitude of message signal
message_signal = A_message * sawtooth(2 * pi * f_message * t, 0.5); % Triangular wave

% Carrier Signal (10 kHz, sinusoidal waveform, 10V amplitude)


f_carrier = 10000; % Frequency of carrier signal
A_carrier = 10; % Amplitude of carrier signal
carrier_signal = A_carrier * sin(2 * pi * f_carrier * t);

% Amplitude Modulation
modulated_signal = (1 + message_signal / A_message) .* carrier_signal;

% Plotting
figure;
subplot(3,1,1);
plot(t, message_signal);
title('Message Signal (500 Hz Triangular Wave)');
xlabel('Time (s)');
ylabel('Amplitude (V)');
grid on;

subplot(3,1,2);
plot(t, carrier_signal);
title('Carrier Signal (10 kHz Sinusoidal Wave)');
xlabel('Time (s)');
ylabel('Amplitude (V)');
grid on;
Prestige Institute of Engineering Management & Research, Indore

subplot(3,1,3);
plot(t, modulated_signal);
title('Amplitude Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude (V)');
grid on;

RESULT:
Prestige Institute of Engineering Management & Research, Indore

Name of Student: ____________________________Roll No: __________________________

Subject: ___________________________ Branch: __________ Year: ________ Sem: __________

Date of Experiment: ____________ Date of Submission: ___________ Teacher Signature

Experiment: 5
Aim: Generating Sine and Cosine wave through Simulink [MATLAB]

Figure: Simulink of generation of Sine wave [using sine wave block, gain block and
scope].

Figure: Generation of Sine wave using MATLAB code.


Prestige Institute of Engineering Management & Research, Indore

Figure: Generation of Cos wave using MATLAB code.

Figure: Cosine wave and Sine wave.


Prestige Institute of Engineering Management & Research, Indore

Name of Student: ____________________________Roll No: __________________________

Subject: ___________________________ Branch: __________ Year: ________ Sem: __________

Date of Experiment: ____________ Date of Submission: ___________ Teacher Signature

Experiment: 6
Aim: Arithmetic Operations in Simulink.

Figure of Arithmetic Operation on Simulink MATLAB.

Figure of Addition of two constant numbers on Simulink MATLAB.


Prestige Institute of Engineering Management & Research, Indore

Name of Student: ____________________________Roll No: __________________________

Subject: ___________________________ Branch: __________ Year: ________ Sem: __________

Date of Experiment: ____________ Date of Submission: ___________ Teacher Signature

Experiment: 7
Aim: Procedure of installation of Support Package of Arduino Uno setup in MATLAB
Here, is the procedure of how to setup the support package of Arduino Uno in MATLAB with steps as
follows.
Step 1: Open MATLAB then click on Add-Ons option, after that select Get Hardware Support
Packages.

Step 2: Search for “MATLAB Support Package for Arduino Hardware” and click on it.
Prestige Institute of Engineering Management & Research, Indore

Step 3: After that a new tab will open in which you have to install the package as shown below.

Step 4: Then it will download the necessary files to run the Support Package; After completion click
on install.

Step 5: after installation, you have to connect the Arduino Uno with your Device, you can connect
Arduino by any of these methods that are by USB, by Bluetooth or WIFI.
Prestige Institute of Engineering Management & Research, Indore

Step 7: After that, you will get a new “Hardware Setup” window. In which we have to choose board
type and Port, after selecting, we have to select libraries to be include in the server. Then click on
Program button.

 Then a message will show below [Succes! Click Next to proceed.]


 Now, Arduino UNO is successfully connected with your device.
Prestige Institute of Engineering Management & Research, Indore
Name of Student: ____________________________Roll No: ______________________________

Subject: ___________________________ Branch: __________ Year: ________ Sem: __________

Date of Experiment: ____________ Date of Submission: ___________ Teacher Signature______

Experiment: 8
Aim: Procedure of installation of Support Package of Raspberry Pi setup in MATLAB
Here, is the procedure of how to setup the support package of Raspberry Pi in MATLAB with steps
as follows.
Step 1: Open MATLAB then click on Add-Ons option, after that select Get Hardware Support
Packages.

Step 2: Search for “Simulink Support Package for Raspberry Hardware” and click on it.
Prestige Institute of Engineering Management & Research, Indore
Step 4: Then it will download the necessary files to run the Support Package

Step 5: Then open Simulink, create a Blank Model.

Step 6: After that click on Apps then go to “Get Add-Ons” then click on Get Hardware Support
Packages
Prestige Institute of Engineering Management & Research, Indore
Step 7: A window will pop up, you have to click on three dots of “MATLAB Support Package for
Raspberry Pi Hardware”, then click on step up.

Step 8: a new window will in which you to select your Raspberry Pi model. [Note: your device
should be connected with Raspberry Pi from this step]
Prestige Institute of Engineering Management & Research, Indore
Step 9: Complete Installation

The installer may ask for additional configurations or downloads. Allow the installer to complete
these. After installation, you will see a confirmation message.

Step 10: Verify Installation


Run a test command, such as:
mypi = raspi;
disp(mypi)
If the setup is successful, it will display information about your Raspberry Pi.
This process ensures your MATLAB environment is ready to communicate and work with your
Raspberry Pi.
Prestige Institute of Engineering Management & Research, Indore
Name of Student: ____________________________Roll No: ______________________________

Subject: ___________________________ Branch: __________ Year: ________ Sem: __________

Date of Experiment: ____________ Date of Submission: ___________ Teacher Signature______

Experiment: 9
Aim: Interface sensors with a microcontroller and capture real-time data.

Answer: we will interface Sensors that is DTH11 Temperature sensor, after that it will connect to a
microcontroller (e.g., Arduin UNO), and analysis the data, and verify with serial monitor.

2. Establish communication between the microcontroller and MATLAB for data transfer.
Prestige Institute of Engineering Management & Research, Indore
3. Implement data logging techniques in MATLAB to store and manage sensor data.

4. Use MATLAB to process, analyze, and visualize the logged data.


Prestige Institute of Engineering Management & Research, Indore
5. Apply basic signal processing techniques to extract meaningful insights from sensor data.

You might also like