Digitization of Analog Signals in TD

Download Report

Transcript Digitization of Analog Signals in TD

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:
Digitized signal stored
as a sequence of numbers
 array
Analog Signal : AI
V(t) = F(t)
Clock
(Pulse Wave signal)
Sampling interval,
Sampling Frequency
3
ADC: Sampling and Quantization
(simplified operation as a two stage process)
Analog Signal : AI
S/H Sample and Hold circuit
Quantizer
Quantization. Result:
Digitized signal stored
as a sequence of numbers
 array
4
Stage 1. Sample and Hold
Analog Signal : AI
Sample and Hold circuit
AI : Analog Input
AO : Analog Output
C : control signal (Clock)
Analog Signal : AO
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
Sampling interval,
Sampling Frequency
(Pulse Wave
signal)
Quantization. Result:
Digitized signal stored as a sequence of numbers
 array
6
Stage 2. Quantization: Number of Quantization Levels
Quantizer
Circuit
Quantizer circuit “searchs” for the best “approximation”
 To finish the process in the reasonable time
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 setup() {
Serial.begin(9600);
for (int i=0; i<100; i++)
{
digitalSignal[i] = i;
}
}
void loop() {
for (int i=0; i<100; i++)
{
Serial.println( digitalSignal[i] );
delay(1);
}
}
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
int val;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
val = analogRead( analogPin);
Serial.println(val);
delay(50);
}
Reads an analog input on pin 0,
converts it to voltage,
and prints the result to the serial monitor.
Graphical representation is available
using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0,
and the outside pins to +5V and ground.
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println(val);
17
Arduino: Analog Input. “Simple Voltmeter”.
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading
// (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
Reads an analog input on pin 0,
converts it to voltage,
and prints the result to the serial monitor.
Graphical representation is available
using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0,
and the outside pins to +5V and ground.
18
Arduino: Analog Input. Voltage range
The Arduino UNO board contains
a 6 channel
10-bit analog to digital converter
(Pins A0 .. A5)
This means that it will map input voltages
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.
The input range and resolution can be changed
using analogReference().
Do not do this until full understanding
* Some authors uses 5 V / 1023 !!!!
19
Arduino: Analog Input. Sampling Rate
For a 16 MHz Arduino the ADC clock is set to 16
MHz/128 = 125 KHz.
Each conversion in AVR takes 13 ADC clocks
so 125 KHz /13 = 9615 Hz.
That is the maximum possible sampling rate,
but the actual sampling rate in your application
depends on the interval
between successive conversions calls
Practically:
Much less.
Something must be done with samples.
Sending data to PC takes time
PC must response
But Windows is not real-time system
 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