(18-37524-1 - D) DSP Lab Report 2
(18-37524-1 - D) DSP Lab Report 2
(AIUB)
Faculty of Engineering
Department of Electrical and Electronic Engineering
TITLE:
Submitted by:
NAME: SEN, SHUVRO SANKAR
ID: 18-37524-1 CONTACT:
SIGNATURE:
SUBMITTED TO:
TAHIA FAHRIN KARIM
FACULTY OF ENGINEERING
DEPARTMENT OF EEE
Introduction:
In many DSP applications, real world analog signals are converted into discrete signals using
sampling and quantization operations (collectively called analog-to-digital conversion or ADC).
These discrete signals are processed by digital signal processors, and the processed signals are
converted into analog signals using a reconstruction operation (called digital-to-analog
conversion or DAC).
Digital Digital
Input signal Input signal
To understand how the DSP system works, we need to know the relation between an analog
signal and its discrete time sampled version.
The objective of this laboratory is to illustrate the basic principles of sampling and
reconstruction. An analog signal will be generated and sampled using a defined sampling
frequency. Different reconstruction filters will be considered. The lab also examines the
representation of these signals in the frequency domain.
In time domain, relation between an analog signal and a sampled discrete time signal is given by
x(n) xa (nTs )
Where Ts is sampling interval. However, in the frequency domain, the relation between spectra of
analog signal and its discretized version is more complicated. Here we can use using Fourier analysis
to explain this relation and then address the reconstruction operation as follows:
X a (F) xa (t)e j2 Ft dt
xa (t) X a (F)e j2 Ft dF
X(f) x(n)e j2 fn
n
The inverse discrete time Fourier transform is given by
x(n) X ( f )e j2 fndf
Where Fs is a sampling frequency = 1/Ts. In other words, X(f) consists of infinite numbers of
copies of scaled Xa(F) separated by frequency interval f = 1. From the relation between discrete
time and analog frequencies
F
f
Fs
We get
F) Fs X a (F kFs )
X(
Fs k
F
in which X ( ) consists of infinite numbers of copies of scaled Xa(F) separated by
interval
F=Fs. Fs
Sampling Principle
In order to avoid aliasing, a band-limited signal xa(t) with bandwidth B can be reconstructed
from its sample values x(n) = xa(nTs) if the sampling frequency Fs= 1/Ts is greater than twice the
bandwidth B of xa(t).
Fs 2B
Otherwise aliasing would result in x(n). The sampling rate of 2B for an analog band-
limited signal is called the Nyquist rate.
© Dept. of EEE, Faculty of Engineering, American International University-Bangladesh (AIUB) 2
Experiment 2 Lab Manual
Reconstruction
From the sampling theorem and the above examples it is clear that if we sample band limited
xa(t) above its Nyquist rate, then we can reconstruct xa(t) from its samples x(n). Using
an interpolation formula:
xa (t) x(n)sin c(Fs (t nTs ))
n
sin( x)
Where sin c(x) is an interpolating function derived from an ideal low
pass
x
reconstruction filter. However, since an ideal low pass reconstruction filter cannot be
implemented, we usually estimated the ideal low pass filter by the following methods:
In this interpolation a given sample value is held for the sample interval until the next sample is
received.
xa (t) x(n), nTs t (n 1)Ts
which can be obtained by filtering the impulse train through an interpolating filter of
1 0 t Ts
h0 (t)
0 otherwise
In this case the adjacent samples are joined by straight lines. This can be obtained by filtering the
impulse train through
t
1 0 t Ts
T
s
t
h1 (t) Ts t 2Ts
1 Ts
0 otherwise
Pre-lab Homework:
The link is operated at 24,000bits/second and each input signal is quantized into 4096 different
voltage levels.
2) What is the sampling rate, sampling interval, folding frequency for this signal?
3) What is the discrete-time signal obtained after sampling? (Find out the simplest form)
4) Determine whether the discrete signal is periodic or not. Compute the fundamental period
if the signal is periodic.
5) What is the analog signal ya(t) that we can reconstruct from the samples if we use ideal
interpolation?
Apparatus:
1. Matlab
Precautions:
Use following matlab commands in the M-file before starting the lab.
1) Clear all
2) Close all
Experimental Procedure:
To study the effect of sampling on the spectrum of the discrete signal, we will sample at two
different sampling frequencies and then reconstruct the signals. Let xa (t) e 10t .The continuous
time Fourier transform is given by
2 *10
X a (F) .
2
10 (2 F)
The code has given in the appendices.
1. What is the MATLAB function that would be used to plot a staircase (ZOH) interpolation of the
analog signal?
2. What is the MATLAB function that would be used to plot a linear (FOH) interpolation of the
analog signal?
3. From the experiment, describe why the minimum sampling rate must be at least twice
the
bandwidth of an analog signal.
© Dept. of EEE, Faculty of Engineering, American International University-Bangladesh (AIUB) 6
Experiment 2 Lab Manual
Ans: Because of the finite time available , a sample rate somewhat higher than this is necessary.
4. Repeat the whole experimental procedure using Fs = 10 samples/sec. Explain why using Fs =
50 samples/sec is better than using Fs = 10 samples/sec. Locate the area where the spectra are
most likely to overlap other resulting in aliasing.
5. Consider an analog signal xa(t) = sin(20πt), 0 ≤ t ≤ 1. It is sampled at Ts = 0.01, 0.03, 0.05,
0.07 And 0.1 sec intervals to obtain x(n).
Codes Output
Analog signal and a) With Fs = 50 Hz
Sampled signal:
a) %Sampling xa(t) at Fs =
50 samples/sec.
clear all
tmin = -1;
tmax = 1;
% Analog signal
t = tmin:0.001:tmax;
xa = exp(-10*abs(t));
% Sampling rate
(sample/second)
Fs = 50
% Sample period
Ts = 1/Fs
% Discrete time signal
n = tmin/Ts:tmax/Ts;
x = exp(-10*abs(n*Ts));
%Display signals in time
domain
figure(1)
subplot(211)
plot(t,xa)
title('Analog and discrete
time signals')
xlabel('time (sec)')
ylabel('Analog signal
x(t)')
subplot(212)
© Dept. of EEE, Faculty of Engineering, American International University-Bangladesh (AIUB) 7
Experiment 2 Lab Manual
stem(n,x)
xlabel('n')
ylabel('Discrete time
signal x(n)')
b) %Sampling xa(t) at Fs =
10 samples/sec.
clear all
tmin = -1;
tmax = 1;
% Analog signal
t = tmin:0.001:tmax;
xa = exp(-10*abs(t));
% Sampling rate b) with Fs = 10 Hz
(sample/second)
Fs = 10
% Sample period
Ts = 1/Fs
% Discrete time signal
n = tmin/Ts:tmax/Ts;
x = exp(-10*abs(n*Ts));
%Display signals in time
domain
figure(1)
subplot(211)
plot(t,xa)
title('Analog and discrete
time signals')
xlabel('time (sec)')
ylabel('Analog signal
x(t)')
subplot(212)
stem(n,x)
xlabel('n')
ylabel('Discrete time
signal x(n)')
References:
Appendix A
%Sampling xa(t) at Fs = 50 samples/sec.
clear all
tmin = -1;
tmax = 1;
%ZOH Post-Filter
% Analog signal
t = tmin:0.001:tmax;
xa = exp(-10*abs(t));
% Sampling rate (sample/second)
Fs = 50
% Sample period
Ts = 1/Fs
% Discrete time signal
n = tmin/Ts:tmax/Ts;
x = exp(-10*abs(n*Ts));
%Display signals in time domain
figure(1)
subplot(211)
plot(t,xa)
title('Analog and discrete time signals')
xlabel('time (sec)')
ylabel('Analog signal x(t)')
subplot(212)
stem(n,x)
xlabel('n')
ylabel('Discrete time signal x(n)')
% Computing Fourier transform
% Analog frequency (Hert)
F = -100:0.1:100;
W = (2*pi*F);
%Discrete time frequency (Circle/sample)
f = F/Fs;
w = 2*pi*f;
xlabel('Freq (circle/sec)')
ylabel('X(F/Fs)')
subplot(313)
plot(f,abs(XF))
xlabel('Freq (circle/sample)')
ylabel('X(f)')
% Display spectra in the fundamental range
figure(3)
subplot(211)
plot(F,abs(XF))
title('Spectra in the fundamental range')
xlabel('Freq (circle/sec)')
ylabel('X(F/Fs)')
v = axis;
v(1:2) = [-Fs/2 Fs/2];
axis(v)
subplot(212)
plot(f,abs(XF))
xlabel('Freq (circle/sample)')
ylabel('X(f)')
v = axis;
v(1:2) = [-1/2 1/2];
axis(v)
%Reconstruction of xa(t).
t = tmin:0.001:tmax;
figure(4)
clf
subplot(211) hold
on
stem(n*Ts,x,'r')
for i = 1:size(x,2)
xsinc(i,:) = x(i)*sinc(Fs*(t -(i+min(n)-1)*Ts));
plot(t,xsinc(i,:))
end
title('Signal reconstruction')
xlabel('time (second)')
ylabel('x(n)*Sinc(Fs*(t-nTs))')
hold off
xar = sum(xsinc);
subplot(212)
plot(t,xar,'b-',t,xa,'r:')
legend('Reconstructed signal','Original signal')
ylabel('Reconstructed signal xa(t)')
xlabel('time (second)')
% reconstruction error
maxerror = max(abs(xa - xar));