Activity 1 ADC To DAC
Activity 1 ADC To DAC
Activity 1 ADC To DAC
II. BACKGROUND
Digital signal processing generally involves the following: (1) representation of a an input
analog signal as sequence of numbers, (2) implementation of a computational algorithm on the
numbers representing the input signal, and (3) reconstruction of an output analog signal from the
numbers that results from the computations. The mathematical operations done on the numbers is
the signal processing. There is a wide variety of goals for signal processing like enhancement of
visual images, recognition of speech, compression of data for storage and transmission, and removal
of unwanted noise.
The process of representing an analog signal as a sequence of numbers is analog-to-digital
conversion (ADC) and it is done using an IC device called an analog-to-digital converter. The
reconstruction of an analog signal from a sequence of numbers is digital-to-analog conversion
(DAC) and it is done using a digital-to-analog converter. In some cases, ADC and DAC are
performed by a single IC device.
SLU 1
MEngg ECE D511
Digital Signal Processing ADC and DAC
The ADC process is divided into three sub-processes, namely: sampling, quantization, and
encoding. Sampling involves taking measurements of the input analog signal at regular intervals
and each measurement is referred to as a sample. The interval between successive samples is the
sampling interval and the number of samples taken per unit time is the sampling frequency. The
sampling frequency is in samples per second which is commonly denoted with the unit Hz.
Quantization is the rounding-off of the measured value to the nearest quantization level. Encoding is
the representation of the sample with the binary code assigned to the quantization level that it has
been rounded to.
SLU 2
MEngg ECE D511
Digital Signal Processing ADC and DAC
For a given analog-to-digital converter, the number of bits used to represent a sample is
fixed (usually 8, 16, or 24 bits) and the binary numeric format is also specified (usually signed 2's
complement). The interval between quantization levels is also given.
Let: n - number of bits used to represent a sample
Vref - quantization interval (also called the reference voltage)
xq - quantized or rounded-off value of the sample
and
xq = round(xs/Vref) * Vref
with round( ) being a rounding-off function that rounds-off the argument xs/Vref.
Assuming signed 2's complement is used, the sample is represented in binary format as
binary representation of sample = n-bit signed 2's complement of round(xs/Vref)
ADC Issues
To ensure that the numbers resulting from the ADC represents the input analog signal,
several considerations should be observed.
According to the Nyquist sampling theorem, the sampling frequency used in the ADC
process should be at least twice the highest frequency of the input analog signal to ensure that the
spectral content of the analog signal is represented by the samples.
Fs ≥ 2fmax, where fmax - highest frequency content of the analog signal
If the sampling frequency is less than that specified by the Nyquist limit, the samples will not
represent the analog signal. Rather, the samples will represent a different signal called an alias. The
Nyquist sampling theorem also implies that the highest frequency represented is Fs/2. Any
frequency content of the analog signal that is higher than Fs/2 is not represented by the samples.
Sampling at the Nyquist rate can create a good approximation of the original signal. Oversampling
can also create the same approximation, but it is redundant and unnecessary.
With quantization, the total voltage range is subdivided into several quantization levels. The
magnitude difference between adjacent quantization levels is called the quantization interval or
resolution. The likelihood of a sample voltage being equal to one of the quantization levels is
remote. Therefore, each sample voltage is rounded off to the closest available quantization level.
The difference between the sample voltage and the closest available quantization level is called the
SLU 3
MEngg ECE D511
Digital Signal Processing ADC and DAC
quantization error. For a given voltage range, more quantization levels will produce quantized
values closer to the sampled values thus, smaller quantization error. The smaller the quantization
error, the more accurately the quantized signal will resemble the original analog sample.
When the amplitude of the signal is high, all samples higher than the highest quantization
level are quantized to the highest quantization level and a condition called overflow occurs. With
overflow, numbers resulting from the ADC process do not represent the actual variations of the
analog signal. The numbers represent a signal whose amplitude is clipped at the highest
quantization level. A similar condition occurs when samples are lower than the lowest quantization
level.
Thus, to ensure that the numbers resulting from the ADC process represent correctly the input
analog signal, the sampling frequency should satisfy Nyquist sampling theorem and overflow
should not occur.
SLU 4
MEngg ECE D511
Digital Signal Processing ADC and DAC
From the concepts presented in the background, solve the following problems.
1. The ADC shown samples at 8000 samples/second and uses 8-bit, signed 2's complement
encoding. Its reference voltage is 10mV. The input signal is defined as x(t)=1.5sin(2000πt)volts
and the sampling starts at t=0.
ADC Table:
n x[n], mV xq[n], mV xenc[n]
1
2
3
4
5
6
7
8
(b) The output of the ADC process is applied as input to an DAC process as shown at a rate of 8000
samples/second. The DAC has a resolution of 25mV and also uses 8-bit, signed 2's complement
format.
SLU 5
MEngg ECE D511
Digital Signal Processing ADC and DAC
Sketch the staircase waveform of the output signal of the DAC. Indicate all significant amplitude
values and time values.
(b) Determine the minimum sampling frequency (Fsmin) to avoid aliasing and the minimum
reference voltage (Vrefmin) that should be used to prevent overflow in the analog-to-digital
conversion of x(t). Assume that 8-bit, signed 2's complement is used.
Fsmin = __________ Hz Vrefmin = __________ volt
SLU 6
MEngg ECE D511
Digital Signal Processing ADC and DAC
1. Familiarization with SCILAB functions used for the simulation of ADC and DAC
(a) Open the SCILAB file ADC_DAC_functions.sce and familiarize with the user-defined function
functions used in the file. Understand their operation and the syntax for calling them.
(b) Use the SCILAB functions declared in ADC_DAC_functions.sce to solve problem 1 of the
problem set. Compare the results you get from using the SCILAB functions with your answers.
Are the results obtained using the SCILAB functions similar to your answers? _____
2. Simulation of the ADC/DAC process to demonstrate aliasing and overflow.
(a) Copy and execute the simulation program simulation1.sce given in Part IV. (may require minor
debugging)
(b) Go over the program and answer the following:
SLU 7
MEngg ECE D511
Digital Signal Processing ADC and DAC
(e) Edit the simulation program to make the frequency of the input signal be 100Hz and its
amplitude be 5volts and then execute the simulation program.
(e.1) What is the amplitude and frequency of the reconstructed signal?
_______________________________________________________________________
(e.2) Is the reconstructed output an acceptable approximation of the input signal
in terms of (a) waveform, (b) amplitude, and (c) frequency?
_______________________________________________________________________
(f) Edit the simulation program to make the frequency of the input signal be 8100Hz and its
amplitude be 5volts and then execute the simulation program.
(f.1) What is the amplitude and frequency of the reconstructed signal?
_______________________________________________________________________
(f.2) Is the reconstructed output an acceptable approximation of the input signal
in terms of (a) waveform, (b) amplitude, and (c) frequency?
_______________________________________________________________________
3. Simulation of the ADC of audio signals and storing the ADC results as a wave file
(a) Copy and execute the simulation program simulation2.sce given in Part IV. (may require minor
debugging)
(b) Edit the PATH in the simulation program and then execute the program?
(b.1) Did it result to the playback of the sampled 500Hz tone?
_______________________________________________________________________
(b.2) Is the wave file created at the designated subdirectory?
_______________________________________________________________________
(b.3) Playback the wave file with Goldwave. Does the playback of the wave file sounded
similar to the 500Hz tone during the execution of the simulation program?
_______________________________________________________________________
(c) Create 4 wave files by simulating an ADC process in which the 500Hz input is sampled at
Fsmin, 2Fsmin, 5Fsmin, 10Fsmin with Fsmin being the minimum sampling frequency as
prescribed by the Nyquist sampling theorem. Name the wave files according to the convention
SLU 8
MEngg ECE D511
Digital Signal Processing ADC and DAC
used in the program. Open the wave files simultaneously using Goldwave. Expand the
displayed waveforms by pressing SHIFT + to observe the reconstructed signals.
(c.1) Which wave file has the best reconstruction of the 500Hz tone?
_______________________________________________________________________
(c.2) Do all the reconstructed signals sound similar? If no, which signals sound signals sound
similar?
_______________________________________________________________________
(d) Edit the simulation program to make the frequency of the input signal be 7800Hz with an
amplitude of 2.5volts. Reset the sampling frequency to 8000Hz and then execute the simulation
program. Open the resulting wave file using Goldwave.
(d.1) What is the amplitude and frequency of the reconstructed signal?
_______________________________________________________________________
(d.2) Is the reconstructed output an acceptable approximation of the input signal in terms of
(a) waveform, (b) amplitude, and (c) frequency? if no, explain why?
_______________________________________________________________________
_______________________________________________________________________
The following are the SCILAB programs for the laboratory activities. The programs can be
executed by copying them and pasting them on the Scilab command console or in the Scilab editor.
SLU 9
MEngg ECE D511
Digital Signal Processing ADC and DAC
Ts=1/Fs;
ts=ti:Ts:ti+tdur;
xn=x(ts);
endfunction;
function xqn=quantization(xn,Vref,n)
//Function that simulates the quantization process
//Assumes an n-bit, signed 2's complement format
//xqn - quantized values of the samples
//xn - values of the samples to be quantized
//Vref - reference voltage / resolution of the ADC
//n - number of bits
//Vmax - maximum input voltage allowable to prevent overflow
//Vmin - minimum input voltage allowable to prevent overflow
Vmax=(2^(n-1)-1)*Vref;
Vmin=-(2^(n-1))*Vref;
[r,c]=size(xn)
for i=1:r
for j=1:c
// quantize the sample and check for overflow
if xn(i,j) > Vmax then
xqn(i,j)= Vmax; end;
if xn(i,j) < Vmin then
xqn(i,j)=Vmin; end;
if xn(i,j)>=Vmin & xn(i,j)<=Vmax then
xqn(i,j)=round(xn(i,j)/Vref)*Vref; end;
end;
end;
endfunction;
function xenc=encoding(xqn,Vref,n)
//Function that simulates the encoding process //xenc - n-bit, signed, 2's complement
representation of the values of xqn
//xqn - quantized values of the samples
SLU 10
MEngg ECE D511
Digital Signal Processing ADC and DAC
//DAC FUNCTIONS
function [tsd,xnd]=dac(xenc,Fsp,Vrefp,n)
//Function that simulates the decoding process
SLU 11
MEngg ECE D511
Digital Signal Processing ADC and DAC
[r,c]=size(xenc);
//Decode the value of the sample from the signed, 2's complement numbers
for i=1:r
for j=1:c
//Check sign bit
if part(xenc(i,j),1)=='0' then
//Convert the signed, 2's complement number to decimal
xndecimal=bin2dec(part(xenc(i,j),2:n));
//Compute the quantized value
xnd(i,j)=xndecimal*Vrefp;
else
//Convert the signed, 2's complement number to decimal
xndecimal=-(2^(n-1)-bin2dec(part(xenc(i,j),2:n)));
xnd(i,j)=xndecimal*Vrefp;
end;
end;
end;
//Generate the time intervals for the samples
//Assumes that the first sample is reconstructed at t=0
dtp=1/Fsp;
tsd=0:dtp:(length(xnd)-1)*dtp;
//Plot the staircase waveform of the reconstructed analog signal
clf;plot2d2([tsd length(xnd)*dtp],[xnd xnd(length(xnd))]);xgrid();
endfunction;
1. Simulation1 (simulation1.sce)
SLU 12
MEngg ECE D511
Digital Signal Processing ADC and DAC
2. Simulation 2 (simulation2.sce)
SLU 13
MEngg ECE D511
Digital Signal Processing ADC and DAC
//Generate the values for the sampling instants for 5 seconds duration
ts=0:1/Fs:5;
//Generate the samples for x(t)
xn=x(ts);
//Playback the samples
playsnd(xn,Fs);
//Save the samples as a .wav file with filename tone500Hz_Fs8000_8bits
wavwrite('PATH\tone500Hz_Fs8000_16bits.wav',xn,Fsp,8);
SLU 14