Final PDF
Final PDF
Final PDF
STUDY
the
process
of
Page | 1
-- Chapter: 1--
SIMULINK : An INTRODUCTION
Simulink is a tool available in MATLAB. It provides an environment for
simulation of Model Based Design. It supports system level design, automatic
code generation and continuous test & verification of embedded system. Some
of its features are as follows:
Page | 2
-- Chapter: 2--
Page | 3
-- Chapter: 3--
An INTRODUCION to MATLAB
MATLAB, is a software package developed by Math Works Inc. that is used
to perform scientific computations & visualization. Its capability for analysis of
various scientific problems flexibility and graphic makes it a very useful software.
It provides an integrated development environment for programming with
numerous predefined functions for technical computations and visualization.
The environmental components of MATLAB comprises of the following:1. Command Window This is the main window that is activated as soon
as MATLAB is started. In this window commands are entered and
executed in a similar fashion as in C environment.
2. Command History As the name itself describes, it contains all the
commands that have been entered and executed.
3. Workspace Similar to C, variables are generated in MATLAB. The
Workspace contains all the variables that have been generated.
4. Current Directory It lists all the files and folders present in the current
directory similar to DOS.
5. Edit Window This window is used when we are required to create a
script or a function.
6. Figure Window This window is invoked through command when we
are in need to display a graphical representation.
MATLAB has its own file types:1. M Files :- It is an extension that denotes a script or function of MATLAB.
a. A script is a file that contains a set of MATLAB commands. This file
does have its own variable and uses the variables stored in
workspace for its functionality.
b. A function is a file that begins with function definition and similar
to a C program it has its own program and variables.
2. MAT Files :- They denote a binary data file of MATLAB that is saved by
save command.
3. MEX Files :- This type of file contains FORTRAN or C program and is
callable in MATLAB. This file helps in integrating FORTRAN or C language
into programs developed by MATLAB.
Page | 4
Operation
Expression
Result
Addition
p+q
Subtraction
pq
.*
Multiplication
p*q
./
Left Division
p ./ q
1.5
.^
Power
p .^ q
Unary Plus
+p
+3
Unary Minus
-P
-3
2. Relational Operations
Operator
Operation
Expressio
n
Result
<
Less than
p<q
<=
p <= q
>
Greater than
p>q
>=
p >= q
==
Equal to
p == q
-=
Not equal to
p -= q
Page | 5
3. Logical Operations and functions : Let us declare the following variables A=2; B=5; C=-4; D=0
Operator
Function
Description
Expression
Result
&
A&B
A|B
~C
xor()
xor(A,B)
any()
any(A,B)
all()
all(A)
Page | 6
Page | 7
Addition:-
C=A+B
output-
7 14
21 28
Subtraction:-
C=A-B
output-
3 6
9 12
Multiplication:-
C=A*B
output-
70 100
150 200
MATLAB Graphics:- Matlab provides very good tools for 2D and 3D plots.
2d plot Plot command is used to plot 2d graphs.
E.g A Matlab program to plot a row vector having complex
number:a=[1-2i,3+4i,5+6i,3+8i,4+9i,23+12i];
plot(a);
grid on;
xlabel('x-axis');
ylabel('y-axis');
Page | 8
Page | 9
Page | 11
-- Chapter: 4--
Identify system
components
Define system
equation
Collect parameter
data
Model component
Simulate component
Change model
No
Expected
Result
Yes
No
Finished
Modelling?
Figure 7. Modelling a system
Page | 14
Page | 15
Integrating the simulation:Connect component models and simulate the model response over time
to validate the design.
The structure can be given as:-
Connect model
components
Simulate connected
components
Change model
No
Expected result
Yes
Model external
interface
Connect Model Components After each model built and validated, it can
be connect to create a complete model, then the model is simulated, and
results are analysed. Some guidelines for connecting model components:
Integrate model components by first connecting two of them (for
example, connect a plant to a controller).
After validating the pair by simulation, continue connecting
components until the model is complete. It must be kept in mind
Page | 16
how each component that has been added affects the other parts
of the model.
Simulate Connected Components Validating the model determines if it
accurately represents the physical characteristics of the modelled
dynamic system. Some guidelines for validating subsystems:
Predicting the expected simulation results and outputs of the
subsystems.
Adding realistic inputs using source blocks.
Adding sink blocks to record and visualize results. Simulate the
subsystems and compare the simulated result with the expected
result.
Model External Interface Blocks for connecting external signals into and
out of the model are added.
Page | 17
-- Chapter: 5--
Determine
simulation
goals
Collect data
Prepare
model
Set
parameters
Collect Data Input and output data from an actual system is collected.
Measured input data is used to drive the simulation. Measured output
data is used to compare with the simulation results from the model.
Measured input data is used to drive a simulation and measured output
data to verify the simulation results.
Prepare model Preparing a model for simulation includes defining the
external interfaces for input data and control signals, and output signals
for viewing and recording simulation results.
Set Parameters For the first simulation, model parameters from the
validated model is used. After comparing the simulation results with
measured output data, model parameters are changed to more
accurately represent the modelled system.
Run and evaluate the simulation:Simulate the model and verify that the simulation results match the
measured data from the modelled system.
The structure can be give as:-
Import data
Run simulation
Change model
Evaluate result
Expected
result
No
Yes
Connect
component
model
Page | 19
Import Data Simulink allows the import of data from external files such
as Excel Sheets or Comma Separated Value (CSV) files if necessary.
Run simulation Using measured input data, a simulation is run and save
results.
Evaluate result The differences between simulated output and
measured output data are evaluated. The evaluation is used to verify the
accuracy of the model and how well it represents the system behaviour.
Decision is taken whether the accuracy of the model adequately
represents the dynamic system that was being modelled.
Change model If necessary determine the changes to improve the
model. Model changes include:
Parameters if some parameters were initially estimated and
approximated. Optimize and update those parameters.
Adding structure if some parts or details of the system were not
modelled. Add missing details.
Page | 20
PHASE-II
DESIGN
--Chapter: 6--
Page | 22
1. Grayscale Colour Model Grayscale simply means black and white. In this
model representation of colour is done in a single sample, i.e. the only
information it has is that of the intensity. The colour black and white, as
said earlier is nothing but the combination of similar intensities of all RGB
colour, because of which it is possible to represent them in a single
sample. Digital imaging provides a way to represent the intensities of each
pixel by creating a range from minimum to maximum. Modern
approaches have used 8bit to sample a grayscale, which means it has 256
different intensities to measure where 0 is the lowest and 255 is the
highest.
2. RGB Colour Model The RGB colour model is called an additive colour
model, i.e. apart from RGB colour, all other colours are created by
adding RGB in various ways. This model is mostly used in electronic
systems, and its basic purpose is to represent an image for displaying in
those electronic systems. Now, to create a colour apart from RGB, a
simple procedure is done which is to just to superimpose the three RGB
coloured lights with different intensities. The perception of Black colour
is given when the intensities of each of the RGB colour is none and for
White colour, the intensities of each RGB colour is full.
Page | 23
What is Histogram?
Introduced by KARL PEARSON, histogram is the representation of
numerical data in graphical format. Statistically speaking it represents the
frequency of an object at which it is being distributed. Therefore in digital
imaging, histogram will represent the frequency at which pixels are being
distributed over the entire image. In image processing there are many
applications such as- Image segmentation, image restoration, image
enhancement etc., all of which depends on the data provided by histogram.
The histogram representation is done in a two dimensional axis.
Horizontal axis (x-axis) represents the intensities where the extreme left displays
the darker intensities and as it moves toward the right it represents the lighter
intensities and ultimately as it reaches the extreme right, it represents the white
intensities. The vertical axis (y-axis) represents the frequency of pixels of that
particular intensity. When we say histogram of an image. we generally mean
the intensity levels of a grayscale image. However it is also possible to find the
histogram of a colour image as well.
Page | 24
Process of Histogram
Let us consider a grayscale image A, then
H(k) =Histogram of image A.
Let us say the gray levels are in the range [0, L-1]
The histogram H(k), say, is derived by counting the number of pixels at
each & every gray level k .
H(k) = Nk for k = 0,1,2..L-1;
Where,
Nk is the count of pixels at gray level k,
Therefore, L = total number of bins in the histogram.
Page | 25
Page | 26
--Chapter: 7--
Starting Simulink
1. Open Matlab
2. Click on New -> Simulink Model. (This will open Simulink library browser)
3. In the Simulink library window click on File->New->Model (This will open
Simulink environment)
4. Now browse through the library and add the following models by dragging
them onto the Simulink environment.
Block
Image from file
Video Viewer
Matrix Concatenate
Vector Scope
Histogram
Library
Computer Vision ->
Sources
Computer Vision ->
Sources
Simulink -> Math
operations
DSP System Toolbox > Sinks
DSP System Toolbox > Statistics
Quantity
1
1
1
4
3
Table 4. List of blocks to be used with its quantity and library set
Page | 27
Page | 28
Now set the following parameters: Use the Image From File block to import an RGB image. Set the
block parameters as follows:
o Sample time = inf
o Image signal = Separate colour signals
o Output port labels: = R|G|B
o On the Data Types tab, Output data type: = double
Use the Video Viewer block to automatically display the original
image in the viewer window when you run the model.
o Set the Image signal parameter to Separate colour signals
from the File menu.
Use the Histogram blocks to calculate the histogram of the R, G, and
B values in the image. Set the Main tab block parameters for the
three Histogram blocks as follows:
o Lower limit of histogram: 0
o Upper limit of histogram: 1
o Number of bins: = 256
o Find the histogram over: = Entire Input
The R, G, and B input values to the Histogram block are doubleprecision floating point and range between 0 and 1. The block creates 256
bins between the maximum and minimum input values and counts the
number of R, G, and B values in each bin.
Use the Matrix Concatenate block to concatenate the R, G, and B
column vectors into a single matrix so they can be displayed using
the Vector Scope block. Set the Number of inputs parameter to 3.
Use the Vector Scope block to display the histograms of the R, G,
and B values of the input image. Set the block parameters as
follows:
o Scope Properties pane, Input domain = User-defined
o Display Properties pane, clear the Frame number check box
o Display Properties pane, select the Channel legend check box
o Display Properties pane, select the Compact display check
box
o Axis Properties pane, clear the Inherit sample increment
from input check box.
Page | 29
o
o
o
o
o
Page | 30
Page | 31
Figure 20. Vector scope displaying histogram of all three RGB channels for
comparison
Page | 32
Understanding the simulation:To understand how the simulation worked let us understand the different
blocks used in the simulation First we used the Image from File block to read an image from the
computer as desired by the user. If the image is an M-by-N array, the block
outputs a binary or intensity image, where M and N are the number of rows and
columns in the image. If the image is an M-by-N-by-P array, the block outputs a
colour image, where M and N are the number of rows and columns in each
colour plane, P. The Image signal parameter of this block is used to specify how
the block outputs a colour signal. If One multidimensional signal is selected, the
block outputs an M-by-N-by-P colour video signal, where P is the number of
colour planes, at one port. If Separate colour signals is selected, additional
ports appear on the block. Each port outputs one M-by-N plane of each Red
Green and Blue signal separately.
Now comes the Video Viewer block. The Video Viewer block allows to
view a binary, intensity, or RGB image or a video stream. The block provides
simulation controls for play, pause, and step while running the model.
The Histogram block calculates the histogram from the input values.
The Matrix Concatenate block concatenates the signals at its inputs to
create an output signal whose elements reside in contiguous locations in
memory.
The Vector Scope block is a comprehensive display tool similar to a digital
oscilloscope. The block plots each sample of each input channel sequentially
across the horizontal axis of the plot.
Now let us understand how the simulation has worked:The Image from File block reads an image, and separates the three RGB
channels. Each channel is connected to independent Histogram blocks that
calculates the histogram of its input signal. To view the image, the three RGB
channels are also branched and connected to the Video Viewer block which
displays the image that has been selected. The Vector scope connected to each
separate Histogram block displays the output of the histograms in separate
graphs. We have also branched the output signal of each Histogram block to
the Matrix Concatenate block that combines all the three different signal and
Page | 33
sends the output signal to a Vector Scope that displays all the three signals in a
single graph allowing us to compare the histograms of the RGB channels.
Page | 34
--Chapter: 8--
IMAGE ENHANCEMENT
Image Enhancement
The aim of image enhancement is to improve the interpretability or perception
of information in images for human viewers, or to provide `better' input for
other automated image processing techniques.
Image enhancement techniques can be divided into two broad categories:
1. Spatial domain methods, which operate directly on pixels,
a. Contrast and dynamic range modification
b. Noise reduction
c. Edge enhancement
2. Frequency domain methods, which operate on the Fourier transform of
an image.
However, there is no general theory for determining what `good
enhancement is when it comes to human perception. But when
enhancement techniques are used as pre-processing tools for other
processing techniques, then quantitative measures can determine
techniques are most appropriate.
image
image
image
which
especially when the usable data of the image is represented by close contrast
values. Through adjustment, the intensities can be better distributed on the
histogram. This allows for areas with lower contrast to gain a higher contrast.
Histogram equalization redistributes the pixel intensity values evenly by
using cumulative (sum) histogram as a transfer function or as a look-up table.
The idea of histogram equalization comes from the cumulative histogram.
Looking at the image above, we can see that the frequencies (the number of
pixels) at each intensity value are accumulated. The higher pixel density is, the
greater steepness is. There are 2 intervals with same width, but different slopes;
one interval has slow steepness, and the other interval has steep slope. Let's
project the intervals of the intensity values onto the other axis. Once they are
projected, they have different intervals on the projected axis. If the slope is less
than 1, the interval gets narrower. If the slope is greater than 1, then the interval
is going to be wider. In other words, we are going to spread the intensity range
if the pixel density is high, and shrink the interval if the density is low. Histogram
equalization works best on an over or under exposed image, which has narrow
contrast range.
Page | 36
L being the total number of gray levels in the image (typically 256), n being the
total number of pixels in the image, and
being in fact the image's
histogram for pixel value i, normalized to [0,1].
Let us also define the cumulative distribution function corresponding to px as
,
Which is also the image's accumulated normalized histogram.
We would like to create a transformation of the form y = T(x) to produce a new
image {y}, with a flat histogram. Such an image would have a linearized
cumulative distribution function (CDF) across the value range, i.e.
for some constant K. The properties of the CDF allow us to perform such a
transform; it is defined as
where k is in the range [0,L). Notice that T maps the levels into the range [0,1],
since we used a normalized histogram of {x}. In order to map the values back
into their original range, the following simple transformation needs to be
applied on the result:
Page | 37
H=
((G-B)/)/6
(2+ (B-R)/))/6
(4+ (R-G)/))/6
If R = Cmax
If G = Cmax
If B = Cmax
S = /Cmax
V = Cmax
The HSV to R'G'B' conversion is defined by the following equations:
H, S, and V vary from 0 to 1, where 1 represents the greatest saturation and
value.
Page | 39
--Chapter: 9--
Library
Computer Vision -> Sources
Computer Vision -> Sources
Simulink -> Math operations
DSP System Toolbox -> Sinks
DSP System Toolbox ->
Statistics
Computer Vision -> Analysis
& Enhancements
Computer Vision ->
Conversions
Quantity
1
2
2
2
6
1
2
Page | 40
Page | 41
Page | 42
Page | 43
Understanding the simulation:The COLOUR SPACE CONVERSION block with RGB to HSV parameter
converts the RGB colour space to HSV colour space. The VISUAL channel which
contains the GRAY levels of the image is then equalized by the HISTORAM
EQUALIZATION block. Then the COLOUR SPACE CONVERSION block with HSV to
RGB parameter then converts the HSV colour space back into RGB colour space.
Page | 44
-- Chapter: 9--
CONCLUSION
We can now conclude that Simulink is indeed an innovative and
exceptional tool to understand, design, analyse, and simulate a hardware or
application before actually physically creating it. Having a virtual laboratory that
can be used as if it has physical existence is not only cost effective but also time
saving. With the option of testing via running the simulation as if it were an
actual application or hardware, it provides us with valuable information
regarding the model at hand allowing us to freely change any parameter or add
or remove any block necessary for the error free functionality of the model.
Page | 45
REFERENCES
1. MATLAB and its application in Engineering
Raj Kumar Bansal
Ashok Kumar Goel
Manoj Kumar Sharma
2. MATLAB Demystified
K K Sharma
MATHWORKS
Rafael C Gonzalez
Richard E Woods
5. Introduction to Simulink
6. Image Histograms
Scientic Volume
Imaging B.V
7. http://www.colourtherapyhealing.com
8. http://www.designersinsights.com
9. http://hidefcolour.com
10. http://wikipedia.prg/Histogram
11. http://homepages.inf.ed.ac.uk
12. http://infohost.nmt.edu
13. http://rapidtables.com
Page | 46