- Software Algorithms -

by

Harvey
Twyman
About Me Email Me

" I find that everytime I want to write this word I
have to look up the spelling first. Therefore for the
benefit of Search Engines my common variations are:

Algorhythm, Algarithm, Algarhythm,
Aglorithms, Algarithm and Algolrythm

However they're all wrong as the actual spelling is
A-L-G-O-R-I-T-H-M"


    Question:

    What exactly are Algorithms?


    Reply:

    An "Algorithm" is a set of rules applied to solve a specific application. They only define the broad outline of operation and are usually expressed as "Mathematical Formulas".

    Specific code is not included so that the principles can be applied to any type of computer system.


Some Useful Algorithms:

Most of the algorithms described below are related to "Emulating" the effects of "Op-Amp" devices:

  • Normalisation
    • used for removing "DC Offsets" from data sampled from various sensors

  • Maximisation
    • used for digitally "Amplifying" or "Attenuating" a sampled waveform

  • Inverting Data
    • used for "Re-Inverting" data from sensors which have been connected to "Inverting Op-Amp" circuits
    • also used for "Reversing" the sense of data from potentiometers or controls from "Clockwise" to "Anti-clockwise"

  • Toggling Variables
    • used for Alternating the state of a variable
    • uses include "Flashing" indicators like LEDs

But first a few comments:

Changing Data Dynamics:

Changing the "Dynamics" of signals by either "Amplification" or "Attenuation" can be achieved by using the "Normalisation" and "Maximisation" algorithms described below.

The traditional methods of amplifying or attenuating signals is by the use of external electronic circuits involving "Op-Amp" devices. However here we're only using "Software" to modify the dynamic range of the data.

Before continuing a note of CAUTION:

Digitised data has a fixed number of "Quantisation Levels". e.g. A 12 Bit Analogue-to-Digital Converter (ADC) will take an analogue input voltage and convert it into 2^12 or 4096 levels or steps. These series of levels or steps "Roughly" resemble the original analogue voltage. The larger the number of bits that the ADC possesses will improve the representation of the original data.

The techniques mentioned below are purely software methods to increase or decrease the range of these voltages. The number of levels that the amplified signal contains will be reduced by the same amount of the "Gain" applied to the signal.

Therefore the final data will have "Less" levels or steps within it thus affecting the data's "Resolution" and "Accuracy".

The formulaes described below are used to calculate each new data element of the waveform at a time and will be incorporated into a "Loop" within the software to process all the waveform's data.


The algorithms described rely on a set of "Signal Names" which are defined below in the diagram:



Normalisation

Normalisation is equivalent to using the "DC Offset" pin on an "Op-Amp". However this digital method using software effectively does the same with the data sampled from an "A-D Converter".

Normalisation is required as part of the "Gain" or "Maximisation" algorithms described below but could be used independantly.

The "Original Signal Amplitude" waveform shown above in the diagram is "Shifted" so that the "Minimum" value becomes "Zero" or "NEWMIN".

This is achieved by "Subtracting" the "OLDMIN" value from all the "Original Signal" values thus:

NEWDATA = OLDDATA - OLDMIN

This effectively "Shifts" the complete waveform data so that the "Minimum Data Value" will be "Zero" thus eliminating any "DC Offsets" from the "Original Signal".


Maximisation

Maximisation is equivalent to using an "Op-Amp" to "Amplify" the signal by using software on the data sampled from the "A-D Converter".

N.B. THIS ALGORITHM WILL ONLY WORK IF
THE DATA HAS BEEN PROCESSED BY THE "NORMALISATION" ALGORITHM FIRST!

To calculate the "Gain" required to "Amplify" the signal to the new levels is show in the following formula:

GAIN =
( NEWMAX - NEWMIN ) / ( OLDMAX - OLDMIN )

The "New Amplified" data values are then created using the "Gain" calculated above "Multiplied" by the original data thus:

NEWDATA = OLDDATA * GAIN

However if "Attenuation" is required instead of "Gain" then the "Gain Value" calculated above will be the "Divisor" in the formula below:

NEWDATA = OLDDATA / GAIN


Inverting Data

This algorithm is equivalent to using an "Inverting Op-Amp" in "Unity Gain". The data range must be between the "Original Data Values" of OLDMAX and OLDMIN.

Algorithm: NEWDATA = OLDMAX - OLDDATA


Toggling Variables

    Toggling a variable in software is useful for "Alternating" between 2 parts of a program. Here it is used to control a "Flashing LED".

Initial State: C = 0

Algorithm: C = 1 - C

After Algorithm: C = 1

Every repeat of the algorithm "Alternates" the value of "C" between "0" and "1". The state of "0" represents "False" and "1" represents "True" when used in "Conditional Statements" in software.

Thus the "True" could be used to "Turn On" an LED and the "False" used to turn it "Off" again.