Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Introduction of MATLAB

The document is a lab report for an experiment on MATLAB, detailing its objectives, theoretical background, and practical tasks. It covers basic MATLAB commands, plotting sine and cosine waves, and adding noise to signals, demonstrating MATLAB's capabilities in data visualization and numerical computation. The report concludes with an affirmation of MATLAB's importance in engineering and scientific applications.

Uploaded by

2204002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Introduction of MATLAB

The document is a lab report for an experiment on MATLAB, detailing its objectives, theoretical background, and practical tasks. It covers basic MATLAB commands, plotting sine and cosine waves, and adding noise to signals, demonstrating MATLAB's capabilities in data visualization and numerical computation. The report concludes with an affirmation of MATLAB's importance in engineering and scientific applications.

Uploaded by

2204002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Heaven’s Light is Our Guide

Rajshahi University of Engineering & Technology


Department of Electronics & Telecommunication Engineering

ETE 2110: Electronic Circuit Design & Simulation Lab

Experiment No. 1
Experiment Name: Introduction of MATLAB

Submitted by: Submitted to:


Sheikh Tanjim Ahmed Hasan Sarker

Roll: 2204002 Assistant Professor

Session: 2022-23 Dept. of ETE, RUET

Date of Experiment : 04/12/2024


Date of Submission : 08/01/2025

Report (Teacher’s Section) Viva


□ Excellent □ Excellent
□ Very Good □ Very Good
□ Good ——————————– □ Good
□ Average Signature □ Average
□ Poor □ Poor
Experiment No: 1

Experiment Name: Introduction of MATLAB.

1.1 Objectives:

• To create basic plotting and visualizations.

• To learn the basic features of MATLAB.

1.2 Theory:

A flexible computational tool for developing algorithms, data visualization, and numerical
computation is called MATLAB (Matrix Laboratory). It is perfect for domains like machine
learning, control systems, and signal processing because of its proficiency in matrix opera-
tions. MATLAB facilitates effective problem solving and graphical visualization in both 2D
and 3D with its robust functions and toolboxes.

MATLAB Commands and Functions

• clc (Clear Command Window)


Syntax: clc

The clc command clears the Command Window in MATLAB, providing a clean win-
dow. It is useful for improving code readability during interactive sessions.

• clear all
Syntax: clear all

The clear all command removes all variables from the workspace and makes the
memory free. This command is beneficial when you want to avoid conflicts between
variables of the same name.

• close all
Syntax: close all

1
The close all command closes all open figure windows in MATLAB. It’s helpful for
managing resources and reducing clutter on the screen.

• .ˆ (Element-wise Power)
Syntax: A .B̂

The .ˆ operator performs element-wise power, allowing you to raise each element of
a matrix or array to a specified power individually.

• + (Addition)
Syntax: A + B

The + operator is used for addition in MATLAB, whether it’s scalar addition or matrix
addition.

• - (Subtraction)
Syntax: A - B

The - operator is used for subtraction, performing element-wise subtraction for ma-
trices or subtracting scalar values.

• * (Multiplication)
Syntax: A * B

The * operator performs matrix multiplication or scalar multiplication in MATLAB.

• / (Division)
Syntax: A / B

The / operator performs matrix right division or scalar division in MATLAB.

• ; (Semicolon for Suppressing Output)


Syntax: A = [1 2 3];

The semicolon is used at the end of a statement to suppress the output from being
displayed in the Command Window.

• input
Syntax: x = input(’Prompt: ’)

2
The input function reads and evaluates a specified file, allowing interaction with the
user for input during program execution.

• disp
Syntax: disp(x)

The disp function displays the value of a variable or expression. It is commonly used
for printing results in the Command Window.

• figure
Syntax: figure

The figure command creates a new figure for plotting. MATLAB figures provide a
blank space for visualizing data and results.

• plot
Syntax: plot(X, Y)

The plot function is used for creating 2D plots in MATLAB. It allows you to visualize
data points and relationships between variables.

• title, xlabel, ylabel


Syntax:

– title(’Title Text’)

– xlabel(’X-axis Label’)

– ylabel(’Y-axis Label’)

These functions are used to set titles and labels for the plot, making it more informative
and understandable.

• subplot
Syntax: subplot(m, n, p)

The subplot function divides the figure window into subplots, allowing multiple plots
to be displayed within the same figure.

3
• grid
Syntax: grid on or grid off

The grid function displays grid lines on a plot, aiding in the visual interpretation of
data.

• filter
Syntax: y = filter(b, a, x)

The filter function in MATLAB is used to apply a filter operation to a signal, which is
crucial in signal processing and analysis.

1.3 Required Software:

• MATLAB R2024b

1.4 Lab Tasks

Task 01: Plot Sine and Cosine waves

MATLAB Code:

1 clc ;
2 clear all ;
3 close all ;
4 p = 0;
5 a = 1;
6 w = 2* pi *5;
7 t = 0:0.001:1;
8 A = a * sin ( w * t + p ) ;
9 subplot (2 ,1 ,1) ;
10 plot (t ,A , ’ black ’) ;
11 xlabel ( ’ Time ’) ;

4
12 ylabel ( ’ Amplitude ’) ;
13 title (" Sine signal ") ;
14 grid on ;
15 B = a * cos ( w * t + p ) ;
16 subplot (2 ,1 ,2) ;
17 plot (t , B ) ;
18 xlabel ( ’ Time ’) ;
19 ylabel ( ’ Amplitude ’) ;
20 title (" Cosine signal ") ;
21 grid on ;

Output:

Figure 1.1: sine wave and cosine wave

5
Task 02: Plot the addition and subtraction of sine and cosine wave

MATLAB Code:

1 clc ;
2 clear all ;
3 close all ;
4

5 % Defining value
6 p = 0;
7 a = 1;
8 w = 2* pi *5;
9 t = 0:0.001:1;
10 % Signal equation
11 A = a * sin ( w * t + p ) ;
12 B = a * cos ( w * t + p ) ;
13 % Addition
14 y1 = A + B ;
15 subplot (2 ,1 ,1) ;
16 plot (t , y1 ) ;
17 xlabel ( ’ Time ’) ;
18 ylabel ( ’ Amplitude ’) ;
19 title (" Addition signal ") ;
20 grid on ;
21 % Subtraction
22 y2 = A - B ;
23 subplot (2 ,1 ,2) ;
24 plot (t , y2 ) ;
25 xlabel ( ’ Time ’) ;
26 ylabel ( ’ Amplitude ’) ;
27 title (" Subtraction signal ") ;
28 grid on ;

6
Output:

Figure 1.2: Addition and Subtraction of waves

Task 03: Plot a Signal, Noise, and add Noise to the Signal

MATLAB Code:

1 clc ;
2 clear all ;
3 close all ;
4

5 fs = 100;
6 T = 1/ fs ;
7 t = 0: T :1 - T ;
8 f = 2;

7
9 w = 2* pi * f ;
10 A = 10;
11 C =5;
12 % Generate Signal
13 signal = A * sin ( w * t ) ;
14

15 % Generate Noise
16 noise = C * randn ( size ( t ) ) ;
17

18 % Combined Signal ( Signal + Noise )


19 m = signal + noise ;
20 % Plotting
21 figure ;
22 subplot (3 , 1 , 1) ;
23 plot (t , signal , ’b ’ , ’ linewidth ’ , 2) ;
24 title ( ’ 1. Signal ’) ;
25 xlabel ( ’ Time ’) ;
26 ylabel ( ’ Amplitude ’) ;
27 grid on ;
28

29 subplot (3 , 1 , 2) ;
30 plot (t , noise , ’r ’ , ’ linewidth ’ , 2) ;
31 title ( ’ 2. Noise ’) ;
32 xlabel ( ’ Time ’) ;
33 ylabel ( ’ Amplitude ’) ;
34 grid on ;
35 subplot (3 ,1 ,3) ;
36 plot (t , m , ’c ’ , ’ linewidth ’ , 2) ;
37 title ( ’ 3. Noise + Signal ’) ;
38 xlabel ( ’ Time ’) ;
39 ylabel ( ’ Amplitude ’) ;
40 grid on ;

8
Output:

Figure 1.3: Noise added to a Signal

1.5 Discussion:

By the experiment, I came to a basic understanding of the usage of MATLAB as a high-level


programming language and computational tool. It gave a complete sense of the ease of use
of MATLAB through simple commands to manage the workspace and its powerful matrix-
based operations for efficient problem solving. The experiment showed MATLAB’s visual-
ization capabilities with functions like plot and subplot, enabling clear and customizable
data representation. In addition, the flexibility of interactive and script-based programming
was explored, showcasing its versatility for various applications. In general, the experiment
showed the importance of MATLAB as a versatile tool for numerical computation, data anal-
ysis, and visualization in the scientific and engineering domains.

9
1.6 Conclusion:

The experiment successfully introduced the core features of MATLAB, showing its role as a
powerful tool for numerical computation, data analysis, and data visualization. This basic
knowledge is crucial for applying MATLAB to more complex problems in various domains,
including engineering, physics & data science, etc.

10

You might also like