Professional Documents
Culture Documents
Certificate: Vaibhav Gaur, Students of Semester 4
Certificate: Vaibhav Gaur, Students of Semester 4
Deepali Sharma
(Project Incharge)
ACKNOWLEDGEMENT
The project work on “FUZZYLOGIC” was carried out at NSIT , under guidance
of Ms. Deepali Sharma. We gratefully acknowledge the guidance of our project
incharge for the successful completion of the project. The support of Head of
Department, Director/Principal, faculty and the laboratory staff in execution of
project is gratefully acknowledged.
Vaibhav Chhabra(521/IC/09)
Umesh Kumar(520/IC/09)
Vaibhav Gaur(522/IC/09)
MODULE – 1
Introduction to MATLAB
Etymology: MATLAB stands for Matrix Laboratory. The reason behind this is that internally,
every computation done by this application is in the form of number matrices of n-dimensions.
Hence, the name.
As it has already been touched in the Preface section, MATLAB is an engineering utility
application which allows us to compute many kinds of problems of different fields of science
and technology. This is a virtual environment which allows us to do numerical computations in a
simplified manner. Developed by Mathworks, this allows matrix manipulations, function
plotting, algorithm implementations and creation of Graphical User Interfaces. This designed for
live interaction with other computer language programs like C++ and FORTRAN.
MATLAB can call functions and subroutines written in the C programming language or Fortran.
A wrapper function is created allowing MATLAB data types to be passed and returned. The
dynamically loadable object files created by compiling such functions are termed "MEX-files"
(for MATLAB executable).
MATLAB is a "Matrix Laboratory", and as such it provides many convenient ways for creating
vectors, matrices, and multi-dimensional arrays. In the MATLAB vernacular, a vector refers to a
one dimensional (1×N or N×1) matrix, commonly referred to as an array in other programming
languages. A matrix generally refers to a 2-dimensional array, i.e. an m×n array where m and n
are greater than or equal to 1. Arrays with more than two dimensions are referred to as
multidimensional arrays. We can define vectors and matrices using square bracket, space and
semicolon in MATLAB.
Utilities
MATAB as an application is so extremely useful, that it can be used to do almost anything.
Starting from solving of nth order set of equations, it can be used in aeronautics, predicting
market statistics and economic situations, in wavelet transformations, as well as genetic
mapping. This application nowadays is being used in every research based industry to its benefit.
In 2004, MATLAB had around one million users across industry and academia.
History
MATLAB was created in the late 1970s by Cleve Moler, the chairman of the
computer department at the University of New Mexico. He designed it to give his students access
to LINPACK and EISPACK without having to learn Fortran. It soon spread to other universities
and found a strong audience within the applied mathematics community. Jack Little, an engineer,
was exposed to it during a visit Moler made to Stanford University in 1983. Recognizing its
commercial potential, he joined with Moler and Steve Bangert. They rewrote MATLAB in C and
founded MathWorks in 1984 to continue its development. These rewritten libraries were known
as JACKPAC. In 2000, MATLAB was rewritten to use a newer set of libraries for matrix
manipulation, LAPACK. MATLAB was first adopted by control design engineers, Little's
specialty, but quickly spread to many other domains. It is now also used in education, in
particular the teaching of linear algebra and numerical analysis, and is popular amongst scientists
involved with image processing.
Toolboxes
A MATLAB user is always empowered with strikingly efficient and diverse set of user-friendly
toolboxes which make the job of the programmer very simple by interacting graphically and
producing vivid diagrammatic results. These toolboxes may be used together to solve complex
problems.
The toolboxes available in the version used through this training are:
1. Aerospace Toolbox
The Aerospace Toolbox product extends the MATLAB ® technical computing
environment by providing reference standards, environment models, and aerodynamic
coefficient importing for performing advanced aerospace analysis to develop and
evaluate your designs. The toolbox provides the following to enable you to visualize
flight data in a three-dimensional environment and reconstruct behavioral anomalies in
flight-test results:
Aero.Animation, Aero.Body, Aero.Camera, and Aero.Geometry objects and associated
methods
An interface to the FlightGear flight simulator
An interface to the Simulink® 3D Animation™ software
2. Bioinformatics Toolbox
The Bioinformatics Toolbox™ product extends the MATLAB® environment to provide
an integrated software environment for genome and proteome analysis. Scientists and
engineers can answer questions, solve problems, prototype new algorithms, and build
applications for drug discovery and design, genetic engineering, and biological research.
An introduction to these features will help you to develop a conceptual model for
working with the toolbox and your biological data.
Toolbox features and functions fall within these categories:
Data formats and databases — Connect to Web-accessible databases containing
genomic and proteomic data. Read and convert between multiple data formats.
Sequence analysis — Determine the statistical characteristics of a sequence, align
two sequences, and multiply align several sequences. Model patterns in biological
sequences using hidden Markov model (HMM) profiles.
Phylogenetic analysis — Create and manipulate phylogenetic tree data.
Microarray data analysis — Read, normalize, and visualize microarray data.
Mass spectrometry data analysis — Analyze and enhance raw mass spectrometry
data.
Statistical learning — Classify and identify features in data sets with statistical
learning tools.
Programming interface — Use other bioinformatic software (BioPerl and
BioJava) within the MATLAB environment.
3. Communications Toolbox
Communications Toolbox software extends the MATLAB technical computing
environment with functions, plots, and a graphical user interface for exploring, designing,
analyzing, and simulating algorithms for the physical layer of communication systems.
The toolbox helps you create algorithms for commercial and defense wireless or wireline
systems.
The key features of the toolbox are:
Functions for designing the physical layer of communications links, including source
coding, channel coding, interleaving, modulation, channel models, and equalization
Plots such as eye diagrams and constellations for visualizing communications signals
Graphical user interface for comparing the bit error rate of your system with a wide
variety of proven analytical results
Galois field data type for building communications algorithms
7. Database Toolbox
The Database Toolbox™ software is one of an extensive collection of toolboxes for use
with the MATLAB® product. This toolbox enables you to use MATLAB functions to
import and export data between the MATLAB workspace and relational databases. With
the Database Toolbox software, you can bring data from a database into the MATLAB
workspace, and then use MATLAB computational and analytic tools to work with the
data, You can then store the results back in the database or in another database.
8. Datafeed Toolbox
This toolbox, used with the MATLAB ® product, effectively turns your MATLAB
workstation into a financial data acquisition terminal. The toolbox enables you to:
Retrieve and analyze a wide variety of security data from financial data servers in
MATLAB.
Access market, time-series, and historical market data in MATLAB.
Monitor the status and history of each connection to a supported data service provider.
Fetch data fields for multiple securities in a single call.
Look up security ticker symbols from the toolbox GUI or the MATLAB command line.
9. Econometric Toolbox
The Econometrics Toolbox™ software, combined with MATLAB ®, Optimization
Toolbox™, and Statistics Toolbox™ software, provides an integrated computing
environment for modeling and analyzing economic and social systems. It enables
economists, quantitative analysts, and social scientists to perform rigorous modeling,
simulation, calibration, identification, and forecasting with a variety of standard
econometrics tools.
Specific functionality includes:
Univariate ARMAX/GARCH composite models with several GARCH variants
(ARCH/GARCH, EGARCH, and GJR)
Dickey-Fuller and Phillips-Perron unit root tests
Multivariate VARX model estimation, simulation, and forecasting
Multivariate VARMAX model simulation and forecasting
Monte Carlo simulation of many common stochastic differential equations (SDEs),
including arithmetic and geometric Brownian motion, Constant Elasticity of Variance
(CEV), Cox-Ingersoll-Ross (CIR), Hull-White, Vasicek, and Heston stochastic volatility
Monte Carlo simulation support for virtually any linear or nonlinear SDE
Hodrick-Prescott filter
Statistical tests such as likelihood ratio, Engle's ARCH, Ljung-Box Q
Diagnostic tools such as Akaike information criterion (AIC), Bayesian information
criterion (BIC), and partial/auto/cross correlation functions
MODULE 1 PROGRAMS:
INPUT:-
%operations on matrices
m1=[2 3 1;4 6 2;8 7 9]
m2=[5 3 2;4 3 7;8 1 5]
sum=m1+m2
product = m1*m2
inverse=m2^-1
e=eig(m1)
%plotting of graphs
theta=linspace(0,2*pi,10)
x=sin(theta)
y=cos(theta)
z=1:5
w=3*z-2
plot(x,y,z,w,'o')
axis('equal')
xlabel('sin(theta)')
ylabel('cos(theta)')
OUTPUT:-
m1 =
2 3 1
4 6 2
8 7 9
m2 =
5 3 2
4 3 7
8 1 5
sum =
7 6 3
8 9 9
16 8 14
product =
30 16 30
60 32 60
140 54 110
inverse =
e =
13.2170
-0.0000
3.7830
theta =
Columns 1 through 5
Columns 6 through 10
3.4907 4.1888 4.8869 5.5851 6.2832
x =
Columns 1 through 5
Columns 6 through 10
y =
Columns 1 through 5
Columns 6 through 10
z =
1 2 3 4 5
w =
1 4 7 10 13
INPUT:-
%Define a transfer fn and plot its pole-zero map
%file written by varun kumar kadian.
load numdemo Pd Cd
pzplot(Pd,'b',Cd,'r')
OUTPUT:-
MODULE 2
INTRODUCTION TO FUZZY LOGIC:
In recent years, the number and variety of applications of fuzzy logic have increased
significantly. The applications range from consumer products such as cameras, camcorders,
washing machines, and microwave ovens to industrial process control, medical instrumentation,
decision-support systems, and portfolio selection.
Fuzzy logic has two different meanings. In a narrow sense, fuzzy logic is a logical system, which
is an extension of multivalued logic. However, in a wider sense fuzzy logic (FL) is almost
synonymous with the theory of fuzzy sets, a theory which relates to classes of objects with
unsharp boundaries in which membership is a matter of degree. In this perspective, fuzzy logic in
its narrow sense is a branch of FL. Even in its more narrow definition, fuzzy logic differs both in
concept and substance from traditional multivalued logical systems.
In Fuzzy Logic Toolbox software, fuzzy logic should be interpreted as FL, that is, fuzzy logic in
its wide sense. What might be added is that the basic concept underlying FL is that of a linguistic
variable, that is, a variable whose values are words rather than numbers. In effect, much of FL
may be viewed as a methodology for computing with words rather than numbers. Although
words are inherently less precise than numbers, their use is closer to human intuition.
Furthermore, computing with words exploits the tolerance for imprecision and thereby lowers
the cost of solution.
A trend that is growing in visibility relates to the use of fuzzy logic in combination with
neurocomputing and genetic algorithms. More generally, fuzzy logic, neurocomputing, and
genetic algorithms may be viewed as the principal constituents of what might be called soft
computing. Unlike the traditional, hard computing, soft computing accommodates the
imprecision of the real world. The guiding principle of soft computing is: Exploit the tolerance
for imprecision, uncertainty, and partial truth to achieve tractability, robustness, and low solution
cost. In the future, soft computing could play an increasingly important role in the conception
and design of systems whose MIQ (Machine IQ) is much higher than that of systems designed by
conventional methods.
Fuzzy logic is all about the relative importance of precision: How important is it to be exactly
right when a rough answer will do?
The first category of tools is made up of functions that we can call from the command line or
from our own applications. Many of these functions are MATLAB M-files, series of MATLAB
statements that implement specialized fuzzy logic algorithms. We can view the MATLAB code
for these functions using the statement
type function_name
We can change the way any toolbox function works by copying and renaming the M-file, then
modifying our copy. We can also extend the toolbox by adding our own M-files.
Secondly, the toolbox provides a number of interactive tools that let us access many of the
functions through a GUI. Together, the GUI-based tools provide an environment for fuzzy
inference system design, analysis, and implementation.
The third category of tools is a set of blocks for use with Simulink. These are specifically
designed for high speed fuzzy logic inference in the Simulink environment.
What makes the toolbox so powerful is the fact that most of human reasoning and concept
formation is linked to the use of fuzzy rules. By providing a systematic framework for computing
with fuzzy rules, the toolbox greatly amplifies the power of human reasoning. Further
amplification results from the use of MATLAB and graphical user interfaces, areas in which The
MathWorks™ has unparalleled expertise.
Another basic concept in FL, which plays a central role in most of its applications, is that of a
fuzzy if-then rule or, simply, fuzzy rule. Although rule-based systems have a long history of use
in Artificial Intelligence (AI), what is missing in such systems is a mechanism for dealing with
fuzzy consequents and fuzzy antecedents. In fuzzy logic, this mechanism is provided by the
calculus of fuzzy rules.
Why Use Fuzzy Logic?
The mathematical concepts behind fuzzy reasoning are very simple. Fuzzy logic is a
more intuitive approach without the far-reaching complexity.
With any given system, it is easy to layer on more functionality without starting again
from scratch.
Everything is imprecise if you look closely enough, but more than that, most things are
imprecise even on careful inspection. Fuzzy reasoning builds this understanding into the
process rather than tacking it onto the end.
You can create a fuzzy system to match any set of input-output data. This process is
made particularly easy by adaptive techniques like Adaptive Neuro-Fuzzy Inference
Systems (ANFIS), which are available in Fuzzy Logic Toolbox software.
In direct contrast to neural networks, which take training data and generate opaque,
impenetrable models, fuzzy logic lets you rely on the experience of people who already
understand your system.
Fuzzy systems don't necessarily replace conventional control methods. In many cases
fuzzy systems augment them and simplify their implementation.
The basis for fuzzy logic is the basis for human communication. This observation
underpins many of the other statements about fuzzy logic. Because fuzzy logic is built on
the structures of qualitative description used in everyday language, fuzzy logic is easy to
use.
The last statement is perhaps the most important one and deserves more discussion. Natural
language, which is used by ordinary people on a daily basis, has been shaped by thousands of
years of human history to be convenient and efficient. Sentences written in ordinary language
represent a triumph of efficient communication.
Fuzzy logic is not a cure-all. When should you not use fuzzy logic? The safest statement is the
first one made in this introduction: fuzzy logic is a convenient way to map an input space to an
output space. If you find it's not convenient, try something else. If a simpler solution already
exists, use it. Fuzzy logic is the codification of common sense — use common sense when you
implement it and you will probably make the right decision. Many controllers, for example, do a
fine job without using fuzzy logic. However, if you take the time to become familiar with fuzzy
logic, you'll see it can be a very powerful tool for dealing quickly and efficiently with
imprecision and nonlinearity.
Membership Functions
dsigmf Built-in membership function composed of difference between two
sigmoidal membership functions
genfis1 Generate Fuzzy Inference System structure from data using grid
partition
genfis2 Generate Fuzzy Inference System structure from data using subtractive
clustering
genfis3 Generate Fuzzy Inference System structure from data using FCM
clustering
Simulink Environment
fuzblock Simulink fuzzy logic library
INPUT:
a=newfis('washruntime');
a.input(1).name='dirtnessofclothes';
a.input(1).range=[0 100];
a.input(1).mf(1).name='small';
a.input(1).mf(1).type='trimf';
a.input(1).mf(1).params=[-50 0 50];
a.input(1).mf(2).name='medium';
a.input(1).mf(2).type='trimf';
a.input(1).mf(2).params=[0 50 100];
a.input(1).mf(3).name='large';
a.input(1).mf(3).type='trimf';
a.input(1).mf(3).params=[50 100 150];
a.input(2).name='typeofdirt';
a.input(2).range=[0 100];
a.input(2).mf(1).name='notgreasy';
a.input(2).mf(1).type='trimf';
a.input(2).mf(1).params=[-50 0 50];
a.input(2).mf(2).name='medium';
a.input(2).mf(2).type='trimf';
a.input(2).mf(2).params=[0 50 100];
a.input(2).mf(3).name='greasy';
a.input(2).mf(3).type='trimf';
a.input(2).mf(3).params=[50 100 150];
a.output(1).name='runtime';
a.output(1).range=[0 60];
a.output(1).mf(1).name='veryshort';
a.output(1).mf(1).type='trimf';
a.output(1).mf(1).params=[0 10 15];
a.output(1).mf(2).name='short';
a.output(1).mf(2).type='trimf';
a.output(1).mf(2).params=[10 15 23];
a.output(1).mf(3).name='medium';
a.output(1).mf(3).type='trimf';
a.output(1).mf(3).params=[15 23 40];
a.output(1).mf(4).name='long';
a.output(1).mf(4).type='trimf';
a.output(1).mf(4).params=[23 40 60];
a.output(1).mf(5).name='verylong';
a.output(1).mf(5).type='trimf';
a.output(1).mf(5).params=[40 60 75];
a.rule(1).antecedent=[3 3];
a.rule(1).consequent=[5];
a.rule(1).weight=1;
a.rule(1).connection=1;
a.rule(2).antecedent=[2 3];
a.rule(2).consequent=[4];
a.rule(2).weight=1;
a.rule(2).connection=1;
a.rule(3).antecedent=[1 3];
a.rule(3).consequent=[4];
a.rule(3).weight=1;
a.rule(3).connection=1;
a.rule(4).antecedent=[3 2];
a.rule(4).consequent=[4];
a.rule(4).weight=1;
a.rule(4).connection=1;
a.rule(5).antecedent=[2 2];
a.rule(5).consequent=[3];
a.rule(5).weight=1;
a.rule(5).connection=1;
a.rule(6).antecedent=[1 2];
a.rule(6).consequent=[3];
a.rule(6).weight=1;
a.rule(6).connection=1;
a.rule(7).antecedent=[3 1];
a.rule(7).consequent=[3];
a.rule(7).weight=1;
a.rule(7).connection=1;
a.rule(8).antecedent=[2 1];
a.rule(8).consequent=[2];
a.rule(8).weight=1;
a.rule(8).connection=1;
a.rule(9).antecedent=[1 1];
a.rule(9).consequent=[1];
a.rule(9).weight=1;
a.rule(9).connection=1
output=evalfis([20 25],a)
OUTPUT:
a =
name: 'washruntime'
type: 'mamdani'
andMethod: 'min'
orMethod: 'max'
defuzzMethod: 'centroid'
impMethod: 'min'
aggMethod: 'max'
input: [1x2 struct]
output: [1x1 struct]
rule: [1x9 struct]
output =
19.3154
[System]
Name='washruntime'
Type='mamdani'
Version=2.0
NumInputs=2
NumOutputs=1
NumRules=9
AndMethod='min'
OrMethod='max'
ImpMethod='min'
AggMethod='max'
DefuzzMethod='centroid'
[Input1]
Name='dirtnessofclothes'
Range=[0 100]
NumMFs=3
MF1='small':'trimf',[-50 0 50]
MF2='medium':'trimf',[0 50 100]
MF3='large':'trimf',[50 100 150]
[Input2]
Name='typeofdirt'
Range=[0 100]
NumMFs=3
MF1='notgreasy':'trimf',[-50 0 50]
MF2='medium':'trimf',[0 50 100]
MF3='greasy':'trimf',[50 100 150]
[Output1]
Name='runtime'
Range=[0 60]
NumMFs=5
MF1='veryshort':'trimf',[0 10 15]
MF2='short':'trimf',[10 15 23]
MF3='medium':'trimf',[15 23 40]
MF4='long':'trimf',[23 40 60]
MF5='verylong':'trimf',[40 60 75]
[Rules]
3 3, 5 (1) : 1
2 3, 4 (1) : 1
1 3, 4 (1) : 1
3 2, 4 (1) : 1
2 2, 3 (1) : 1
1 2, 3 (1) : 1
3 1, 3 (1) : 1
2 1, 2 (1) : 1
1 1, 1 (1) : 1
INPUT:
a=newfis('speed_control');
a.input(1).name='motorspeed';
a.input(1).range=[2280 2520 ];
a.input(1).mf(1).name='tooslow';
a.input(1).mf(1).type='trimf';
a.input(1).mf(1).params=[2280 2340 2400];
a.input(1).mf(2).name='jstrght';
a.input(1).mf(2).type='trimf';
a.input(1).mf(2).params=[2360 2400 2440];
a.input(1).mf(3).name='toofst';
a.input(1).mf(3).type='trimf';
a.input(1).mf(3).params=[2400 2460 2520];
a.output(1).name='voltage';
a.output(1).range=[2.32 2.48];
a.output(1).mf(1).name='slowdown'
a.output(1).mf(1).type='trimf';
a.output(1).mf(1).params=[2.32 2.36 2.40];
a.output(1).mf(2).name='nochange';
a.output(1).mf(2).type='trimf';
a.output(1).mf(2).params=[2.38 2.40 2.42];
a.output(1).mf(3).name='speedup';
a.output(1).mf(3).type='trimf';
a.output(1).mf(3).params=[2.40 2.44 2.48];
a.rule(1).antecedent=[1 ];
a.rule(1).consequent=[3];
a.rule(1).weight=1;
a.rule(1).connection=1;
a.rule(2).antecedent=[2];
a.rule(2).consequent=[2];
a.rule(2).weight=1;
a.rule(2).connection=1;
a.rule(3).antecedent=[3];
a.rule(3).consequent=[1];
a.rule(3).weight=1;
a.rule(3).connection=1
output=evalfis([2500],a)
OUTPUT:
a =
name: 'speed_control'
type: 'mamdani'
andMethod: 'min'
orMethod: 'max'
defuzzMethod: 'centroid'
impMethod: 'min'
aggMethod: 'max'
input: [1x1 struct]
output: [1x1 struct]
rule: [1x3 struct]
output =
2.3600
[System]
Name='speed_control'
Type='mamdani'
Version=2.0
NumInputs=1
NumOutputs=1
NumRules=3
AndMethod='min'
OrMethod='max'
ImpMethod='min'
AggMethod='max'
DefuzzMethod='centroid'
[Input1]
Name='motorspeed'
Range=[2280 2520]
NumMFs=3
MF1='tooslow':'trimf',[2280 2340 2400]
MF2='jstrght':'trimf',[2360 2400 2440]
MF3='toofst':'trimf',[2400 2460 2520]
[Output1]
Name='voltage'
Range=[2.32 2.48]
NumMFs=3
MF1='slowdown':'trimf',[2.32 2.36 2.4]
MF2='nochange':'trimf',[2.38 2.4 2.42]
MF3='speedup':'trimf',[2.4 2.44 2.48]
[Rules]
1, 3 (1) : 1
2, 2 (1) : 1
3, 1 (1) : 1
1.http://www.mathworks.com/
2.A few matlab books written by Rudra
Pratap,Otto and Denier.
3.Matlab toolbox for fuzzylogic and matlab
help.
4.www.google.co.in