Lab Manual DC
Lab Manual DC
Lab Manual
Course Instructor:
Engr. Dr. Lubna Nadeem
1. Introduction to MATLAB
2. Continuous time and discrete time signal Generation & plotting in Matlab.
3. Analysis of Power Signals and Energy Signals and Power Spectral Density.
4. Analysis and implementation of sampling theorem (Nyquist criteria, under
sampling, over sampling), impulse and natural sampling
5. Implementation of NRZ and RZ line codes
6. Implementation of phase encoded and Multi-level binary codes.
7. Introduction to Simulink
8. Implementation of Sampling, Aliasing and Signal Reconstruction,
Quantization Error Associated With Analog-To-Digital Conversion Using
Simulink
Objective:
The purpose of this Lab is to review MATLAB for those that have used it before, and to provide a brief
introduction to MATLAB for those that have not used it before. This is a "hands-on" introduction.
After using this lab session, students should be able to:
➢ Enter matrices
➢ Perform matrix operations
➢ Make plots
➢ Use MATLAB functions
➢ Write simple m-files
Description:
MATLAB is an interactive program for numerical computation and data visualization. It was
originally developed in FORTRAN as a MATrix LABoratory for solving numerical linear algebra
problems. The original application may seem boring (except to linear algebra enthusiasts), but
MATLAB has advanced to solve nonlinear problems and provide detailed graphics. It is easy to
use, yet very powerful. A few short commands can accomplish the same results that required a
major programming effort only a few years ago. MATLAB features a family of add-on application-
specific solutions called toolboxes. These toolboxes allow you to learn and apply specialized
technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend
the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are
available include communications, signal processing, control systems, neural networks, fuzzy
logic, simulation, and many others.
The best way for you to get started with MATLAB is to learn how to handle matrices. Start
MATLAB and follow along with each example. You can enter matrices into MATLAB by entering
an explicit list of elements or generating matrices using built-in functions. You only have to follow
a few basic conventions: Separate the elements of a row with blanks or commas. Use a semicolon
“;” to indicate the end of each row. Surround the entire list of elements with square brackets “[
]”.
Consider the following vector, x (recall that a vector is simply a matrix with only one row or
column)
» x = [1,3,5,7,9,11]
x = 1 3 5 7 9 11
Notice that a row vector is the default. We could have used spaces as the delimiter between
columns
» x = [1 3 5 7 9 11]
x = 1 3 5 7 9 11
There is a faster way to enter matrices or vectors that have a linear pattern. For example, the
following command creates the previous vector
» x = 1:2:11 (here what does ‘2’ indicate? Will be discussed in proceeding lab sessions)
x = 1 3 5 7 9 11
Transposing a row vector yields a column vector ( 'is the transpose command in MATLAB)
» y = x'
y = 1 3 5 7 9 11
» save file_name
(Saving your variables does not remove them from your workspace; only clear can do that)
You can also save just a few of your variables
» save file_name x y z
» load file_name
Complex variables
»i
ans = 0 + 1.0000i
»j
ans = 0 + 1.0000i
» sqrt(-3)
ans = 0 + 1.7321i
Note that these variables (i and j) can be redefined (as the index in a for loop, for example), not
included in your course. Matrices can be created where some of the elements are complex and
the others are real
a = 2.0000 1.00000
+ 2.0000i -5.0000
b = [1 2 3;4 5 6]
b=123456
» c = a*b
» plot(x,z)
» xlabel('x')
» ylabel('z')
y(t) = 4 e-0.1 t We can solve this for a vector of t values by two simple commands
» t = 0:1:50;
» plot(t,y)
Signal’s representation
Examples: ─
Two-dimensional line and symbol plots are created with the plot command. In its simplest form
plot takes two arguments
>> plot(xdata,ydata)
where xdata and ydata are vectors containing the data. Note that xdata and ydata must be the
same length and both must be the same type, i.e., both must be either row or column vectors.
Additional arguments to the plot command provide other options including the ability to plot
multiple data sets, and a choice of colors, symbols.
Lab 01 (Tasks):
1. Consider the matrices A and B
𝟏 𝟐 𝟓 𝟔
𝑨=[ ] B= [ ]
𝟑 𝟒 𝟕 𝟖
Objective:
To learn plotting of signal in continuous and discrete domain. After this lab, student would be
able to plot the continuous time signal and discrete time signal.
Description:
MATLAB is very useful for making scientific and engineering plots. You can create plots of known,
analytical functions, you can plot data from other sources such as experimental measurements,
and you can analyze data, perhaps by fitting it to a curve, and then plot a comparison. MATLAB
also has powerful built-in routines for drawing contour and three-dimensional surface plots.
Lab 02 (Tasks):
1. Consider the matrix
v= 1 5
3 10
5 15
7 20
9 25
11 30
2. Write the command to access the first column of and to delete the second column of v
3. Plot the following signal x = 10sin π t for t = [-2:0.002:2]
4. Plot the DT sequences:
x = [2, 3, -1, 5, 4, 2, 3, 4, 6, 1]
5. Use Matlab to draw the graph of f (x) = x 2 − 2x − 3 on the interval [−1,3]
6. Generate following elementary DT signals: –
A. Unit Impulse
B. Unit Step
7. Plot the curves of sine function for five different phases and frequencies with different
colors. Also plot all these curves on single graph or figure.
University of Engineering and Technology, Taxila
Department of Telecom Engineering
Subject: Digital Communication Lab#03
Title:
Analysis of Power Signals and Energy Signals and Power Spectral Density.
Objective:
To find the power and energy of the signals. After this lab, student would be able to find the
power and energy of the signals and how to calculate power or energy of a signal using Matlab.
To plot the histogram, to find the PSD.
Description:
Power and Energy content of a signal is often calculated in signal processing for communication
applications. For any signal in discrete form, power and energy can be calculated using the
following equations
Lab 03 (Tasks):
Here T=duration of the signal, and x[n] denotes discrete samples of the signal at regular intervals
(The sampled signal contains N points stretching from 0 to N-1). “NORM” function in Matlab can
be utilized for calculating the power or energy content of a signal.
Task 01:
Task 02:
Objective:
To learn sampling with Nyquist criteria and understand aliasing phenomenon. After completing
this lab student must have strong knowledge of sampling.
Description:
To sample a continuous-time signal x(t) is to represent x(t) at a discrete number of points, t =
nTs , where Ts is the sampling period. The sampling theorem states that a band-limited signal
x(t) with bandwidth W can be reconstructed from its sample values x[n] = x[ nTs] if the sampling
frequency fs =1/Ts is greater than twice the bandwidth W of x(t) . Otherwise, aliasing would
result in x(t) . The minimum sampling rate of 2W for an analog band-limited signal is called the
Nyquist rate. A CT sinusoid containing a maximum frequency of Fmax must be sampled at a
sampling rate Fs > 2Fmax (Nyquist Rate) to avoid aliasing. If sampling rate is greater than Nyquist
Rate, then CT sinusoid can be uniquely recovered from its DT version.
MATLAB Code:
%sampling
t=-10:0.01:10;
T=4;fm=1/T;
x=cos(2*pi*fm*t);
subplot(2,2,1);plot(t,x,'linewidth',3);
xlabel('time');ylabel('amplitude');
grid;
title('input signal');
n1=-4:1:4;
fs1=1.6*fm;
fs2=2*fm;
fs3=8*fm;
x1=cos(2*pi*fm/fs1*n1);
subplot(2,2,2);stem(n1,x1,'linewidth',3);
xlabel('number of samples');ylabel('amplitude');
hold on;
subplot(2,2,2);plot(n1,x1,'linewidth',3);
xlabel('time');ylabel('amplitude');
grid;
title('under sampling');
n2=-5:1:5;
x2=cos(2*pi*fm/fs2*n2);
subplot(2,2,3);stem(n2,x2,'linewidth',3);
xlabel('number of samples');ylabel('amplitude');
hold on;
subplot(2,2,3);plot(n2,x2,'linewidth',3);
xlabel('time');ylabel('amplitude');
grid;
title('uniform sampling');
n3=-20:1:20;
x3=cos(2*pi*fm/fs3*n3);
subplot(2,2,4);stem(n3,x3,'linewidth',3);
hold on;
subplot(2,2,4);plot(n3,x3,'linewidth',3);
xlabel('number of samples');ylabel('amplitude');
xlabel('time');ylabel('amplitude');
grid;
title('over sampling');
Lab 04 (Tasks):
Task 1:
F1=1Hz
F2=3Hz
Using MATLAB, Plot the two signals for time range of -2sec to 2sec
Task 2:
Take sinusoidal signal having frequency of 2Hz. Sample this sinusoidal signal at sampling
frequency of 10Hz using the technique of natural sampling. Write down the Matlab code to
implement natural sampling for the above signal. On the output there must be three graphs
a. First graph must show the sinusoidal signal having frequency of 2Hz for t:0→1
b. Second graph must show the carrier (rectangular signal) signal having frequency of
10Hz
c. Third graph must show the resultant natural sampled signal
University of Engineering and Technology, Taxila
Department of Telecom Engineering
Subject: Digital Communication Lab#05
Title:
Objective:
To learn how to implement following NRZ line codes:
1. NRZ-L
2. NRZ-M
3. NRZ-S
1. Unipolar RZ
2. Bipolar RZ
3. RZ AMI
Description:
Non-return to zero encoding is commonly used in slow speed communications interfaces for both
synchronous and asynchronous transmission. Using NRZ, a logic 1 bit is sent as a high value and
a logic 0 bit is sent as a low value (the line driver chip used to connect the cable may subsequently
invert these signals).
Return-to-zero (RZ or RTZ) describes a line code used in telecommunications signals in which
the signal drops (returns) to zero between each pulse. This takes place even if a number of
consecutive 0s or 1s occur in the signal. The signal is self-clocking. This means that a separate
clock does not need to be sent alongside the signal, but suffers from using twice the bandwidth to
achieve the same data-rate as compared to non-return-to-zero format.
Unipolar RZ: 1 is represented by half duration pulse 0 zero level (absence of pulse)
Bipolar RZ: 1 is represented by half duration positive pulse .0 by half duration negative pulse
RZ AMI: 1 is represented by alternate positive and negative half duration pulses 0 by 0 level
(absence of pulse).
Lab 05 (Tasks):
Task 1:
Task 2:
Objective:
To learn how to implement following phase encoded line codes:
1. Bi-Phi-L
2. Bi-Phi-M
3. Bi-Phi-S
1. Dicode NRZ
2. Dicode RZ
Description:
Biphase encoding is a variation on polar encoding and is an effective answer to synhronisation
problems. Biphase encoding works by changing the signal in the middle of the bit interval,
however, the signal does not then return to zero it continues to the opposite pole. This mid-interval
change is perfect for synchronisation purposes.
1. Bi-Phi-L: Two consecutive bits of the same type force a transition at the beginning of a
bit period.
1 forces a negative transition in the middle of the bit
0 forces a positive transition in the middle of the bit
Task 2:
Introduction to Simulink
Lab#08
Title:
Objective:
Equipment List:
Pc with Matlab and Simulink.
Description:
Sampling
The time division Multiplexer (TDM MUX) module is used to recombine two analog signals
into one data stream. The input A is connected to the OUT connector for a period T (T = 1/fs).
During the next period, input B is connected to the OUT connector. The process then repeats.
It should be obvious that each input, input A (or B) is “Sampled” at a rate equal to ½ fs as set
by the Master clock.
NOTE: The actual waveform sampling rate = ½ fs as set by the “DATA/Sampling RATE”, output,
mentioned above (e.g. to sample a 1kHz cosine, using this equipment at the Nyquist rate then
fs would have to be set to 4 kHz)
Next the fs were set to 10 kHz and the function generator frequency was set to 1 kHz. The
output signal OUT was observed on a scope and was also compared with the input on a dual
channel scope. The value of fs was slightly adjusted for a stable display. The scope was moved
to the sample-and-hold (S & H) output. We see that the amplitude variations during the
sampled period are now replaced with a constant “flat top”.
The input signal looks like the one shown in figure below
The result when the input is overlapped with the output is what is shown below.
Next the function generator was connected to both the inputs A and B. at the OUT connector of the
TDM MUX, the generator’s signal appears undistorted. We see that after moving the scope to the S &
H connector the signal is now being sampled at fs.
Figure: Time Division Multiplexing - Implementation
A. Although multiplexing not classified as “data acquisition,” we shall make use of TDM
modules at this time. Two sine waves were prepared to be multiplexed by setting the
two VCO’s in open loop to 1 kHz and 2 kHz. Connect the 1 kHz sine wave to the A input
and 2 kHz since wave to the B input (see figure 7c). Set fs for 10kHz. The output OUT
and S & H outputs in time and frequency domain were observed. Yes, we can say that
sampling frequency for the TDM system is fs/2. (i.e half the time you sample A and
half the time you sample B)
B. The S & H signal was connected to the TDM DEMUX. Internal timing connects the TDM
DEMUX input signal to the A output when the A input signal is selected by the MUX.
Similarly, the B output is connected to the DEMUX input when the MUX selects input B.
Thus, the TDM signal becomes “demultiplexed”. The Dual LPF was used to reconstruct the
S & H DEMUX output waveforms. All the waveforms observed are attached.
The output of the decoder is fed to a subtractor block, which takes the difference of the input signal
from the output and gives the signal noise generated. The noise generated and the numeric value is:
Figure: Difference – Noise of the PCM
Lab#09
Title:
Lab#10
Title:
Lab#11
Title:
Lab#12
Title:
Lab#13
Title:
Lab#14
Title:
• PSK Modulator
• ASK Modulator
University of Engineering and Technology, Taxila
Department of Telecom Engineering
Lab#15
Title:
Lab#16 (a)
Title:
➢ PCM Encoder
• Analog to Digital Convertor
• Bit Encoder
• Parallel to serial converter
University of Engineering and Technology, Taxila
Department of Telecom Engineering
Lab#16 (b)
Title:
➢ PCM Decoder
• Serial to parallel converter
• Digital to Analog Converter