Monday, 9 May 2011

Algorithms

An algorithm is a description of the steps required to complete a process.  Algorithms are often used by computers, but are in fact independent of them and programming languages.  In algorithms there are three types of activity known as the three 'constructs': the first being sequence (instructions in a certain order), the next being selection (deciding between values), and the last repetition until a criteria is met.  With all algorithms the inputs, outputs and variables are critical to know before an algorithm is created.
  Algorithms can be expressed in five ways.  The first of these is using structured English - therefore English with regular syntax, secondly Pseudo Code which is a way of expressing the steps that a computer program would take but is independent of all programming languages, thirdly as a flowchart using the steps in the previous two types, fourthly through using hand tracing in a table to show how the variables change as the algorithm is conducted, and lastly in a programming language so that the algorithm can be executed by a computer.  Flowcharts involve using decision boxes for selection, process boxes for sequence, and using these with arrows in the right way for repetition.

As an example here is an algorithm that finds the letter 'A' in a list of letters and indicates when it has been found.

Structured English

  • Input Text
  • Count equals 1
  • TextLength equals the  length of the string Text
  • Repeat until Count is greater than the number of characters in Text
  1. If the character at position Count in the string equals 'A', print 'Found it!'
  2. Else add 1.
  • If Count exceeds TextLength then print 'Character Not Found'


Pseudo Code

  • Count ← 1
  • Input Text
  • TextLength ← Text.length
  • For each character in Text
  1. If Character = 'A'  print 'Found it'
  2. Else Count = Count + 1
  • If Count > TextLength print 'Character Not Found'


Flowchart


Hand trace table
This trace table shows what happens to each value as it is used with the algorithm.

Input
Value
Character = A
Count
Text Length
Output
LA
L
No
1
2


A
Yes
2

Found it!

Tuesday, 29 March 2011

Encoding information using binary

In order for letters and other characters to be stored on computer systems this information must be encoded as binary codes.  This is because computers can only actually store 1s and 0s which relate to high and low voltages.  Agreed set of codes are used to represent all characters, the most important being standard 7-bit ASCII (American Standard Code for Information Interchange) which 128 possible combinations of 1s and 0s, in addition to Unicode which is 16-bit and as such has 2 to the power of 16 or 65536 combinations.
  When using ASCII the binary representations of actual digits (0-9) is different to how those numbers would actually be represented in binary if they were being operated upon or stored.  For example, the number 1 would usually be 0000001 in binary, but when being represented as a character it is 0110000 (48).
 Some forms of ASCII may have an extra digit used for an extended character set (256 characters), many of which are used for various symbols, mathematical operations and letters from other languages.  The extra digit (to make it 8-bit) is most often used for error checking however which is important for receiving text correctly.
  ASCII is a very limited character set even with 256 different characters, as it only contains letters from European languages including English and French which use the Latin alphabet originating from the Romans.  As such there is no way to represent letters from languages such as Arabic or those based upon the Cyrillic alphabet.  So these characters can be represented Unicode must be used.  It is 16-bit, and as a result this is sufficient for all characters from all languages, plus mathematical and other symbols.

There are two main types of error checking which are even bit checking, and odd bit checking.  These are used because just one incorrect binary digit per character can result in the characters in a passage of text changing and it not being understandable.  Both rely upon the use of the 8th bit.  In odd bit checking the number of 1s must always be odd, and as such if the 7-bit ASCII code has an even amount of 1s then the check bit will be a 1, making the number of 1s odd.  If the number of 1s is not odd when received it will be assumed that the data has been sent incorrectly, or has been interfered with and as such will be requested again.
  Even-bit checking is the opposite, as the number of 1s must be even and the check digit is used to achieve a similar outcome, and if the number of 1s is odd when received it will be considered incorrect.  Even bit checking is potentially flawed, as if two bits were flipped then the fact that it is incorrect would not necessarily be detected once the code was received.

Error checking refers to superior techniques that may be used in addition to or instead of error detection techniques.  The Majority Vote method is the most common of these, which is a process during which a code is sent three times, and the most common value for each bit is used.  Therefore if two out of three codes show a 1 in the 4th position, but the third code shows a 0 then it will be assumed that this has been corrupted, and that the correct digit is a 1.  This can be used to correct numerous errors, and its only flaws are that a large amount of data has to be sent, in addition to the fact that if a large amount of the codes sent were corrupted then it could receive an incorrect majority, although the chances of this happening are low.
  There are two other error correction methods known as Hamming code and Gray code.  Hamming code utilises positions of powers of 2 as parity bits, and the other integers as locations for data to be encoded.  Depending upon the position of the parity bit, different patterns of checking and skipping are used.  The checking method with position n can be summed up however with the checking pattern skip n - 1 bits, then in turn check n bits and skip n bits.  It has a number of sets of parity bits (often 4), and in each set there will be an odd number of binary digits initially, but an even parity will be used.  As such a check digit is included in the same manner as previously mentioned to make sure the number of 1s is always even.
  With Gray code every number in a specific range can be represented, and as such there are no 'in-between' values.  It is also considered to be more reliable than standard binary because there is less likely to be an error due to a slow response time.  Using Gray code only one digit is changed at a time, whilst when using binary multiple digits could.  Gray code counters also use less energy than their binary equivalents.  One of their key uses is for passing information between microchips that operate on different frequencies.
 

Wednesday, 23 March 2011

Binary Numbers, Binary Arithmetic and Hexadecimal

Computers store numbers in binary, long sequences of 0s and 1s which correspond to low and high voltages.  Each 0 or 1 is known as a Bit, and  8 bits make up a Byte.  If Bytes are grouped together they make up what are known as words.  Unlike denary which works in base 10 where each place is worth 10 times the one to the right, binary works in base 2 because each digit has twice the value of the one to the right.  As such the number 5 in denary would be 101 in binary, because it is (1x1) + (0x2) + (1x4).  If converting a binary number to denary one a similar method is used - so 33 is 100001 because it is (32x1) + (16x0) + (8x0) + (4x0) + (2x0) + (1x1).
  When adding binary numbers a method of 'carrying' digits is used if there is more than one '1' in a place.  As such if there are two 0s the place is 0, a 1 and a 0 would be 1, two 1s would result in a 1 being carried making 10 and three 1s would result in a 1 being carried and a 1 being kept making 11.  For example, if one were to add 1101 and 1010, then 10111 would be the result, as the two 1s in the 8 column would be carried, as 2 x 8 = 16, meaning the next column would contain a 1.  The next column would contain a 0, whilst the other three would contain 1s because there are two subsequent 1s in the first number, and one in the second number - all in different columns.
  Binary multiplication has similarities to denary multiplication, as it is done with respect to place value.  If multiplying only by a 1 in the furthest right column then the number does not change, or if there are more 1s it is added to the total.  On the other hand if a binary number is multiplied by a number with at least two places (therefore one with a value of at least 2) then the number of places after the 1 is added to the end of the binary number as 0s, meaning that it moves up places.  For example, 100 x 101 would be 10000 +100 = 10100.  This is because the 101 has merely moved up two places.
  Negative numbers can also be represented using binary through utilising Two's Complement.  To convert a positive binary number to a negative one the digits are simply inverted, and then 1 is added.  The denary number 7 is 0111 in binary, and this is flipped to become 1000, and then 1 is added to make it 1001.  This method of 'flipping' the bits is used so that computers are able to store negative numbers.  Also worth mentioning are most and least significant bits.  Positive numbers have 0 as the MSB, whilst it is 1 with negative numbers.  Odd numbers have 1 as the LSB, whilst it is 0 with even numbers.
  With this knowledge it is possible to subtract binary numbers.  This is most easily done by turning the number into a negative one and then adding it.  For example, 7 - 5 would become -5 + 7, or 1011 + 0111, with an answer of two in denary, or 0010 in binary.
  Hexadecimal refers to a base 16 number system, which is used for representing numbers shorthand.  Each digit/letter is has a value of 16 times what it would have one place to the right.  It is often favoured over binary because that will have long chains of 0s and 1s, whilst a number's hexadecimal equivalent will be much shorter.  The numbers 0-9 are used in hexadecimal for their respective values in binary, but then the letters A-F are used for the numbers 10 to 15 in denary, and '10' is used for 16 in denary.  An example of this would be the number 38.  If this number is divided by 16 one gets 2 remainder 6, so a 2 is placed in the column with a value of 16x the digit, and a 6 in the column with a value of 1x the digit- so 38 in denary is 26 in hexadecimal. Letters are only generally used for larger numbers - an example being 173.  This is (10 x 16) + 13, making the hexadecimal number AD.
  Lastly decimals may also be represented using binary, with use of a binary point.  Beyond the binary point are values of 2 to negative powers (or 1 over 2 to powers), each being half the value of the one to the left.  For example the number 5.25 would be 101.01 as 101 is 5 in binary, and .01 in binary is zero halves + one quarter.  Although processing is quick using this system, there is a limited range of fractions available.  As such it would be difficult if possible to represent a denary number like 134.62 in binary.

Tuesday, 1 March 2011

Finite State Machines

Finite State Machines refer to mechanise systems which may change between a pre-defined number of 'states', which refer to different situations, the most basic example being 'on' or 'off'.  These systems also contain inputs which cause a change between states, as well as possibly outputs.  If there are no outputs then the system will be known as a Finite State Automaton and have a 'goal' or 'accept' state.  They can be represented as state transition diagrams, as depicted below with arrows as transitions between states due to inputs.  In these diagrams there is an initial state denoted with a start arrow, and the accept state will be shown by a double circle.

Those Finite State Machines with outputs do have an initial state, but not an 'accept' state.  They are known as Mealy Machines.  A state transition diagram for a vending machine, an example of one, is shown below.

Transition tables can also be used for these systems and they differ depending upon whether the FSM has an output.  The first table is for the first FSM, whilst the second table is for the second FSM.


Input
Current State
Next State
Nothing
S0
S0
Incorrect Code
S0
S1
Nothing
S1
S0
Correct Code
S0
S2
Nothing
S2
S0



Input
Current State
Output
Next State
0p
S0
0
S0
50p
S0
0
S1
50p
S1
1
S2
£1
S0
1
S2
0p
S2
0
S1


Decision tables let one consider the possible combinations and what should happen as a result.
Example: if the week day is odd then output A, if it is even then output B


Conditions
                                               Specific Data
Mon/Wed/Fri/Sun
Y
N
Tues/Thurs/Sat
N
Y
Output A
Y
N
Output B
N
Y

Y = Yes, N = No

Psuedo code can also used to represent these problems as they would be using similar syntax to inside a computer program, but not in a programming language.  For the example shown above the pseudo code would be something like:

If Day = Odd, then Output A
Else Output B

Monday, 28 February 2011

System Development Life Cycle

A system life cycle refers to the stages used to successfully create a system which is exactly what is desired by a customer. This life cycle is used within computing, in software development for example, as well as outside of computing for large-scale projects. The life cycle makes it less likely for a project to fail or be undesirable.  It is used because of the consequences which could be the result of a system failure.  Below the phases of the system life cycle have been detailed.

Phase One: Analysis

  • Finding out the purpose of the project and final objectives, as such forming a requirements specification.
  • Research (e.g. use of surveys, reports and interviews etc.)
  • Any other information required in order to know exactly what is needed..

Phase Two: Design

  • How will the system be created?
  • Making sure that the system will meet its objectives before it is created.
  • Final specification and design

Phase Three: Implementation

  • Create the system
  • Establishing or setting-up the system
  • Preparing the system for use
  • Training people to use the system
  • Creating instructions so people can use the system

Phase Four: Testing

  • Test parts of the system and the system overall to make sure all elements function correctly individually, and that they function correctly together.
  • Make sure that those trained to do so can use the system.

Phase Five: Evaluation

  • Is it the right system for the problem?
  • Is it effective?
  • What can be improved next time?

After these phases:

  • Maintenance in the form of updating the system to fix problems and make changes so it suits the user's needs.
  • Second iteration of the cycle.

Tuesday, 8 February 2011

Types of Sound, Conversion, Storage and Transmission

Sound refers to a type of energy that causes particles to vibrate as it travels through a medium other than a vacuum (which contains no particles).  This can then be converted to its electrical counterpart - a signal, which can be the equivalent of many types of energy.  The aforementioned process is done using a transducer such as  a microphone, which converts from one type of energy to another.  When transmitted as energy the data is analogue, but requires conversion to digital data to be stored in memory on a computer.  Analogue data continuously changes between an infinite amount of values, whilst digital data is discrete and as such has only fixed values which it can vary between.
  In order to be converted to digital data the analogue sound is sampled at periodic intervals (twice every second for example), using a process called Pulse Amplitude Modulation.  Quality is lost however, because not of the data from the analogue sound has been retained, and the values (e.g. loudness) of the samples will have been rounded using a process called quantisation, and stored in binary.  These numbers represent Pulse Code Modulation, and each value is stored in sequence in a binary file.  When sampling two factors are considered - the sampling rate which refers to the number of times an audio track is sampled per second, and the sampling resolution, which is the number of binary digits allocated to the range of possible values for the discrete data.
  Frequency refers to the amount of complete waves per second, and is measured in Hz, kHz (thousands), and MHz (millions).  According to Harry Nyquist, a famous American electrical engineer, an audio recording must be sampled at a rate of twice the frequency of the actual recording or higher in order to retain its quality.  In order to calculate how large the file will be after quantisation when the minimum amount of samples is taken, one needs to multiply the frequency by 2, and then by the resolution.  This gives the amount in bits, which can be converted to bytes, kilobytes and megabytes.
  In order to play the music stored using speakers, the digital data must be converted back to analogue.  As a result of only having samples, the computer is required guess the missing values, by looking at the values they are between.  Graphically this would seem like a best fit line between the discrete steps.  This often results in the audio sounding different to when it was originally created.
  On computers sound may be stored in a variety of different file formats which vary in quality.  The most common is WAV, which is on average 2.5 MB of data per minute of audio.  MPEG formats on the other hand do not retain data concerning frequencies which cannot be interpreted by the human brain.  As such they can be only 10% of the size of the original audio recording.  When stored digitally it is also much easier for us to edit and alter recordings in certain ways, such as adding effects.  This makes changing music much easier than it was before these advanced techniques, when each audio track was recorded on a separate tape, and if there was a mistake the recording had to be recreated.
  Sound may also be synthesised using a MIDI (Music Information Digital Interface), which gives the computer instructions about what exact sound to make, including instructions about factors such as its pitch or loudness.  This is like vector graphics, as the exact instructions used to create the file must be given.  As such this technology cannot be used to create a copy of an existing audio recording.  The file size is much smaller however, because it is not the audio recording which is stored, but the instructions used to create it.
  One last way that audio can be used on computers is through the use of streaming technology.  This involves buffering sound in packets over a network, or for the most part the internet.  Parts of the sound recording are sent in small amounts of bits, and are discarded after being played.  Although this music cannot be stored on a hard disk, it is more difficult to be copied meaning that copyright is protected, and cannot be listened to when the computer cannot contact the server.  It is also affected by bandwidth, because if only a small amount of bits cannot be sent per second then the audio track will often need to stop, wait until more data has been received and then resume.

Tuesday, 1 February 2011

Images, Graphics and Compression Techniques

Images and graphics on computers have traditionally been, and generally still are stored as bitmaps - therefore arrays of binary digits, which depending on the colour depth will have a certain colour mapped to each pixel in a bitmap.  A pixel is the smallest addressable area of colour in an image, and these make up bitmaps.
  Colour depth refers to the number of bits used per pixel to store the colour, and when there are a greater range of colours available for use the bitmap will allot a larger binary number to each pixel resulting in a larger number of combinations of binary digits.  For example, if there was a colour depth of 3-bit, then 8 colours would be available, due to there being 8 possible combinations (000 to 111).  The number of possible combinations can be quickly figured out by putting 2 to the power of binary digits allotted to each pixel.  Therefore if the colour depth was 8-bit then 256 colours would be available, and 2 to the power of 24 colours available for 24-bit colour depth.  The most commonly used colour depth is 24-bit colour, which is known as true colour because a colour depth of 24-bit or higher cannot be distinguished from reality by the naked eye.  When 24-bit colour is used, 8 bits are allocated for red, 8 bits for green, and 8 for blue and the combination of the three selected shades forms the outcome.
  Uncompressed bitmaps always use a large amount of memory however, as the total number of bits used equals the number of bits per pixel multiplied per number of pixels.  For example, a 24-bit (true colour) bitmap taken on a 14 megapixel camera would contain 14 million pixels.  This number is then multiplied by 24 to get 336000000 bits, which is 42000000 bytes, or 42 megabytes - the largest possible size of a 24-bit 14 megapixel image.  As such many people use compression techniques to reduce the file size of an image.  Compression may either be lossy which involves the quality of the image decreasing, or lossless which involves no data being lost.  An example of lossy compression is saving an image as a JPEG, a format which removes colour which is difficult for the human eye to see, whilst Run Length Encoding is a type of lossless compression, and involves designating blocks of the same colour within the image, so that the same colour does not need to be specified for every pixel in that area.
  Vector graphics refer to another method of storing images.  Instead of storing them as bitmaps, they store information about the shapes in and other properties of the image such as colour, so that each time they are accessed they can be created.  In order to be able to create a vector graphic however, the instructions used to create the image must have been inputted, so that they could have been recorded.  These instructions are stored within what is known as the drawing list and contain data such as the shape type, coordinates and area.  This means that images taken with a digital camera for example cannot be turned into vector graphics because these properties are not recorded.  They would also be unsuitable for images as complex as photographs due to their level of detail.
  As a result of instructions being used to create the image instead of data about each pixel being stored the image has a much lesser file size (sometimes up to a million times less), which means that they take up much less hard disk space and can be loaded more quickly.  They also do not become pixelated like bitmap images when zoomed in on, because of the way that the geometric data stored results in the scaling being more precise than a bitmap image because of the way the software can alter the graphic for that level of zoom, whilst bitmap images cannot be scaled in the same way due to containing a pre-defined amount of pixels.
  Lastly, resolution refers to an image's dimension in pixels in relation to the space it occupies.  More pixels in an image will result in a higher resolution, and as such the image will be of higher quality.  A typical resolution if 1024 x 768, but no area is specified, and as such this could appear to be pixelated (blocky and low quality) if projected onto a very large space such as the side of a building, or of very high quality if in small area such as a 19-inch visual display unit (monitor).  A better way of measuring resolution is through use of Dots Per Inch, which tells one how many pixels there are in a specified area, meaning that the quality of the image can be determined.