You are on page 1of 20

Electronic instrumentation

Digitization of Analog Signal in TD


Lecturer: Dr. Samuel Kosolapov
Items to be discussed

• Digitization (or digitizing) of Analog Signal


• Sampling and Quantization
• Storage of Digital signal as array of counts
• Nyquist Frequency
• Alias
• Serial Monitor and Serial Plotter
• Arduino Examples

2
ADC

ADC
Quantization. Result:
Analog Signal : AI Digitized signal stored
V(t) = F(t) as a sequence of numbers
 array

Clock
(Pulse Wave signal)

Sampling interval,
Sampling Frequency

3
ADC: Sampling and Quantization
(simplified operation as a two stage process)

Quantization. Result:
Digitized signal stored
Analog Signal : AI as a sequence of numbers
S/H Sample and Hold circuit Quantizer  array

4
Stage 1. Sample and Hold

Sample and Hold circuit


AI : Analog Input
Analog Signal : AI Analog Signal : AO
AO : Analog Output
C : control signal (Clock)

The output level of the S/H is updated


on every rising edge of the ADC’s clock input

AI not equal to AO !!!

5
Stage 2. Quantization

Quantizer
Circuit
Analog Signal : AO
Clock
(Pulse Wave
signal)
Sampling interval,
Sampling Frequency

Quantization. Result:
Digitized signal stored as a sequence of numbers
 array

6
Stage 2. Quantization: Number of Quantization Levels

Quantizer Quantizer circuit “searchs” for the best “approximation”


 To finish the process in the reasonable time
Circuit one must LIMIT a number of quantization levels.

 Speed versus Accuracy

7
Sampling Frequency. Nyquist Frequency
Nyquist sampling theorem:
The sampling frequency should be at least twice the highest frequency contained in the signal.

Example: signal is sinewave at a frequency 1 Hz

According to Nyquist theorem,


if we sample this waveform at 2 Hz ,
this is sufficient to capture every peak of the signal
 We can reconstruct this signal

8
Oversampling and Undersampling
Oversampling (at a frequency, say 3 Hz) is OK.
We have more than enough samples
to reconstruct the signal

Undersampling (at a frequency, say 1.5 Hz) is BAD.

The problem is that with undersampling


we get wrong information about the signal.
The person receiving these samples reconstruct
different signal

9
Nyquist Frequency
Real signal is a complex signal composed of
many frequency components.
By Fourier theorem we know, that any continuous signal
can be decomposed in terms of a sum of sines and cosines
at different frequencies.
Example: sum of sinewaves at frequencies 1 Hz, 2 Hz and 3 Hz

We know, that highest frequency in this signal is 3 Hz.


 This signal must be sampled at least at 2*3 Hz = 6 Hz.
One can see that then we can exactly reconstruct the signal

10
Nyquist Frequency and Nyquist Rate

Strictly speaking, the Nyquist frequency should not be confused with the Nyquist rate,
which is the minimum sampling rate
that satisfies the Nyquist sampling criterion for a given signal

Thus, Nyquist rate is a property of a continuous-time signal,


whereas Nyquist frequency is a property of a discrete-time system.

11
Restoring Analog Signal by “samples”

12
Arduino: Presenting Digitized Signal
with Serial Monitor and Serial Plotter
Version 1.6.6. Reinstall !!!

Arduino has a class “Serial”


Arduino communicates with PC by using USB cable.
However communication is executed by using RS232 protocol

Arduino IDE has “Serial Monitor” and “Serial Plotter”.

“Serial Monitor” can accept bytes from Arduino


and send bytes to Arduino.

Class Serial has a number of “methods” (functions) enabling


to work with bytes, int, strings, etc.

13
Arduino: Generating Synthetic Signal and Presenting it
with Serial Monitor and Serial Plotter

int digitalSignal[100];
void loop() {
void setup() { for (int i=0; i<100; i++)
Serial.begin(9600); {
for (int i=0; i<100; i++) Serial.println( digitalSignal[i] );
{ delay(1);
digitalSignal[i] = i; }
} }
}

14
Arduino: Presenting Digitized Signal
with Serial Monitor and Serial Plotter

15
Arduino: Analog Input. Potentiometer

Potentiometer used as a “Angle Sensor”.


Potentiometer connected as Voltage Divider.
One (say, left) pin of the potentiometer is connected to +5V
Then right pin of the potentiometer is connected to GND

Middle pin of the potentiometer is connected to


A0 : Analog Input Pin

Rotating the handle changes the voltage on the middle pin


from 0 V to +5V
16
Arduino: Analog Input. Potentiometer. Code.
int analogPin = 0; // A0 Reads an analog input on pin 0,
int val; converts it to voltage,
and prints the result to the serial monitor.
void setup() { Graphical representation is available
// put your setup code here, to run once: using serial plotter (Tools > Serial Plotter menu)
Serial.begin(9600);
} Attach the center pin of a potentiometer to pin A0,
and the outside pins to +5V and ground.
void loop() {
// put your main code here, to run repeatedly:
val = analogRead( analogPin);
Serial.println(val); // initialize serial communication at 9600 bits per second:
Serial.begin(9600);
delay(50);
} Serial.println(val);

17
Arduino: Analog Input. “Simple Voltmeter”.

Reads an analog input on pin 0,


converts it to voltage,
void loop() { and prints the result to the serial monitor.
// read the input on analog pin 0: Graphical representation is available
int sensorValue = analogRead(A0); using serial plotter (Tools > Serial Plotter menu)
// Convert the analog reading
// (which goes from 0 - 1023) to a voltage (0 - 5V): Attach the center pin of a potentiometer to pin A0,
float voltage = sensorValue * (5.0 / 1023.0); and the outside pins to +5V and ground.
// print out the value you read:
Serial.println(voltage);
}

18
Arduino: Analog Input. Voltage range

The Arduino UNO board contains


a 6 channel
10-bit analog to digital converter
(Pins A0 .. A5) The input range and resolution can be changed
using analogReference().
This means that it will map input voltages Do not do this until full understanding
between 0 and 5 volts
into integer values between 0 and 1023.
This yields a resolution between readings of:
5 volts / 1024 units
or, 0.0049 volts (4.9 mV) per unit.

* Some authors uses 5 V / 1023 !!!!

19
Arduino: Analog Input. Sampling Rate

For a 16 MHz Arduino the ADC clock is set to 16


Practically:
MHz/128 = 125 KHz.
Much less.
Each conversion in AVR takes 13 ADC clocks
Something must be done with samples.
so 125 KHz /13 = 9615 Hz.
Sending data to PC takes time
That is the maximum possible sampling rate,
PC must response
but the actual sampling rate in your application
But Windows is not real-time system
depends on the interval
between successive conversions calls  one may get jitter

Professionals using direct access to processor’


registers can increase Sampling Rate
but on the price of the precision (less bits)

20

You might also like