Embedeo - embedded systems and microcontroller projects

Main menu
  1. Home
  2. Resources
  3. About Us

Resources
  1. Technical Articles
  2. Vendors and Suppliers
  3. Development Tools
  4. Startup Projects

Bisection Method in Embedded Systems

Abstract

This article explains how to apply a bisection method in embedded systems, in order to avoid division of integer numbers. There are also mentioned: precision vs. speed tradeoff, and splitting of a nonlinear function into linear subranges. Included sample program in C, simulates calculation process and analysis of the maximum error.

by Nedko Iliev, posted:2006.08.07

We take into consideration some non-linear function y=f(x) in a given argument range (a0,a4). The goal of the target program, running on a microcontroller is calculation of y with predictable accuracy. First we split the entire argument range into several subranges [ai,ai+1], then we replace each part of the real function by a line g(x), so f(ai)=g(ai)=bi and f(ai+1)=g(ai+1)=bi+1 as it is shown on Fig.1

sample curve of a function
Fig.1

The linear function g(x) is expressed by the following equations:

or

The function is solvable but it involves some division. Additionally the replacement of f(x) by g(x) already involves an error. We can go further by this approach in order to avoid arbitrary division. At next example we'll seek y=f(xc) but we'll not solve g(x) -equations directly.

part of the curve
Fig.2

We split the subrange along each axis in two equal parts, defining new subranges that are twice smaller. Thus for [ai,ai+1] and [bi,bi+1] we obtain their middle points x1=((ai+ai+1)/2) and y1=((bi+bi+1)/2), accordingly. Then we compare the given value xc with the middle of the initial subrange x1. If (x1>xc) then we assume for the next step new subrange [ai;x1] for x-axis, and [bi;y1] for y-axis, otherwise we shall assume the other new subranges, i.e. [x1;ai+1] and [y1;bi+1]. We continue splitting and comparison process, until we obtain a middle point on the x-axis exactly equal to xc or reach certain limit of iterations (splitting and comparison). Of course the last obtained value for y-axis is the value we seek, and we should expect that it is not exact value of the function. Obviously we replace the arbitrary division by additions, comparisons and divisions by 2, and the last one is simply a shift-right operation for a microcontroller.

Download sample code

bisection.zip (5KB)
The zip file includes two files. The file bisection.c is a sample program in plain C for the command line. The program bisectionally finds solution for the sample function y=64*log(x/16), where log means natural logarithm (to base e). The argument x ranges from 32 to 1023. Scalling factors are includded for better resolution. The program also prints the maximum positive and negative errors for the given range of the argument. You can play with it, and observe various aspects of the bisection method. The other file lnsample.xls included in the zip-file, contains a spreadsheet with a graphical representation of the function. The file was created by OpenOffice.org Calc a spreadsheet program, which is part of the free, powerfull, multiplatform and open-source office suite OpenOffice.org

You can mail your questions or comments to:
This is intentionally picture

Copyright (C) 2005, 2006 embedeo.com - Tems of Use and Legal Disclaimer