Matlab Project File

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

MATLAB PRACTICAL FILE

BACHELOR OF TECHNOLOGY IN
ELECTRONICS & COMMUNICATION ENGINEERING

UNIVERSITY SCHOOL OF INFORMATION,


COMMUNICATION & TECHNOLOGY,
GGSIPU, DWARKA SECTOR 16C, NEW DELHI

Submitted by
HIMANSHU (02316412820)
BTECH ECE 7th SEM

Submitted to
Mr Manvendra Singh
(Research Scholar, USICT )
INDEX

SNo. Experiment

1 Write a brief introduction about MATLAB.

2 Write MATLAB programs for matrix operations: Transpose, Inverse,


Multiplication, Concatenation

3 Write MATLAB programs for Arrays to find the smallest number in the array
and sort the array

4 Write MATLAB program for 2D plotting and 3D plotting

5 a) Write a MATLAB program to find the first 10 terms of the Fibonacci


series using For loop.
b) Write a MATLAB program to find all terms of Fibonacci series with
values less than 300 using While loop

6 Write a MATLAB script for the example given below:


Location of a ball thrown upwards is given by y=v0t−1/2gt^2 . calculate the
location of the ball for every 0.1 seconds until it reaches the ground (i.e.,
y>0).

7 Write a MATLAB function to calculate the given equation, f=


c0+c1x+c2x2+…+cnxn, where, c0=1, cm=1/m.
8 Write a MATLAB script for image processing
a) Resizing and showing original color image
b) Convert rgb to gray image
c) Convert image to binary image
d) Show intensity profile of the image

9 Write a brief introduction about Simulink. Also, create a model and show the
simulation for that model.

10 Write a code to generate and plot a sinusoidal signal with frequency 100 Hz
and amplitude 1 V

11 Write a code to calculate the Fourier transform of a square wave


EXPERIMENT 1

AIM: Write a brief introduction about MATLAB.

MATLAB (matrix laboratory) is a fourth-generation high-level programming language


and interactive environment for numerical computation, visualization and programming.

It allows matrix manipulations; plotting of functions and data; implementation of


algorithms; creation of user interfaces; interfacing with programs written in other
languages, including C, C++, Java, and FORTRAN; analyze data; develop algorithms;
and create models and applications.

It has numerous built-in commands and math functions that help you in mathematical
calculations, generating plots, and performing numerical methods.

Applications of Matlab is built around the Matlab scripting language and revolves based
on the following mathematical concepts:
- Variables
- Vectors and matrices
- Structures
- Functions
- Function handles
- Classes and object-oriented programming

APPLICATIONS
1. Embedded Systems
Embedded systems are computer systems consisting of hardware and software components and
are designed to do a specific task. Some examples of embedded systems are washing machines,
printers, automobiles, cameras, industrial machines, etc. With the push of one button, Matlab
allows us to generate code and run it on hardware.
2. Control Systems
Another most common reason why the use of Matlab is important is that it provides control to
devices and systems. A control system is responsible for managing, giving commands and
regulating the behavior of other devices or systems. It is based on control loops. The devices or
systems being controlled can range from simple home heaters to large industrial control systems
that control the processes or the machines. The control system toolbox of Matlab provides
algorithms and apps for systematically analyzing, designing and tuning linear control systems.

3. Digital Signal Processing


Digital signal processing is the usage of digital processing such as by computers or specialized
digital signal processors to perform a range of signal processing operations. uses of Matlab
products make it easy to use signal processing techniques to analyze time series data and also
provides a unified workflow for the development of embedded systems and streaming
applications.

4. Wireless Communication
Wireless communication is a broad term used for connecting two devices using a wireless signal.
Teams in wireless Engineering use Matlab too reduce development time, eliminate design
problems early, and streamline testing and verification.

5. Image Processing and Computer Vision


Image processing is mainly focused on the processing of raw images and making them ready for
other tasks such as computer vision. Computer vision, on the other hand, looks at images like the
human eye. It involves understanding and predicting the visual output. Algorithm building is vital
for image processing and computer vision. Uses of Matlab provides a comprehensive
environment to analyze images and build algorithms.

6. Internet of Things
Internet of Things is the network of devices, vehicles and home appliances and others embedded
with electronics, software, sensors, actuators, and connectivity which enables the exchange of
data. uses of Matlab help in the design, prototype, and deployment of IOT applications such as
predictive maintenance, operations optimization, supervisory control etc.

7. FPGA Design and Codesign


Matlab enables hardware-software codesign by providing C/C++ and HDL code generation with
targeted support for programmable SoC devices.

TOOLS AND OTHER USES


1. Statistics and Machine Learning Toolbox
It provides functions and apps to describe, analyze, and model data. You can use descriptive
statistics, visualizations, and clustering for exploratory data analysis, fit probability distributions to
data, generate random numbers for Monte Carlo simulations, and perform hypothesis tests.
Regression and classification algorithms let you draw inferences from data and build predictive
models either interactively, using the Classification and Regression Learner apps, or
programmatically, using AutoML.

2. Curve Fitting Toolbox


It provides an app and functions for fitting curves and surfaces to data. The toolbox lets you
perform exploratory data analysis, preprocess and post-process data, compare candidate
models, and remove outliers. You can conduct regression analysis using the library of linear and
nonlinear models provided or specify your own custom equations. The library provides optimized
solver parameters and starting conditions to improve the quality of your fits. The toolbox also
supports nonparametric modeling techniques, such as splines, interpolation, and smoothing.

After creating a fit, you can apply a variety of post-processing methods for plotting, interpolation,
and extrapolation; estimating confidence intervals; and calculating integrals and derivatives.

3. Control System Toolbox


It provides algorithms and apps for systematically analyzing, designing, and tuning linear control
systems. You can specify your system as a transfer function, statespace, zero-pole-gain, or
frequency-response model. Apps and functions, such as step response plot and Bode plot, let
you analyze and visualize system behavior in the time and frequency domains.

You can tune compensator parameters using interactive techniques such as Bode loop shaping
and the root locus method. The toolbox automatically tunes both SISO and MIMO compensators,
including PID controllers. Compensators can include multiple tunable blocks spanning several
feedback loops. You can tune gain-scheduled controllers and specify multiple tuning objectives,
such as reference tracking, disturbance rejection, and stability margins. You can validate your
design by verifying rise time, overshoot, settling time, gain and phase margins, and other
requirements.
4. Signal Processing Toolbox
It provides functions and apps to analyze, preprocess, and extract features from uniformly and
nonuniformly sampled signals. The toolbox includes tools for filter design and analysis,
resampling, smoothing, detrending, and power spectrum estimation. The toolbox also provides
functionality for extracting features like changepoints and envelopes, finding peaks and signal
patterns, quantifying signal similarities, and performing measurements such as SNR and
distortion. You can also perform modal and order analysis of vibration signals.

5. Mapping Toolbox
It provides algorithms and functions for transforming geographic data and creating map displays.
You can visualize your data in a geographic context, build map displays from more than 60 map
projections, and transform data from a variety of sources into a consistent geographic coordinate
system.

Mapping Toolbox supports a complete workflow for managing geographic data. You can import
vector and raster data from a wide range of file formats and web map servers. The toolbox lets
you process and customize data using trimming, interpolation, resampling, coordinate
transformations, and other techniques. Data can be combined with base map layers from multiple
sources in a single map display. You can export data in file formats such as shapefile, GeoTIFF,
and KML.

6. System Identification Toolbox


It provides MATLAB functions, Simulink blocks, and an app for constructing mathematical models
of dynamic systems from measured input-output data. It lets you create and use models of
dynamic systems not easily modeled from first principles or specifications. You can use time-
domain and frequency-domain input-output data to identify continuous-time and discrete-time
transfer functions, process models, and state-space models. The toolbox also provides
algorithms for embedded online parameter estimation.

The toolbox provides identification techniques such as maximum likelihood, prediction-error


minimization (PEM), and subspace system identification. To represent nonlinear system
dynamics, you can estimate Hammerstein-Weiner models and nonlinear ARX models with
wavelet network, tree-partition, and sigmoid network nonlinearities. The toolbox performs greybox
system identification for estimating parameters of a user-defined model. You can use the
identified model for
system response prediction and plant modeling in Simulink. The toolbox also supports time-series
data modeling and time-series forecasting.

7. Deep Learning Toolbox


It provides a framework for designing and implementing deep neural networks with algorithms,
pretrained models, and apps. You can use convolutional neural networks (ConvNets, CNNs) and
long short-term memory (LSTM) networks to perform classification and regression on image,
time-series, and text data. You can build network architectures such as generative adversarial
networks (GANs) and Siamese networks using automatic differentiation, custom training loops,
and shared weights. With the Deep Network Designer app, you can design, analyze, and train
networks graphically. The Experiment Manager app helps you manage multiple deep learning
experiments, keep track of training parameters, analyze results, and compare code from different
experiments. You can visualize layer activations and graphically monitor training progress.

8. DSP System Toolbox


It provides algorithms, apps, and scopes for designing, simulating, and analyzing signal
processing systems in MATLAB® and Simulink®. You can model real-time DSP systems for
communications, radar, audio, medical devices, IoT, and other applications.

With DSP System Toolbox you can design and analyze FIR, IIR, multirate, multistage, and
adaptive filters. You can stream signals from variables, data files, and network devices for system
development and verification. The Time Scope, Spectrum Analyzer, and Logic Analyzer let you
dynamically visualize and measure streaming signals. For desktop prototyping and deployment to
embedded processors, including ARM® Cortex® architectures, the toolbox supports C/C++ code
generation. It also supports bit-accurate fixed-point modeling and HDL code generation from
filters, FFT, IFFT, and other algorithms.

9. Datafeed Toolbox
It provides access to financial data, news and social media data, and trading systems. You can
establish connections from MATLAB® to retrieve historical, intraday, or realtime data streams and
then perform analyses, develop models and financial trading strategies, and create visualizations
that reflect financial and market behavior.

You can use the streaming and event-based data in MATLAB to build automated trading
strategies that react to market events via industry-standard or proprietary trade execution
platforms. The toolbox includes functions for analyzing transaction costs, accessing trade and
quote pricing data, defining order types, and executing orders.

10. Financial Toolbox


It provides functions for the mathematical modeling and statistical analysis of financial data. You
can analyze, backtest, and optimize investment portfolios taking into account turnover,
transaction costs, semi-continuous constraints, and minimum or maximum number of assets. The
toolbox enables you to estimate risk, model credit scorecards, analyze yield curves, price fixed-
income instruments and European options, and measure investment performance.

Stochastic differential equation (SDE) tools let you model and simulate a variety of stochastic
processes. Time series analysis functions let you perform transformations or regressions with
missing data and convert between different trading calendars and day-count conventions.

11. Image Processing Toolbox


It provides a comprehensive set of reference-standard algorithms and workflow apps for image
processing, analysis, visualization, and algorithm development. You can perform image
segmentation, image enhancement, noise reduction, geometric transformations, andnimage
registration using deep learning and traditional image processing techniques. The toolbox
supports processing of 2D, 3D, and arbitrarily large images.
Image Processing Toolbox apps let you automate common image processing workflows. You can
interactively segment image data, compare image registration techniques, and batchprocess
large datasets. Visualization functions and apps let you explore images, 3D volumes, and videos;
adjust contrast; create histograms; and manipulate regions of interest (ROIs).

12. Text Analytics Toolbox


It provides algorithms and visualizations for preprocessing, analyzing, and modeling text data.
Models created with the toolbox can be used in applications such as sentiment analysis,
predictive maintenance, and topic modeling.

Text Analytics Toolbox includes tools for processing raw text from sources such as equipment
logs, news feeds, surveys, operator reports, and social media. You can extract text from popular
file formats, preprocess raw text, extract individual words, convert text into numerical
representations, and build statistical models.
Using machine learning techniques such as LSA, LDA, and word embeddings, you can find
clusters and create features from high-dimensional text datasets. Features created with Text
Analytics Toolbox can be combined with features from other data sources to build machine
learning models that take advantage of textual, numeric, and other types of data.
EXPERIMENT 2

AIM: Write MATLAB programs for matrix operations:


a) Transpose
b) Inverse
c) Multiplication
d) Concatenation

A) Transpose
Code
a = [1 3 5; 2 4 6; 7 8 9]
b = transpose(a)

Output

B) Inverse
Code
a = [1 3 5; 2 4 6; 7 8 9]
g = inv (a)

Output
C) Multiplication
Code
a=[1 3 5;2 4 6;7 8 9 ]
b=[1 2 3;4 5 6;7 8 9]
c=a*b

Output

D) Concatenation
Code
a=[1 3 5;2 4 6;7 8 9 ]
b=[1 2 3;4 5 6;7 8 9]
d=[ab]

Output
EXPERIMENT 3

AIM: Write MATLAB programs for Arrays:


a) To find the smallest number in Array
b) To sort the Array.

Code
A=[12 62 93 -8]
D=Min(A)
B= sort(A)

Output
EXPERIMENT 4

AIM: Write MATLAB programs for:


a) 2D Plotting
b) 3D Plotting

A) 2D Plotting
Code
%for constant doc f
= [100 63 40 16];
s9 =[0.68 0.62 0.5 0.36];
s13= [0.66 0.54 0.46 0.35];
s18= [0.66 0.52 0.4 0.35];
s25 =[0.64 0.5 0.4 0.32];
plot (f,s9, '--bo', f, s13, '--ro', f,s18, --go', f, s25, '--yo');
xlabel('feed (mm/mm)');
ylabel('surface roughness (micro m) ');

Output

A) 3D Plotting
Code
x = linspace(-2,2,20);
y = x';
[X, Y] = meshgrid(x, y);
Z = sqrt(2 - X.^2 - Y.^2);
surf(X, Y, Z);

Output
EXPERIMENT 5

AIM: Write MATLAB programs for:


a) Write a MATLAB program to find the first 10 terms of the Fibonacci series using
For loop.
b) Write a MATLAB program to find all terms of Fibonacci series with values less
than 300 using While loop

A) Write a MATLAB program to find the first 10 terms of the Fibonacci series
using For loop.
Code
clc
clear all
% Call the Fibonacci function and specify the number of terms
Fibonacci(10);
function fibn = Fibonacci(n)
% Initializing first two values for Fibonacci sequence
fibn = zeros(1, n);
fibn(1) = 0;
fibn(2) = 1;
% Generating Fibonacci sequence
for i = 3:n
fibn(i) = fibn(i - 2) + fibn(i - 1);
end
end

Output
B) Write a MATLAB program to find all terms of Fibonacci series with values less
than 300 using While loop
Code
clc
clear all
Fibonacci(300);
function fibn = Fibonacci(n)
fibn = [1 1];
i = 3;
while fibn(i - 1) < n
fibn(i) = fibn(i - 2) + fibn(i - 1);
i = i + 1;
end
fibn = fibn(1:end - 1);
end

Output
EXPERIMENT 6

AIM: Write a MATLAB script for the example given below:

Location of a ball thrown upwards is given by y=v0t−1/2gt^2 . calculate the location of


the ball for every 0.1 seconds until it reaches the ground (i.e., y>0).

Code
v0 = 20;
g = 9.8;
y = 0;
t = 0;
while (y >= 0)
disp(['at t = ', num2str(t), ', location = ', num2str(y)]);
t = t + 0.1;
y = v0 * t - g * t^2 / 2;
End

Output
EXPERIMENT 7

AIM: Write a MATLAB function to calculate the given equation, f=


c0+c1x+c2x2+…+cnxn, where, c0=1, cm=1/m.

Code
Function result = myFunction(n,x)
C= [1];
vec = [1:n];
C = [C, 1./vec];
a= [1,x.^vec];
result = sum (C. *a);
end
EXPERIMENT 8

AIM: Write a MATLAB script for image processing


a) Resizing and showing original color image
b) Convert rgb to gray image
c) Convert image to binary image
d) Show intensity profile of the image

Code
close all
clear all

myimage = imread('C:\Users\devan\Desktop\yo.jpeg');
mycolorimage = imresize(myimage, [256,256],'nearest');
mygrayimage = rgb2gray(mycolorimage);
mybinimage = im2bw(mycolorimage);

subplot(2,2,1);
imshow(mycolorimage);
title('Original Colour Image');

subplot(2,2,2);
imshow(mygrayimage);
title('Gray Image');

subplot(2,2,3);
imshow(mybinimage);
title('Binary Image');

subplot(2,2,4);
improfile(mygrayimage, [10,50], [45,100]);
ylabel('Pixel Value');
xlabel('Distance');
title('Intensity Profile of the Given Image');

Output
EXPERIMENT 9

AIM: Write a brief introduction about Simulink. Also, create a model and show the
simulation for that model

Simulink is a MATLAB-based graphical programming environment for modeling,


simulating and analyzing multidomain dynamical systems. Its primary interface is a
graphical block diagramming tool and a customizable set of block libraries. It offers tight
integration with the rest of the MATLAB environment and can either drive MATLAB or
be scripted from it. Simulink is widely used in automatic control and digital signal
processing for multidomain simulation and model-based design.

Model
EXPERIMENT 10

AIM: Write a code to generate and plot a sinusoidal signal with frequency 100 Hz and
amplitude 1 V

CODE
f = 100; % Frequency in Hz
A = 1; % Amplitude in V
t = 0:0.01:1; % Time vector in seconds
y = A * sin(2 * pi * f * t); % Sinusoidal signal
plot(t, y); % Plot the signal
title('Sinusoidal Signal');
xlabel('Time (s)');
ylabel('Amplitude (V)');

OUTPUT
EXPERIMENT 11

AIM: Write a code to calculate the Fourier transform of a square wave

CODE
% Calculate the Fourier transform of a square wave
n = 0:100;
x = ((n >= 25) & (n < 75)) + 1;
X = abs(fft(x));
% Plot the magnitude of the Fourier transform
plot(abs(X));

xlabel('Frequency (Hz)');
ylabel('Magnitude');

OUTPUT

You might also like