0% found this document useful (0 votes)
24 views

Lab 9

Uploaded by

Hafiz Muhammad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Lab 9

Uploaded by

Hafiz Muhammad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

National University of Technology

Islamabad, Pakistan
Electrical Engineering Department

EXPERIMENT NO: 9
To understand sampling, analog to digital conversion, digital to
analog conversion and aliasing
OBJECTIVE:

To study the relationship between discrete-time and continuous time


signals by examining sampling and aliasing.

SAMPLING:
In signal processing, sampling is the reduction of a continuous signal to a discrete signal, as
shown in the following figure.

Nyquist Theorem:
It is one of the most important rules of sampling, which states that the highest frequency in a
signal which can be accurately represented is less than one-half of the sampling rate.
Mathematically,
f s f 2max
Where,
fs is the sampling frequency and fmax is the maximum frequency component present in the
signal. For example, if we want a full 20 kHz audio bandwidth, we must sample at least twice
that fast, i.e. over 40 kHz.

clc
clear all
close all
t=-100:01:100;
fm=0.02;
National University of Technology
Islamabad, Pakistan
Electrical Engineering Department
x=cos(2*pi*t*fm);
subplot(2,2,1);
plot(t,x);
xlabel('time in sec');
ylabel('x(t)');
title('continuous time signal');
fs1=0.02; n=-2:2;
x1=cos(2*pi*fm*n/fs1);
subplot(2,2,2);
stem(n,x1);
hold on
subplot(2,2,2);
plot(n,x1,':');
title('discrete time signal x(n) with fs<2fm’)
xlabel('n');
ylabel('x(n)');
fs2=0.04;
n1=-4:4;
x2=cos(2*pi*fm*n1/fs2);
subplot(2,2,3);
stem(n1,x2);
hold on
subplot(2,2,3);
plot(n1,x2,':');
title('discrete time signal x(n) with fs>2fm');
xlabel('n');
ylabel('x(n)');
n2=-50:50; fs3=0.5;
x3=cos(2*pi*fm*n2/fs3);
subplot(2,2,4);
stem(n2,x3); hold on
subplot(2,2,4);
plot(n2,x3,':');
xlabel('n');
ylabel('x(n)');
title('discrete time signal x(n) with fs=2fm');

Aliasing:
Aliasing is the phenomenon that results in loss of information when a continuous time signal
is reconstructed from its samples (and the Nyquist sampling theorem is violated).
The figure on the next page shows an alias.
National University of Technology
Islamabad, Pakistan
Electrical Engineering Department

There are two approaches to avoid aliasing. One is to raise the sampling frequency to satisfy
the sampling theorem. The other is to filter off the unnecessary high-frequency components
from the continuous-time signal. We limit the signal frequency by an effective low-pass filter,
called anti-aliasing prefilter, so that the highest frequency left in the signal is less than half
of the intended sampling rate.
1. Consider an analog signal x(t) consisting of three sinusoids of frequencies of 1 kHz, 4
kHz, and 6 kHz:
x(t)= cos(2πt)+ cos(8πt)+ cos(12πt)
where t is in milliseconds. Show that if this signal is sampled at a rate of fs = 5 kHz, it
will be aliased with the following signal, in the sense that their sample values will be
the same:
xa(t)= 3 cos(2πt)
On the same graph, plot the two signals x(t) and xa(t) versus t in the range 0 ≤ t ≤ 2
msec. To this plot, add the time samples x(tn) and verify that x(t) and xa(t) intersect
precisely at these samples. These samples can be evaluated and plotted as follows:
fs = 5;
T = 1/fs;
tn = 0:T:2;
xn = x(tn);
plot(tn, xn, ’.’);
2. Repeat part (a) with fs = 10 kHz. In this case, determine the signal xa(t) with which
x(t) is aliased. Plot both x(t) and xa(t) on the same graph over the same range 0 ≤ t ≤ 2
msec. Verify again that the two signals intersect at the sampling instants.

ALIASING EFFECT IN THE FREQUENCY DOMAIN

The relation between the continuous-time Fourier transform (CTFT) of an arbitrary


band limited continuous-time signal and the discrete-time Fourier transform (DTFT) of
the discrete-time signal is investigated next in this project. In order to convert a
continuous-time signal xa(t) into an equivalent discrete-time signal x[n], the former
must be band-limited in the frequency domain (see R5.2). To illustrate the effect of
sampling in the frequency domain we choose an exponentially decaying continuous-
time signal with a CTFT that is approximately band limited.

clear all
fm=input(‘Enter the Msg Frequency (fm)’);
t=0:0.00002:1;
National University of Technology
Islamabad, Pakistan
Electrical Engineering Department
xal=2*sin (2*pi*fm*t);
subplot (2, 2, 1);
plot (t, xal);
title (‘ Continuous sinusoidal signal’);
xlabel (‘ t ’);
ylabel(‘ x (t) ‘ ) ;
fsl = input ( ‘ Enter the sampling frequency greater than 2xfm’);
n = 0 : 1/fsl : 1;
xa2 = 2 *sin (2*pi*n*fm);
subplot (2, 2, 2);
stem (n, xa2);
title ( ‘ Above nyquist rate’);
xlabel (‘ n ‘);
ylabel ( ‘x (n)’) ;
fs2 = input (‘ enter the sampling frequency less than 2xfm’);
n1 = 0:1/fs2:1;
xa3 = 2*sin(2*pi*nl*fm);
subplot (2, 2, 3);
stem (n1, xa3);
title (‘ Under sampled case’);
xlabel (‘ n ‘);
ylabel (‘x (n) ‘ );
%ts2 = 1/50;
Fs3= input (‘Enter the sampling frequency equal 2xfm’);
n2 = 0:1/fs3:1;
clc;
xa4 = 2 sin (2*pi*n2*fm);
subplot (2, 2, 4);
stem (n2, xa4);
title (‘ At nyquist rate ‘);
xlabel (‘n’);
ylabel (‘x(n)’);

1. UPSAMPLING AND DOWNSAMPLING:

UPSAMPLING:
“Up sampling” is the process of inserting zero-valued samples between original
samples to increase the sampling rate. (This is called “zero-stuffing”.) Up sampling
adds undesired spectral images to the original signal which are centered on multiples
of the original sampling rate.

clc
clear all
National University of Technology
Islamabad, Pakistan
Electrical Engineering Department
close all
N=6;
U=2;
f=50;
n=0:N-1;
x=[1 2 3 4 5 6]
subplot(211)
stem(n,x)
y=zeros(1,U*length(x)-1);
y([1:U:length(y)])=x
n1=0:1/U:5
subplot(212)
stem(n1,y)

DOWNSAMPLING:
“Decimation” is the process of reducing the sampling rate. In practice, this usually
implies low pass-filtering a signal, then throwing away some of its samples.

Lab Tasks:

Q1. Run the codes described in section 3, 4 and 5.


Q2. Write a Program for up sampling an exponential sequence by a factor M
Q3. With the help of the code given above, write a code in which the sampling violates the
Nyquist Theorem. Also sketch an approximate signal.
___________________________________________________________________________

___________________________________________________________________________

___________________________________________________________________________

________________________

Q4. What are alias frequencies?

___________________________________________________________________________
National University of Technology
Islamabad, Pakistan
Electrical Engineering Department
___________________________________________________________________________

___________________________________________________________________________

__________________________

Q5. If the maximum frequency component in a signal is 40 hz, what should be the minimum

sampling frequency to avoid aliasing?

___________________________________________________________________________

_______________________________________________
National University of Technology
Islamabad, Pakistan
Electrical Engineering Department
Comments:

You might also like