You are on page 1of 15

Lab 1

SIMULATING THE SAMPLING AND REBUILDING OF


SIGNALS
The lab shortly reviews the signal sampling, quantifying, rebuilding
knowledge earned in previous classes, preparing the students to use it in
data acquisition systems. The complexity of the work makes it suitable for
two successive lab periods.
THEORETICAL CONSIDERATIONS
The signals picked up from nature, both from environmental or
industrial processes, are usually analog. As suggested by Fig. 1, they origin
in electrical or non-electrical quantities and are translated (by transducers)
in electrical signals (usually voltages or currents). These are continuous,
both in time and amplitude domains. Digital handling supposes a
discretization process for both domains. The time discretizing (sampling
rom: eantionare) replaces the original continuous signal by a series of
samples (rom: eantioane), each equal to the instantaneous value of the
original signal at the sampling time.

acquisition
Environment
Transducer

Analog
input
signal

Conditioning
- amplification
- noise filtering
- galvanic isolation
- linearization, etc.

Sample
and hold

Anti-alias
filtering

conditioning

Actuator

analog
command

Conditioning
- amplification
- noise filtering
- linearization, etc.

Low-pass
filter

ADC

fsampling

DAC

Digital processing
- storage
- transmission
Interpolation - computing
- linearization
- etc.

action

Fig. 1 Acquiring an environmental signal and generating an appropriate


feedback command.
1

Data Conversion and Acquisition Systems - Lab manual


Considering the time interval between successive samples, two different
modes are possible:
uniform sampling (rom: eantionare uniform) or with constant
sampling rate (rom: frecven de eantionare) same time interval between
each two successive samples;
non-uniform sampling (rom: eantionare neuniform) or with variable
sampling rate the time interval between successive samples is not
constant.
Converting the analog sample value to a digital representation
(usually binary) includes, by default, the amplitude discretization:
quantification. The finite number of bits chosen for the binary used code, n,
allows a finite number of possible values: 2n. The least change of the input
signal value which is detectable into a correspondent digital value change is
the resolution of the ADC (Analog to Digital Converter, rom: CAN =
Convertor Analog Numeric). The resolution can also be expressed rated to
the FSR (Full Scale Range rom: domeniu de definiie) of the input analog
value: for a binary ADC, the Relative Resolution (rom: rezoluia relativ) is
2-n. A small quantifying error is equivalent to a good resolution. The ADC
(in fact the number of bits n) determines the relative resolution of the binary
representation.
The conversion time is the ADC parameter showing the time interval
from the sampling time until the output digital result is available. The
maximum sampling rate for a simple system is imposed by the conversion
time (Pipe-line ADCs bypass this limitation, but are not discussed here):
f sampling 1

(1)

tconv

For uniform sampling (most used), the sampling frequency is limited


conform to the sampling (Shannon) theorem (rom: teorema eantionrii):
f sampling 2 f max

(2)

where fmax is the highest frequency in the input signal spectrum.


2

Simulating the sampling and rebuilding of signals


Osc ilosc op

Fig. 2 Signal undersampling


Osc ilosc op

Fig. 3 Sampling a signal at Nyquist limit


Osc ilosc op

Fig. 4 Sinusoidal signal oversampling


3

Undersampling
(rom: subeantionare) uses
a sampling frequency lower
than specified by the
sampling theorem. The
resulting samples do not
carry enough information
about the original signal.
Fig.
2
shows
an
undersampled signal.
Sampling a signal
precisely with the Nyquist
frequency (Fig. 3) allows
(theoretically) the signal
rebuild, using an ideal filter
(practically
impossible).
Two samples are picked up
each input signal period.
Depending on the phase
offset between the input
signal and the sampling
times, the resulting sample
values are different. For the
two limit situations, the
samples values are:
0, as in Fig. 3);
maximum, respectively
minimum values of the
input signal.
Every
intermediate
situation is possible.
Oversampling (rom:
supraeantionare) uses a
sampling frequency (much)

Data Conversion and Acquisition Systems - Lab manual


higher
than
sampling
theorem requires.
The resulting samples
represent the input signal
more and more precisely,
as the oversampling rate
increases. Fig. 4 shows the
oversampling of a sinus
signal.

Osc ilosc op

Fig. 5 Rectangular signal...


Spec trul de amplitudine
10.0
8.0
6.0
4.0
2.0
0.0
0

500

1000

1500

2000

2500

Fig. 6 ...its spectrum...


Spec trul de amplitudine
10.0
8.0

The sampled signal


spectrum includes the
initial signal spectrum, but
also its mirror images
shifted around the sampling
frequency and its integer
multiples.
Alias phenomena
occur for undersampling
and consist in superposing
the original spectrum to
adjacent mirror images.
Recovering the initial
spectrum and subsequently
rebuilding the input signal
is now impossible.

6.0
4.0
2.0
0.0
0

500

1000

1500

2000

2500

Fig. 7 ...and the sampled signal spectrum.

For
infinite
spectrum
signals
(i.e.
rectangle, triangle), it is
impossible to obey the
sampling theorem (f=).
Fig. 5 Shows a rectangular
signal and Fig. 6 its

Simulating the sampling and rebuilding of signals


spectrum
Picking 15 samples
each rectangular signal
period, the sampled signal
spectrum superposes the
initial image to the mirror
images. (Fig. 7). The
filtering rebuild of the
initial signal is impossible.

Osc ilosc op

Fig. 8 Anti-alias filtered rectangular


signal...
Spec trul de amplitudine
10.0
8.0
6.0
4.0
2.0
0.0
0

500

1000

1500

2000

2500

Fig. 9 ...its spectrum...


Spec trul de amplitudine
10.0
8.0
6.0
4.0
2.0
0.0
0

500

1000

1500

2000

2500

Fig. 10...and the sampled signal spectrum.


5

It is preferable to
cut the initial signal
spectrum, using an antialias filter (low pass), as in
Fig. 9. The signal can be
rebuilt (using a low pass
output filter), as shown in
Fig. 10. Obviously, the
spectral limitation above
modifies the initial signal
shape, (Fig. 8), but avoids
the alias phenomena.
Ideal
sampling
(obvious
impossible)
would
generate
infinitesimal
length
samples
of
infinite
amplitude, such a way that
the sample energy to be
proportional to the input
signal instantaneous value
at the sampling time. (The
area of such a sampling
pulse, in the time-power

Data Conversion and Acquisition Systems - Lab manual


reference
system
represents the sample
energy). Fig. 11 shows this
kind of sampling applied
on a sinus signal as in Fig.
4.
Real
sampling
circuits
peak
the
instantaneous value of the
Fig. 11 Ideal sampling (using finite energy
input
signal
at
the
infinite amplitude Dirac pulses)
sampling time. Fig. 12
shows the real sampling of
the sinus signal shown in
Osc ilosc op
Fig. 4.
The resulted sample
values
are
quantified
during the analog-to-digital
conversion.
A
finite
number
of
distinct,
equidistant
values
is
possible, using the n bits of
the
analog-to-digital
Fig. 12 Real sampling (finite amplitude)
converter.
The
digital
representation of the signal, a string of numbers generated by the analog to
digital converter, can be transmitted, stored and/or processed, taking the
advantages of digital technology (high speed, density, computational power,
error immunity, etc.)
Usually, the digital processing system generates an answer signal
(again a string of numbers), which is re-converted to an analog signal to be
used in closing the feedback loop shown in Fig. 1, influencing the
environment in the desired manner.
Osc ilosc op

Simulating the sampling and rebuilding of signals


Osc ilosc op

Fig. 13 Rebuilding a signal using 0-degree


interpolation...

To rebuild the
continuity of the (initial or
processed) signal, the
digital values in the string
are interpolated:
0-degree (no digital
interpolation) keeps the
current sample value
unmodified until the
time of the next sample
(Fig. 13);

Osc ilosc op

Fig. 14 ...and linear (1st degree)


interpolation.

1st
degree
(linear)
interpolation generates
a linear function to
bound the values of
each two successive
samples (Fig. 14);
2nd, 3rd, etc. degree
interpolations
use
polynomial
corresponding
functions to generate
additional
values
between the original

samples.
The 0-degree interpolation represents an extreme approximation of ideal
sampling, suggesting sample pulses whose width equals the sampling
period.
The digital-to-analog converter performs by default the 0-degree
interpolation; latching each digital sample value at its input until the time of
the next sample keeps the output analog value constant for that time.
1st degree and higher interpolations are performed as the final step in the
digital processing, inserting new digital sample values between the existing
ones. The so obtained string of values is also 0-degree interpolated by the
7

Data Conversion and Acquisition Systems - Lab manual


latching mechanism previously described. Obviously, the analog signal is in
this case smoother than without digital interpolation.
The final (re)build of the (initial) analog signal supposes the spectral cut
of the sampled (eventually interpolated) signal, recovering its (initial)
spectrum. In the case of ideal sampling, the original spectrum is available in
the sampled signal in infinite number of mirrored images, around integer
multiples of sampling frequency. The simplest way to extract it, is using a
low-pass filter including in its pass-band the whole spectrum of the original
spectrum, but no mirrored images.
Spectral components of a digital signal can be computed by applying
DFT = Digital Fourier Transform algorithm to the sample values
(eventually in FFT = Fast Fourier Transform variant). By default, the
algorithm supposes the input time sample set represents a whole period of a
periodical input signal. FFT algorithm simplifies the calculus, significantly
reducing the run time, but it imposes the input data string to have a power of
2 number of samples.
The length of the digital representation has to be limited at a time
period (which is considered the Fourier-transformed-signal period) even if
the initial signal has a different period, as in Fig. 15. Applying the DFT
(FFT) algorithm supposes by default that the input data string is periodically
repeated infinite number of times, to generate a theoretical, periodical,
infinite signal. This artifact eventually induces discontinuities at the
period boundaries, inducing high frequency components in the computed
spectrum. Being higher than the Nyquist allowed frequency, these
components generate alias phenomena in the 0...fs/2 range. The computed
spectru
m
differs
compar
ed
to
the
initial
signal
Fig. 15 Discontinuities induced by the FFT computing period.
8

Simulating the sampling and rebuilding of signals


spectrum, as the energy of some spectral components leaks to other ones
(spectral leakage rom: scurgere spectral).
A simple way to improve the spectral representation of a sampled
signal is applying a smoothing window (rom: fereastr de netezire). It is an
auxiliary signal, in the time domain, having a specific shape (mathematical
expression). Basically it is null outside its own definition range, around 1 in
its symmetry point and decreases toward the range limits.
The simplest one (actually not smoothing) is the rectangular
window. It has the value of 1 during the definition time range, and 0
outside. Other windows have specific shapes (mainly similar to the Gauss
bell) closing (together with the Ox axis) the same surface like the same time
range rectangular window.
Applying
the
Osc ilosc op
smoothing window means
point by point multiplying
the initial digital signal to
the window. Applying the
rectangular
window
generates a signal identical
to the initial one, for the
window range, and null in
rest.
Fig. 16 The initial signal,...
Fig. 16 and Fig. 17
show a sinus signal and
Osc ilosc op
how it change by applying
a Hanning window. The
FFT algorithm defined time
range is not equal to an
integer number of sinus
periods.
Applying a nonrectangular
smoothing
window modifies the initial
Fig. 17 ...the Hanning window and the signal for the defined range
resulting signal.
9

Data Conversion and Acquisition Systems - Lab manual


and makes it to 0 in rest. Changing the signal even in the window range
does modify the spectrum, but less than the discontinuities occurred without
windowing would do.
From the spectral point of view, the smoothing window acts as a
narrow band low-pass filter (the pass-band approximately equals the inverse
of the window definition time).
The equal surface closed by all window types generates equal
windowed signal energy for the considered time range, regardless the
window type.
Table 1 shows an image of the optimum window type for several
applications. Usually the input signal is not known well enough to correctly
choose a window and the optimum type is experimentally determined.
Signal type
Window
Short pulse (shorter than the Rectangular
window time range)
Long pulse (longer than the Exponential, Hanning
window time range)
General application
Hanning
System analysis (measuring the Hanning (for random excitation)
frequency response)
Rectangular (for pseudo-random
excitation)
To separate two tones (close Kaiser-Bessel
frequencies,
very
different
amplitudes)
To separate two tones (very close Rectangular
frequencies and amplitudes)
Precise de amplitude measurement Flat Top
for a single tone
Table 1 Recommended windows for different signal types

10

Simulating the sampling and rebuilding of signals


THE SIMULATION PROGRAM
The analog signal acquisition process and further on the signal
restoring based on the picked samples are simulated based on the block
structure shown in Fig 18.
Discretization
Signal
generator

Anti-alias LP
Butterworth filter

Sampling

Energetic correction
DAC

ADC

Final LP
Butterworth filter

Interpolation
Signal shape
Frequency
Amplitude
Offset
Noise level

Cut frequency
Filter order

Rebuild
Conversion time

Cut frequency
Filter order

Interpolation type

Sampling frequency

Fig. 18 The block structure of the simulated process


The simulation program suggests 4 devices, each having its own
scope and spectral analyzer. The settable parameters are shown on the block
diagram. Fig. 18 is a simplified variant of the general data acquisition and
processing system shown in Fig. 1.
THE SIGNAL GENERATOR

the signal shape to study:


- sinus;
- rectangle;
- triangle;
- saw tooth;
- sum of two sinus signals.
the signal frequency can be set in the range 0,1 Hz 200 MHz, using
the Frequency radio button and the range push buttons;
the signal amplitude settable in the range 0+10 V;
11

Data Conversion and Acquisition Systems - Lab manual


the Offset button sets the continuous component of the signal in the
range 10+10 V;
the (white) noise of the signal generator settable in the range 0+1 V.
ANTI-ALIAS FILTER
Limits the spectral bandwidth before sampling.

ON/OFF pushbutton allows skipping the filter.

The low pass Butterworth simulated filter, allows two parameters to


set:
cut frequency in a range depending on the signal generator range:
f min 2500 f min ;
filter order (1 50) determines both the through- and phase-diagram.
Both filter through-diagram and the filtered signal are shown on the
spectral analyzer screen.
DISCRETIZATION AND REBUILD BLOCK
The functions supplied here are:
The discretization both in time- (sampling) and amplitude-domain
(analog-to-digital-conversion implied quantification).
The Sampling is uniform. The sampling frequency can be set in a
range depending on the generator signal range:
f min 10.000 f min
The analog-to-digital conversion is characterized by the conversion
time, variable in a range dependent to the sampling frequency:
0 Tsampling .
A scaled cursor represents the percentage of the ADC conversion time
compared to the sampling period. Quantifying- and ADC-specific errors are
neglected (ideal, infinite resolution ADC).
12

Simulating the sampling and rebuilding of signals


Rebuild of the input signal using the picked samples. Fig. 15
suggests that the sampled signal is not digitally processed, the samples are
directly delivered to the rebuild process.
The direct digital-to-analog conversion generates very short pulses,
having same amplitude as the original samples (similar to real sampling
shown in Fig. 12). The resulting signal has much lower energy than the
initial one. The energy loss is due to the very short (infinitesimal) sample
length.
The energetic correction generates very short pulses with such an
amplitude to equal input signal energy (similar to ideal sampling shown in
Fig. 11 the signal instantaneous value information is encoded in the
surface of the rectangular pulse).
0-degree interpolation (hold) is the most used way to rebuild/generate
analog signals, due to simplicity. A simple latch circuit stores the value of
each sample at the DAC input, until the next update. The so built
rectangular pulses have the amplitude equal to the original sample and the
width equal to the sampling period, correctly encoding the energetic
information (Fig. 13).
1st-degree (linear) interpolation implies digital processing of the
available samples, connecting them with appropriate linear segments. Linear
interpolation requires two successive sample values, implying a delay equal
to the initial sampling period (Fig. 14).
THE OUTPUT FILTER
It limits the bandwidth of the DAC output signal, cutting off the high
frequency components of the mirror images induced by sampling. When
rebuilding the signal from ideal (infinitesimal) samples, it is the only block
to extract the initial signal spectrum from the sampled signal one. On the
other hand, the interpolation significantly reduces and pushes at higher
frequencies the mirror images, the output filter only (eventually) improves
the rebuilt signal.
ON/OFF button allows skipping the output filter.
Two parameters are adjustable for the low pass Butterworth output
13

Data Conversion and Acquisition Systems - Lab manual


filter, similar to the anti-alias filter:
cut frequency in a range depending on the signal generator range:
f min 2500 f min ;
filter order (1 50) determines both the through- and phase-diagram.
Both filter through-diagram and the filtered signal are shown on the
spectral analyzer screen.
Hints:
Each spectral image shown along the signal propagation path uses a
time smoothing window, as discussed at theoretical considerations.
However, only the first time diagram explicitly shows the smoothing
window (shadowed) and the smoothed signal (in green).
All the time- and frequency-diagrams allow a zoom-in function, using
the button in the up-right corner of the diagram. The enlarged diagram
provides two cursors, to point specific values. Both mouse-drag and
joystick-like buttons allow cursor moving. The coordinates of cursor-tographic intersections are displayed in the low-right corner of the window.
The process is simulated in transient- (null initial conditions) or steadymode, depending on the state of the control button placed in the Discretizing
panel.
The time diagrams of the anti-alias filtered- and rebuilt-signal allow
emphasizing the sample values as visible dots, using the appropriate control
button, located in the Discretizing panel.

14

Simulating the sampling and rebuilding of signals


THE LAB FLOW
After identifying the configuration and adjustment commands
provided by the simulation program, the students have to perform all the
following steps:
THEMES FOR LAB 1
identify the spectral diagrams for the generator provided signals
emphasize the undersampling phenomenon for each signal type
emphasize the oversampling phenomenon for each signal type
analyze the filter output signal dependency on the filter degree
for infinite spectrum signals, study the anti-alias filter effect on the
sampled signal
study the required conditions to correctly acquire a rectangular 100MHz
signal.
analyze the meaning of energetic correction for non-interpolated signal
rebuild
analyze the final filter effect for non-interpolated signal rebuild
analyze the final filter effect for 0-degree interpolated signal rebuild
analyze the final filter effect for 1st-degree interpolated signal rebuild
perform the previous analyzes both for steady and transient mode
identify the optimum smoothing window for each type of input signal
(when the time window does not include a whole number of input signal
periods)

15

You might also like