Data Files
Instrument Data
Why Do You Need To Know About Instrument Data?
What If You Read Measurements And Store The Results In Data Files?

Instrument Data - Numerical Formats

Let's imagine a situation in which you are trying to measure, record and analyze some data.  Here is a picture of the situation.

In this situation, the following operations take place.

• A measurement is taken, and the analog data is converted to a digital representation in the A/D converter tied to the computer.
• That data - now in digital form - is analyzed within the computer.
• After the data is analyzed, the results are stored - either in the computer or on a disk somewhere.
This kind of sequence of operations is very common today.  In other situations, you might find that the data is used immediately to determine control actions taken.  An example might be a temperature control in a chemical process.  Measured temperature data might be used to determine how much heat to apply to the process.

In situations like this, although it is not immediately apparent, the data that is measured often goes through many transformations and takes on many different representations.  Think about the following scenario.

• You take a temperature measurement at a weather station.  Temperature is an analog variable and it is continuously variable.  In other words, temperature can take on any value whatsoever.  Let's just assume that you measure a temperature of 58.3o Fahrenheit.
• Next that temperature measurement is converted to a voltage.  You might use an LM34 temperature sensor, and that would produce a voltage ov .583v to represent the temperature.
• The voltage from the temperature sensor will be converted to a digital format in the A/D converter.  Typically, that results in an integer that represents the voltage.
• That integer has to be changed to a floating point number, and that number would be 58.3.
• If you display the floating point number in a spreadsheet, you need to convert the number to a character form of representation.  That representation would consists of ASCII characters and they would most probably be:
• A character "five": 5
• A character "eight": 8
• A character "period": .
• A character "three": 3
• A character "Line Feed": \n
• If you save the data in a file, you probably save it using a character representation, especially if you save the data directly from the spreadsheet.
You should realize how many conversions are necessary in this process.
• The temperature sensor converts a temperature into a voltage - a conversion between two different physical variables.
• The A/D converter converts the voltage into an integer - a conversion of the voltage into a simple numerical representation.  The resulting integer usually takes two bytes.
• There has to be a program that converts the integere from the A/D into a floating point representation.  Typical IEEE floating point representations take four bytes, but more precise representations might take more storage.
• The floating point representation has to be converted into a character representation.
• Numbers are typed into little boxes.  Each time you type a number you type a sequence of characters.
• If you do that several times in a column, then add all of the numbers in a column, the following has to happen.
• Every entry - every sequence of characters in one of those little boxes - has to be converted to a number.  If you don't have a number you can't add them up.  Computers can't add a whole bunch of sequences of characters directly.  They have to convert those sequences to numbers then add the numbers.
• Before the computer/spreadsheet can display the result, the result has to be translated back into a sequence of characters before the result can be displayed in some other box in the spreadsheet.
You probably don't realize it, but if you know how to program you have already done some conversion between those formats.  You did it every time you printed numerical results from a computation.  Still, before you have a complete understanding of data representations you need to understand how instruments generate and store data.  That's the subject of this lesson.  If you just want a summary of the different kinds of representations - with some details - click here.

When you take measurements with a computer controlled instrument and transmit the data to the computer there are a number of different data formats that you can encounter.  You can encounter data that is represented as characters and data that is stored in numerical formats.

• Given a situation in which you need to measure data and store the measurement data in a computer file, you should be able to:
• Be able to convert data from a character format to a numerical format within a program and to realize when that occurs in a data gathering operation.
• Be able to convert data from a numerical format to a character format within a program and to realize when that occurs in a data gathering operation.
• Be able to write data to a file in either format.
• Be able to predict the size of the file.
We are going to start by looking at the first step in the process - the measurement of data with an instrument.  Even if you do not run the data through a spreadsheet - or any other analysis program - the first step is to measure things and convert the initial measurement to a digital format.  We will begin by looking at what happens as you use an A/D to convert a measurement into a digital format.

Instrument Data - Background

Let's look at what happens when you use an A/D.

• Let's say you wanted to build an A/D that measured voltage from zero (0) to ten (10) volts and you wanted it to have increments of a hundredth (0.01) of a volt.
• That would require you to be able to distinguish 1000 different voltage steps.
• That situation almost always means that you will need to have 10 bits in the A/D converter.
• Ten bits will give 1024 steps, so you could represent voltages like 0.00, 0.01, 0.02 . . . 10.23.  (Remember that is 1024 steps.  Count the zero!)  Remember, N bits can represent numbers from 0 to 2N-1, and 210-1 = 1023.
There are also relations between the accuracy of an A/D and the accuracy of a DVM.  There are many other questions that arise when you start using digital voltmeters.  The answers to questions about meters can be found in the lesson on DVMs.  Click here to go to that lesson.

What If You Read Measurements And Store The Results In Data Files?

Let's assume that you're measuring a DC voltage.  You've written a C function called "MeasureDCVolts", and you use it in this program segment.

float Volts;

Volts = MeasureDCVolts (instrumentHandle);
printf ("The measured voltage is  %f volts DC.", Volts);

What happens in this program segment?

Let's go through this one line at a time.  The first program line measures a voltage and stores the result in a floating point variable "Volts".

Volts = MeasureDCVolts (instrumentHandle);
If the instrument is a 4-1/2 digit meter, using a 30 volt scale, then the result takes at least 15 bits.  That physical measurement determines how well you know the voltage.  No matter how you manipulate it after that it won't get any more accurate.  A 4-1/2 digit meter on a 30 volt scale will measure to within .001 volt, or 1 millivolt.

Now, when you take that result and store it in a floating point variable, your're probably putting it into 4 bytes, or 32 bits.  That's a common way to represent a float variable.  You don't gain any precision when you do that.  Sometimes the conversion will give you trailing "9s" or a "1" after a string of zeroes when you print it.  That's irrelevant, but we do need to talk about what happens when you print things.

You need to consider what happens in a printf statement.  Here's the code from the program segment.

printf ("The measured voltage is  %f volts DC.", Volts);
This line uses the value of the float variable "Volts", and converts the numerical value it finds in "Volts" to a string of characters.  Then it puts those characters in the string surrounding the "%f" and then it prints the characters.  (The "%f" string gives the rule for conversion.)

Problems