You are on page 1of 130

Ain Shams University

Faculty of Engineering
Electronics and Electrical Communications Engineering Department

Experiments Notes

For

Communications Laboratory
4th year

Prepared by:

Prof. Salwa H. Elramly

First semester

2021-2022
Table of Contents

C1: Introduction to LabVIEW & NI-USRP

C2: Line Coding

C3: Spectrum Analyzer

C5: Multirate DSP Systems

C6: DSP using MATLAB


AIN SHAMS UNIVERSITY

FACULTY OF ENGINEERING

ELECTRONICS AND COMMUNICATIONS ENG. DEPT.


(ECE)

COMMUNICATIONS LABORATORY

FOURTH YEAR

EXPERIMENT (C1)

INTRODUCTION TO LABVIEW AND NI-USRP

ATTENDANCE REPORT
C1: Introduction to LabVIEW and NI-USRP
Part 1: Introduction to LabVIEW

1-Introduction:
LabVIEW (Laboratory Virtual Instrument Engineering Workbench) is a graphical
programming language that uses icons instead of lines of text to create applications. In
contrast to text-based programming languages, where instructions determine the order
of program execution, LabVIEW uses dataflow programming, where the flow of data
through the nodes on the block diagram determines the execution order of the VIs and
functions. VIs, or virtual instruments, are LabVIEW programs that imitate physical
instruments. In LabVIEW, you build a user interface by using a set of tools and
objects. The user interface is known as the front panel. You then add code using
graphical representations of functions to control the front panel objects. This graphical
source code is also known as block diagram code.
LabVIEW programs are called virtual instruments, or VIs, because their appearance
and operation imitate physical instruments, such as oscilloscopes and multi-meters.
A VI contains the following two components:
• Front panel: Serves as the user interface.
• Block diagram: Contains the graphical source code that defines the functionality of
the VI.
As shown in Figure (1) simple add and subtract program the code in the block
diagram panel and user interface in the front panel to set inputs and see outputs.

Figure (1) - Add & Subtract VI

C1-1
1.1-Block Diagram Panel:
Block diagram panel contains the graphical source code that defines the functionality
of the VI to place objects on the block diagram, simply drag and drop them from
the Functions palette. The Functions palette automatically appears when you right-
click anywhere on the block diagram workspace it contains many functions,
constants, structures…etc. as shown in Figure (2).

Figure (2) – Functions palette

Functions palette contains many functions as:


a) Structure functions (for loop, while loop, case structure ...etc.) as shown in Figure (3-a)
b) Array functions (Array index, insert to array, Index array...etc.) as shown in Figure (3-b).
c) Comparison functions (If equal, If greater, If smaller…..etc.) as shown in Figure (3-c).

Figure (3) – a) Structures functions – (b) Array functions -(c) Comparison functions

C1-2
1.2-Front Panel:
The front panel window of the VI is the graphical user interface or GUI of a VI. The
front panel window contains a toolbar across the top and controls palette as shown in
Figure (4) that you can access by right-clicking anywhere on the front panel.

Figure (4) - Front panel

Controls palette contains many controls as:


a) Numeric controls (numeric control, numeric indicator, knob...etc.) as shown in Figure (5-a)
b) Boolean controls (push button, round led, square led …etc.) as shown in Figure (5-b).
c) Graph controls (waveform chart, digital waveform graph...etc.) as shown in Figure (5-c).

Figure (5) – (a) Numeric controls – (b) Boolean controls -(c) Graph controls

C1-3
1.3-Examples:
Example 1: Create a VI to add two Numbers
1) Start LabVIEW>>File>>New VI, front panel and block diagram panel appear.
2) Right click on anywhere on block diagram panel functions palette appears.
3) From numeric functions choose add block.
4) Right click on one of add block's inputs and choose create then control a control
block connected to one input.
5) Repeat step 4 to the other input of add block.
6) Right click on the output of add block and press create indicator.
Note: control refers to input and indicator refers to output.
7) Now the block diagram panel and the front panel is as shown in Figure (6)

Figure (6) -Adder

8) Enter x and y values in front panel and click the icon in the top left corner of
the front panel then result of addition will appear in "x+y" indicator.

Example 2: Create a VI to add '5' to a number if it is greater than '10' else


add '10'.
1) Start LabVIEW >> File>> New VI, front panel and block diagram appear.
2) Right click on anywhere on block diagram panel functions palette appears.
3) From comparison functions choose greater block it compares two numbers and returns
true if first number is greater than second number else it returns false.
Note: press ctrl+h on any block to know how it works.
4) Right click on first input of greater block and choose create then control (this for the
input number )
5) Right click on second input of greater block and choose create then constant and make
this constant =10.
6) From structures functions choose case structure.

C1-4
7) Connect output of greater block to the input of case structure as shown in Figure (7).

Figure (7) –Greater block followed by case structure


8) Drag& drop add block inside the case structure and connect its first input to input
number and other input to constant =5 in case of true and constant =10 in case of false
as shown in Figure (8).

Figure (8) –Example 2


9) Run code and check if it works correctly from front panel.
1.4-Code Style in LabVIEW
Googling the phrase “labview code style” will yield a number of sources for general
code style in LabVIEW. Whatever style you choose to follow, remember that your
code style should accomplish the following:
1. Consistency - All of your code should follow the same code style.

2. Readability -Your code should be user-friendly and easy to maintain.

3. Documented - Documentation should not be few and far between .Good


documentation not only comes in the form of free text labels (see the Decorations
palette, which is part of the Structures palette), but it also means good variable and
function names.
When incrementally designing a moderately complicated system, it can be tempting to
continually add hacks until you end up with spaghetti code (see Figure 9).

C1-5
Figure (9)-spaghetti code design can be messy

Any questions you might have about LabVIEW programming, the following tutorials
and reference material [1-2] will help guide you through the process of learning
LabVIEW:

2-Lab Experiment
In this experiment you will build two subVIs: source.vi and error detect.vi. You will
then plug your subVIs into a simulator provided to you (shown in Figure 10). The
goals of this pre-lab are:
(1) To practice LabVIEW programming.
(2) To understand how to build and use subVIs.

What is subVIs?
Modularity, by definition, means to use modules or smaller parts for the overall
objective. Within LabVIEW, program modularity means creating smaller sections of
code known as subVIs. SubVIs are the same as VIs. They contain front panels and
block diagrams, but you call them within a VI. A subVI is similar to a function in
text-based programming languages.

C1-6
. Figure (10)-Simulator block diagram

2.1-Create source SubVi:


1) Source.vi is responsible for generating random bit sequence, the details of sourve.vi are
given in Table (1). There are number of ways to generate random bit sequence in
LabVIEW. For instance, you could do it using the random number generator.
Table (1)
Inputs Length of bits sequence
Outputs Array of random bits

2) Open LabVIEW program then from "File" choose "New VI".


3) Press File >>save >>name it "lab1.1.vi"
4) At block diagram press right click then from Numeric function choose random number
generator block.
5) Random number generator block generates a fraction number from 0 to 1 to convert it to
bit generator (0 or 1) connect its output to round to nearest block from Numeric
function.
6) Right click on the output of round to nearest block then choose create indicator.
7) The code till now as shown in Figure (11).

Figure (11)-Random bit generator

8) Go to front panel and press run the random bit should appear at the front panel.
9) To generate a stream of random bits with certain length, go to block diagram and
choose from structures function for loop.
10) Right click on the letter "N" and choose create control to control the number of
iterations of for loop.

C1-7
11) Inside the for loop put random number generator block followed by round to
nearest block and connect output of round to nearest block to the right edge of for
loop as shown in Figure (12).

Figure (12)-Random bits generator


12) Right click on the output of for loop and then press create indicator.
13) Now the code looks as shown in Figure (13).

Figure (13)-Random bits generator

14) Go to front panel and enter Number of bits (for example 10) then press run
random bits appear as shown in Figure(14).

Figure (14)-Front panel view


15) To convert this code to SubVI select the for loop without Number Of bits &Array
blocks as shown in Figure (15) then press Edit >> create SubVI>>File>>save and
name it "source.vi"

Figure (15) - select subvi

C1-8
2.2-Create error detector SubVi:
Error detector aims to calculate bit error rate by comparing the transmitted bits
sequence and the detected bits sequence the details of error_detect.vi are given in
Table (2) there are number of ways to implement error detector SubVI in LabVIEW
for instance compare bit by bit between transmitted sequence and detected sequence.
Table (2)
Inputs Transmitted bit sequence
Detected bit sequence
Outputs Bit error rate

The block diagram Error detector is as shown in Figure (16).

Figure (16)-error detection block diagram

1) For loop takes bit by bit from the transmitted sequence and detected sequence then
compare between them using if equal block If transmitted bit and detected bit are
equal the output of if equal block is true and hence add zero to error, in case of
bits aren't equal output of if equal block is true and hence add one to error then
divide the number of error bits by the total number of bits by using divide block
to calculate BER.
2) To add shift register to the for loop right click on the for loop and then press add
shift register then right click on the right node of shift register and press create
constant and set this constant equals zero which is the initial value of error.

3) Now convert this code into subvi as shown previously and name it
"error_detect.vi"

C1-9
2.3-Simualte BPSK and QPSK vs SNR:
Now source.vi and error_detect.vi implemented successfully and ready to use with
simulator go to folder named "C1 " on desktop then replace source.vi and
error_detect .vi with yours vis.
1. Open awgn_simple.vi and check from block diagram panel that subvis are
connected successfully as shown in Figure (10)
2. Go to front panel and set the following parameters:
Modulation type="BPSK" Length =1000 Iterations =100
3. Vary the noise power from 0 dB to -10 dB with step -2 dB then run the code after
each step and fill the Table (3).
Table (3)
Noise power(dB) -0 -2 -4 -6 -8 -10
BER_BPSK

4. After each step check data symbols figure and received symbols figure on the
front panel then comment on what do you realize?

5. Repeat step (3&4) for QPSK modulation and fill Table (4).

Table (4)
Noise power(dB) -0 -2 -4 -6 -8 -10

BER_QPSK

6. Plot BER_BPSK &BER_QPSK vs SNR on the same Figure (17).


Note:
!"#$%&'!(&)*+!
SNR= !,&-"*!(&)*+!
, where symbol power = 0 dB so SNR (dB)= -Noise power(dB).

Figure (17)-BER vs SNR

C1-10
C1:Introduction to LabVIEW and NI-USRP

Part 2: Introduction to NI RF Hardware

Summary
In this part of the introductory lab you will learn about the NI RF hardware
to be used in the Wireless Communications Lab. You will acquaint yourself
with the relevant documentation and references available to you with regard
to the RF hardware. You will build some simple example VI’s from the NI
documentation and use some of the existing LabVIEW tools (e.g., RF Signal
Analyzer Demo Panel). In the final part of this lab you will explore some of
the VIs that you will use in future labs to control the RF hardware. This part
of Lab 1 introduces NI RF hardware as a tool for digital communication, and
gets you familiar with the help/documentation available for the hardware you
will be working with throughout the course.
In this lab, for the pre-lab, you are required to turn in only the questions
given in Section 2. There are no pre-lab VIs for this lab. As a part of the
lab session, you will construct two VIs by following the instructions given in
the NI documentation. The questions given in Section 3 need to be answered
during the lab only. Please do not submit the answers to these questions with
your pre-lab. At the end of this lab, you will submit a lab report, the details
of which are given at the end of this document.

1 RF Hardware in Wireless
Communications Lab
In this course you will use software recofigurable RF hardware from National
Instruments to build a digital communication system. This hardware can be
easily configured using LabVIEW. The RF Hardware used in the lab is the
National Instruments USRP (Universal Software Radio Peripheral). Figure 1
shows a USRP connected to a PC (running LabVIEW). This PC controls the
USRP through the gigabit ethernet cable connecting the two together. In this
section you will learn more about these modules.

C1-11
Lab C1: Part 2 Introduction to NI RF Hardware

Figure 1: Hardware setup in Wireless Communications Lab.

1.1 NI USRP (Transmit)


Let’s begin by taking a look at the NI USRP when acting as a transmitter.
The USRP receives a waveform from the host PC with 16 bits of resolution
sampled at up to 25 MSamples/second. This signal is upconverted to a radio
frequency (RF) before being sent to an amplifier and then transmitted over
the air. For more information on the NI USRP, please refer to the help files
associated with the USRP (Help⇒NI-USRP Help⇒Devices⇒NI USRP-
292x Specifications)

1.2 NI USRP (Receive)


The NI USRP is also capable of receiving, and does so in the following man-
ner. The received signal is mixed with a desired carrier frequency in order
to down-convert it to a complex IQ baseband signal sampled at 100 MSam-
ples/second. The digital signal is then downsampled to a rate specified by
the user and passed to the host PC for processing.
When the ADC of the NI USRP samples at the full digitizer rate
(100 MSamp/sec), it can acquire a bandwidth of 20 MHz. Sampling at
such a high rate with high resolution (14 bits) produces a large amount of
data. However, to acquire a signal with smaller bandwidth (a narrowband
signal), it is sufficient to sample at a rate twice that of the signal bandwidth1 .
1 This sampling rate is known as the Nyquist rate of the system. It is the minimum sampling
rate required to reproduce a bandlimited signal from discrete samples.

C1-12
Lab C1: Part 2 Introduction to NI RF Hardware

Decimation is the process of reducing the sampling rate of a discrete-time


signal. In practice, this entails applying an anti-aliasing filter and throwing
away some samples. The NI USRP features a digital down converter (DDC),
which allows it to perform decimation in hardware instead of in software
(which can be considerably slower).
Using the DDC, the USRP can acquire narrowband signals at sample
rates much less than the full digitizer rate (100 MSamp/sec), thus reducing
the memory required to store a waveform. For example, a waveform sam-
pled at 100 MSamp/sec for 1 second produces 100 times more data than the
same waveform sampled at 1 MSamp/sec. The effective sample rate of the
USRP (including DDC) ranges from a maximum of 25 MSamp/sec down to
200 kSamp/sec and is directly configurable by the user. For more information
on the NI USRP, please refer to the associated help files.

2 Pre-Lab Questions
Review the documentation for the USRP (Help⇒NI-USRP Help). You will
find that the help files found under Devices⇒NI USRP-292x Specifications
and Devices⇒ NI USRP-2920 contain the most comprehensive information
about the USRP. For a deeper understanding of the specifications, please refer
to the following documents:

• Bandwidth, Sample Rate and Nyquist Theorem [7]

• Understanding RF & Microwave Specifications - Part I [13]

• Understanding RF & Microwave Specifications - Part II [14]

Answer the following questions about the USRP after reading through the
help files.

1. What is the range of allowable carrier/center frequency supported by


the NI-USRP?

2. What is the maximum allowable bandwidth supported by the NI-USRP?

3. What is the maximum sampling rate of the NI-USRP?

4. Why do you think the DDC is implemented? What is its main benefit?

Answer the following general concept questions using [7], [13] and [14].

1. In your own words, describe what the bandwidth of an instrument is.

C1-13
Lab C1: Part 2 Introduction to NI RF Hardware

2. What is meant by the sampling rate of an instrument?


3. Why are these specifications important for designing a transmitter and receiver in a wireless
communications system?
3 Lab Experiment
3.1 Building a Basic Transmitter VI:
For the first task in this lab you will build a basic transmitter VI described below after
that we will go to build a basic receiver on the other PC.
1. Select Start ⇒Program ⇒National Instruments ⇒Lab VIEW 2010 ⇒ Lab VIEW to launch
LabVIEW the LabVIEW dialog appears.

2. Click New, choose Blank VI, and click OK to create a blank VI.

3. Display the block diagram by clicking it or selecting Window ⇒ Show Block Diagram.

4. Navigate to the NI USRP VIs on the Functions ⇒ Instrument I/O ⇒ Instrument Drivers⇒
NI-USRP⇒ TX palette then choose the four main block of USRP TX as follows:
• niUSRP Open TX Session VI.
• niUSRP Configure Signal VI.
• niUSRP Write TX Data (poly) VI.
• niUSRP Close Session VI

5. Now we are going to create the block diagram shown in Figure 4 by placing the four core VIs
on the block diagram in the order they appear in Figure 4.

6. Hover the cursor over the device name terminal on the niUSRP Open TX Session VI and right
click. Select Create⇒Control to create a front panel field where you specify the NI USRP
device name.

7. Hover the mouse tool over the IQ rate, carrier frequency, and gain terminals of the niUSRP
Configure Signal VI. Right-click each terminal and select Create⇒Control from the shortcut
menu to create frequency, IQ rate, and gain controls

8. Display the front panel by clicking it or selecting Window⇒Show Front Panel. Fields are
displayed in which you can specify a frequency, IQ rate, and gain.

Continuous waveform generation is controlled by means of a STOP button. A STOP button is


typically used within a While Loop. This example places a While Loop around the Write TX Data
VI so that signal generation continues until you click STOP. Build a While Loop and STOP button
by completing the following steps:

9. Display the block diagram by clicking it or selecting Window⇒Show Block Diagram.

10. Select the While Loop on the All Functions⇒Structures⇒While Loop.

C1-14
Lab C1: Part 2 Introduction to NI RF Hardware

Figure 4.Simpe TX block diagram

11. Enclose the niUSRP Write TX Data (Poly) VI in the While Loop.

12. Hover the mouse tool over the Loop Condition terminal of the While Loop then Right-click
the Loop Condition terminal and select Create Control from the shortcut menu to create a
STOP button on the VI front panel.

Now we need to produce a waveform to be transmitted. We will be transmitting a sinusoid at a


carrier frequency that is specified by the carrier frequency control. This means that the baseband
signal will be passing to the NI USRP is simply a constant signal. To generate this signal,
complete the following steps:

C1-15
Lab C1: Part 2 Introduction to NI RF Hardware

13. Place the Initialize Array function down on the block diagram. Right-click on the dimension
size input and select Create ⇒Constant then Double-click on the constant that was create and
change it to 1 (baseband signal =1).

14. Right-click on the dimension size input and select Create⇒Control.

15. Wire the output of the Initialize Array function block to the data input of the niUSRP Write
Tx Data (poly) VI.

16. Finally, wire the STOP button that was created for the While Loop to the end of data? Input of
the niUSRP Write Tx Data (poly) VI and select CDB from that VIs drop down menu.

Remember that in order to operate your transmitter VI, you must properly configure the
USRP IP Address for the USRP (an input to niUSRP Initialize.vi). You can find the IP addresses
for all of the USRP devices connected to your PC by using the NI-USRP Configuration Utility.
Once that is properly configured, set the rest of the parameters as follows and run the VI:

• Carrier frequency =1GHZ.


• IQ rate (samples/sec)=200K
• gain (dB)=20 dB.
• Dimension size=10000.
• active antenna=TX1.

3.1 Building a Receiver VI:

1. On the other PC open LabVIEW then Click New, choose Blank VI, and click OK to create a
blank VI.

2. Display the block diagram by clicking it or selecting Window ⇒ Show Block Diagram.

3. Navigate to the NI USRP VIs on the Functions ⇒ Instrument I/O ⇒ Instrument Drivers⇒
NI-USRP⇒ RX palette then choose the four main block of USRP TX as follows:
• niUSRP Open RX Session VI.
• niUSRP Configure Signal VI.
• niUSRP Initiate Signal VI.
• niUSRP Fetch RX Data (poly) VI.
• niUSRP Abort VI.
• niUSRP Close Session VI.

4. Connect the receiver block as shown in Figure 5.

To view the received baseband signal and test your transmitter and receiver you will graph the
real and complex parts of the signal acquired by niUSRP Fetch Rx Data (poly).vi. To do this:

5. Place two waveform graphs on the front panel of your VI. These can be accessed from the All
Controls tool palette in the Front Panel (All Controls⇒Graph⇒ Waveform Graph.vi).

C1-16
Lab C1: Part 2 Introduction to NI RF Hardware

6. Retrieve the real and imaginary waveform components from the Data output of niUSRP Fetch Rx
Data (poly).vi. Use Get Complex IQ Component.vi to retrieve these components from
IQWaveform. ThisVI can be accessed from the ALL Functions tool palette on the block diagram
(RF Communications Modulations Analog Utilities MT Get complex IQ Component.VI)

Figure 5. RX block diagram

7. On the block diagram, connect the terminal for each waveform graph to its corresponding
waveform for the real and imaginary parts of the acquired signal as shown in Figure 6. (Inside of
the While-Loop structure).

C1-17
Lab C1: Part 2 Introduction to NI RF Hardware

Figure 6. View of In-phase and quadrature Components


8. Set the parameters of the receiver to be as that of the transmitter as follows:

• Carrier frequency =1GHZ.


• IQ rate (samples/sec)=200K
• gain (dB)=20 dB.
• Number of samples =10000.
• active antenna=RX1.

9. Run Transmitter and Receiver VIs simultaneously view the IQ signal on the front panel of
Receiver VI.
Although the baseband signal transmitted from the Transmitter VI is constant equals 1 (In-phase =1,
Quadrature =0) we will receive sinusoidal In-phase and quadrature components on the receiver side.
This occurs because there is carrier frequency offset between the two USRPS used in transmitter and
receiver and can be discussed as follows:
1. Define  as the in-phase component,  as the quadrature component and  as the carrier
frequency of the transmitter. The transmitted signal can be represented as follows:


=  2
+ 2
.

2. The receiver local oscillator generates carrier frequency with frequency mismatch equals ∆
than that of the transmitter carrier frequency so the detection of in-phase component will be as
follows :

= 2 
2[ + ∆ ]
=
cos 2[2 + ∆ ]
+ cos 2 ∆
+ sin 2[2 + ∆ ]
+ sin 2 ∆

3. Then passing 
to low pass filter to get the detected in-phase component as follows:

ℎ ! ! =  cos2 ∆
+ sin 2 ∆

4. the detection of quadrature component will be as follows :


"
= 2 
2[ + ∆ ]
=
 sin 2[2 + ∆ ]
+  sin 2 ∆
−  cos 2[2 + ∆ ]
+  cos 2 ∆

5. Then passing "


to low pass filter to get the detected in-phase component as follows:

$%!& %& ! ! =  cos2 ∆


+ Isin2 ∆

6. If ∆ = 0 the detection of in-phase and quadrature will occur correctly as follows :


ℎ ! ! =  , $%!& %& ! ! = 

C1-18
Lab C1: Part 2 Introduction to NI RF Hardware

REFERENCES
[1] National Instruments LabVIEW 101, retrieved September 13, 2011, from http://www.ni.com/lv101.
[2] National Instruments, LabVIEW Fundamentals, August 2007, retrieved September 23, 2011, from
http://www.ni.com/pdf/manuals/374029c.pdf.
[3] R.W. Heath Jr., Digital wireless Communication: Physical layer exploration lab using the NI USRPTM, National
Technology & Science Press, 2012,

C1-19
Ain Shams University
Faculty of Engineering
Electronics & Communications Eng. Dept.

COMMUNICATIONS LABORATORY
FOURTH YEAR

Experiment (C2)

Line Coding

Attendance Report

You might also like