Sunteți pe pagina 1din 14

ECE 515 FL

Digital Signal Processing Laboratory Activity 1: ADC and DAC

Activity No. 1
ADC and DAC
I. OBJECTIVES

At the end of the activity, the student must be able to:


1. Demonstrate the ADC and DAC processes.
2. Demonstrate the effects of ADC parameters on the digital representation of an analog signal.
3. Demonstrate the effects of DAC parameters on the reconstruction of an analog signal.

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 noisy.
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 ECE 1
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

Analog-to-Digital Conversion (ADC)

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 has the unit 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 it has been
rounded to.

The process of sampling can be mathematically presented as follows:


Let: x(t) - analog input signal
Fs - sampling frequency
Ts - sampling interval, with Ts = 1/Fs
xs(k) - be the kth sample with xs(1) being the first sample
ti - time at which the first sample is taken
The first sample is
x(1) = x(ti)
and the succeeding samples x(2), x(3), x(4) are
x(2) = x(ti + Ts)
x(3) = x(ti + 2Ts)
x(4) = x(ti + 3Ts)
Hence, the kth sample is
x(k) = x(ti + (k-1)Ts)

SLU ECE 2
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: 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. 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.

SLU ECE 3
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

The difference between the sample voltage and the closest available quantization level is called the
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.

Digital-to-Analog Conversion (DAC)

The Digital-to-Analog Converter reconstructs an analog signal from a sequence of numbers.


It outputs a voltage level corresponding to the number.
DAC output = number x Vref' , where Vref' is the reference voltage of the DAC.
The duration of each voltage level is the same as the interval Ts' at which the numbers are sent to
the DAC input.
To ensure that the correct signal is reconstructed by the DAC, its reference voltage Vref'
should be equal to the reference voltage Vref of the DAC. Also, the reconstruction frequency Fs' of
the DAC should be equal to the sampling frequency Fs of the ADC. If Fs is not equal to Fs', the
frequency of the reconstructed signal is the frequency represented by the numbers scaled by a factor
(Fs'/Fs). If Vref is not equal to Vref', the amplitude of the reconstructed signal is the amplitude
represented by the numbers scaled by a factor (Vref'/Vref)

SLU ECE 4
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

III. PRACTICE PROBLEMS

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.

x(t) - analog input signal


x[n] - value of nth sample
xqn[n] - quantized value of the nth sample
xenc[n] - 8-bit, signed 2's complement for the nth sample

(a) Complete the table below for the ADC process.

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 ECE 5
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

Sketch the staircase waveform of the output signal of the DAC. Indicate all significant amplitude
values and time values.

DAC Output Waveform:

2. Given an analog signal x(t) = 2 + 3sin(500πt) + sin(4000πt) volts.


(a) Determine the voltage range and frequency content of x(t).
Voltage range = __________ to _________ volts
Frequency content = _________, _________, __________ Hz

(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 ECE 6
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

II. Laboratory Activities

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) Open the simulation program simulation1.sce.
(b) Go over the program and answer the following:

(b.1) What is the amplitude and frequency of the input signal?


______________________________________________________________________
(b.2) What should be the highest frequency content of the input analog signal to avoid
aliasing?
______________________________________________________________________
(b.3) What should be the range of the input voltage to the ADC to avoid overflow?
______________________________________________________________________
(c) Execute the simulation program. Observe the signal reconstructed at the DAC output.
(c.1) Is the reconstructed output an acceptable approximation of the input signal in terms of
(a) waveform, (b) amplitude, and (c) frequency.
______________________________________________________________________
(d) Edit the simulation program to make the frequency of the input signal be 7800Hz and then
execute the simulation program.
(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?
_______________________________________________________________________

SLU ECE 7
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: 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) Open the simulation program simulation2.sce.
(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
used in the program. Open the wave files simultaneously using Goldwave. Expand the the
displayed waveforms by pressing SHIFT +  to observe the reconstructed signals.

SLU ECE 8
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

(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?
_______________________________________________________________________
_______________________________________________________________________

IV. SCILAB PROGRAMS

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.

1. ADC/DAC Functions (ADC_DAC_functions.sce)


//ADC FUNCTIONS
function [ts,xn]=sampling(Fs,ti,tdur)
//Function that simulates the sampling process
//Assumes that the input analog signal is described as a function x(t)
//ts-sampling instants
//xn-values of the samples
//ti - time at which sampling starts
//tdur - sampling duration
//Ts - sampling interval
Ts=1/Fs;
ts=ti:Ts:ti+tdur;

SLU ECE 9
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

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
//Vref - reference voltage / resolution of the ADC
//n - number of bits

SLU ECE 10
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

//bin - n-bit, signed 2's complement representation of the current value of xqn
[r,c]=size(xqn);
for i=1:r
for j=1:c
if xqn(i,j) >= 0 then
sign_bit='0';
magnitude=round(xqn(i,j)/Vref);
magnitude_bits=dec2bin(magnitude,n-1);
bin=sign_bit + magnitude_bits;
else
sign_bit='1';
magnitude=round(abs(xqn(i,j))/Vref);
magnitude_bits=dec2bin((2^(n-1))-magnitude,n-1);
bin=sign_bit + magnitude_bits;
end;
xenc(i,j)=bin;
end
end
endfunction;

//DAC FUNCTIONS
function [tsd,xnd]=dac(xenc,Fsp,Vrefp,n)
//Function that simulates the decoding process

//Plots the staircase waveform of the DAC output


//Assumes an n-bit, signed 2's complement format
//Assumes that the first sample arrives at t=0
//xnd - decoded values of the samples
//xenc - samples represented as n-bit, signed 2's complement numbers
//Fsp - sample reconstruction rate
//Vrefp - reference voltage / resolution of the DAC
//n - number of bits
[r,c]=size(xenc);
//Decode the value of the sample from the signed, 2's complement numbers

SLU ECE 11
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

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)

//SCILAB program to simulate an ADC/DAC process


//Clear the all previous variables and clear the command window
clear;clc;
//Clear all previous plots in the graphics window
clf;
//Load the SCILAB functions for ADC/DAC
exec('PATH/adc_dac_functions.sce'); //Edit the PATH accordingly
//Declare the ADC parameters

SLU ECE 12
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

Fs=8000; Vref=0.025; n=8;


//Declare the DAC parameters
Fsp=8000; Vrefp=0.025;
//Declare the input signal as a Scilab function
function xa=x(t)
xa=0.5*cos(200*%pi*t);
endfunction;

//Simulate the ADC process


ti=0;
tdur=0.03; //tdur - sampling duration, in seconds
[ts,xn]=sampling(Fs,ti,tdur);
xqn=quantization(xn,Vref,n);
xenc=encoding(xqn,Vref,n);
//Simulate the DAC process
[tsd,xnd]=dac(xenc,Fsp,Vrefp,n);

2. Simulation 2 (simulation2.sce)

//SCILAB program to simulate the ADC process on an audio signal


//The samples are stored into an audio wave (.wav) file
//NOTES:
//The maximum value for a .wav file is 1 and the minimum value is -1.
//Values outside -1 to 1 results in overflow
//Declare sampling frequency of ADC
Fs=8000;
//Declare the input signal
function xa=x(t);
xa=0.5*sin(1000*%pi*t);
endfunction;
//Simulate the ADC
//Generate the values for the sampling instants for 5 seconds duration
ts=0:1/Fs:5;

SLU ECE 13
ECE 515 FL
Digital Signal Processing Laboratory Activity 1: ADC and DAC

//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 ECE 14

S-ar putea să vă placă și