Science Through Thoughts

Why does this magnificient applied science which saves work and makes life easier bring us so little happiness? The simple answer runs: Because we have not yet learned to make sensible use of it.-Albert Einstein-in a speech at the California Institute of Technology, Pasadena, 1931

Saturday, July 18, 2009

MATLAB and forest fire

MATLAB is a numerical computing environment and fourth generation programming language. Developed by The MathWorks, MATLAB allows matrix manipulation, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages. Although it is numeric only, an optional toolbox uses the MuPAD symbolic engine, allowing access to computer algebra capabilities. An additional package, Simulink, adds graphical multidomain simulation and Model-Based Design for dynamic and embedded systems.

The forest fire problem that I’m going to discuss can be categorized under the class cellular automata. In this category a discrete space, discrete time, discrete values and a simple set of rules are used for update time. Forest fire is a simulation which at the end gathers information, what fraction of a forest burns on a fire depending on the density of the trees. If each point on the forest contains a tree at the beginning of the simulation the whole forest would be burnt up and if trees are separated by a significant distance only a portion of the forest would be burnt.

The forest is modeled using a grid where each grid point is one of the four sites: no tree, living tree, burning tree or a burnt tree. The next state of a particular grid point is determined by the current state of its neighbors. There are two most important definitions of “neighbor” in working with grids.


The next state of a particular grid point is determined by the following set of rules.

  • If a site has a living tree and a neighbor is burning, at the next state the current site will be a burning tree.
  • If a site has a living tree and a no neighbor is burning, at the next state the current site remains same.
  • If a site has a burning tree, at the next state the current site will be a burnt tree.
  • In any other case the site remains same as the current state.

To start building the project first a model forest was created. In this particular case a forest with square dimensions were created with N*N dimensions and each site with probability ‘p’ containing a living tree. MATLAB functions were used to visualize the forest with colors. In this particular case forest was initialized in such a way that three edges of the forest was complete treeless and the fourth edge with trees in each grid point.

  • White – no tree
  • Green – living tree
  • Red – burning tree
  • Black – burnt tree

Von Neumann neighborhood was assumed to update the forest and the simulation was driven until the fire stops. At the end of the simulation set of reading were taken in order to plot some graphs.

Graphs plotted using the data from the simulations

Graph 1 -
Fraction of trees burnt with respect to the probability of a site having a tree (200*200 grid)
Graph 2 -
number of iterations it took to completely burnout the forest with respect to the probability of a site having a tree (200*200 grid)
Graph 3 -
Fraction of trees burnt with respect to the probability of a site having a tree (500*500 grid)
Graph 4 -
number of iterations it took to completely burnout the forest with respect to the probability of a site having a tree (500*500 grid)


Video of the simulation

PIC programming and simulations using Proteus

The Proteus Design Suite is wholly unique in offering the ability to co-simulate both high and low-level micro-controller code in the context of a mixed-mode SPICE ( (Simulation Program with Integrated Circuit Emphasis) is a general purpose an

alog electronic circuit simulator. It is a powerful program that is used in IC and board-level design to check the integrity of circuit designs and to predict circuit behavior.) circuit simulation. With this Virtual System Modeling facility, it is possible to

transform the product design cycle, reaping huge rewards in terms of reduced time to market and lower costs of development. In short, Proteus VSM improves efficiency, quality and flexibility throughout the design process.

Proteus Virtual System Modeling (VSM) combines mixed mode SPICE circuit simulation, animated components and microprocessor models to facilitate co-simulation of complete microcontroller based designs. For the first time ever, it is possible to develop and test such designs before a physical prototype is constructed.

This is possible because it is possible to interact with the design using on screen indicators such as LED and LCD displays and actuators such as switches and buttons. The simulation takes place in real time (or near enough to it): a 1GMHz Pentium III can simulate a basic 8051 system clocking at over 12MHz. Proteus VSM also provides extensive debugging facilities including breakpoints, single stepping and variable display for both assembly code and high level language source.

Proteus VSM includes a number of virtual instruments including an Oscilloscope, Logic Analyser, Function Generator, Pattern Generator, Counter Timer and Virtual Terminal as well as simple voltmeters and ammeters

The most exciting and important feature of Proteus VSM is its ability to simulate the interaction between software running on a microcontroller and any analog or digital electronics connected to it.

The micro-controller model sits on the schematic along with the other elements of your product design. It simulates the execution of your object code (machine code), just like a real chip. If the program code writes to a port, the logic levels in circuit change accordingly, and if the circuit changes the state of the processor's pins, this will be seen by your program code, just as in real life.

The VSM CPU models fully simulate I/O ports, interrupts, timers, USARTs(Universal asynchronous receiver/transmitter) and all other peripherals present on each supported processor. It is anything but a simple software simulator since the interaction of all these peripherals with the external circuit is fully modeled down to waveform level and the entire system is therefore simulated.

VSM can even simulate designs containing multiple CPUs, since it is a simple enough matter to place two or more processors on a schematic and wire them together.

Proteus is equipped with comprehensive diagnostic or trace messaging. This allows you to specify which components or processor peripherals that are of interest at any given time and receive detailed textual reporting of all activity and system interaction. This is invaluable as a debugging aid, allowing you to locate and fix problems in both software and hardware much faster than you could when working on a physical prototype.

In addition to the microprocessor models for each supported family, and literally thousands of 'standard' models for passives, TTL/CMOS, memories, etc. Proteus VSM is equipped with a comprehensive library of embedded peripheral models, from alphanumeric and graphical LCD displays, through DC, BLCD and servo motors to Ethernet controller chips.


PIC16F877A is a small piece of semiconductor integrated circuits. The package type of these integrated circuits is DIP package. DIP stand for Dual Inline Package for semiconductor IC. This package is very easy to be soldered onto the strip board. However using a DIP socket is much more easier so that this chip can be plugged and removed from the development board.


PIC16F877A is very popular because PIC16F877A is very cheap. Apart from that it is also very easy to be assembled.Additional components that needed to make this IC work are just a 5V power supply adapter, a 20MHz crystal oscillator and 2 units of 22pF capacitors.


This IC can be reprogrammed and erased up to 10,000 times. Therefore it is very good for new product development phase.