1. Homepage
  2. Programming
  3. ENG4052 Digital Communications 4 - Lab1: Bit Errors and Parity Checking

ENG4052 Digital Communications 4 - Lab1: Bit Errors and Parity Checking

Engage in a Conversation
UKThe University of GlasgowENG4052Digital Communications 4Bit Errors and Parity Checking

1 Digital Communications 4: Bit Errors and Parity Checking CourseNana.COM

1.1 Introduction CourseNana.COM

This laboratory project will introduce you to some issues that occur in digital communication CourseNana.COM

channels. In particular we will study the effects of additive white gaussian noise on the communication CourseNana.COM

channel and how its effects can be mitigated using a simple parity checking and CourseNana.COM

Automatic Repeat-reQuest (ARQ). In your previous laboratories on this course you will have CourseNana.COM

studied modulation formats. Here we will circumvent some of the low-level coding by using the CourseNana.COM

komm Python library https://pypi.org/project/komm/ to provide the appropriate functionality. CourseNana.COM

If you are using your own computer, make sure the Python libraries scipy, numpy, CourseNana.COM

matplotlib and pillow as well as komm are installed. It is recommended that you use a CourseNana.COM

suitable IDE for your project, such as Spyder. CourseNana.COM

Each project will be scheduled over a twoweek period, within which there will be 2 scheduled CourseNana.COM

online consultation sessions where you will be able to ask teaching staff for guidance. The project CourseNana.COM

should be written up as a short report describing what you’ve done and the results you have CourseNana.COM

taken along with any conclusions that you draw. Include your python code(s) in the appendices. CourseNana.COM

Make sure your name and student ID number is on the report. The report should be uploaded to CourseNana.COM

the Moodle assignment by the stated deadline, either using Moodle’s inbuilt html editor, or as a CourseNana.COM

single PDF file. CourseNana.COM

Figure 1: example 150 100 and 300 200 grayscale images CourseNana.COM

1.2 Obtaining Digital Data CourseNana.COM

A number of 8 bit depth grayscale images of various sizes have been provided for you to use CourseNana.COM

in this laboratory project. You may also consider the use of the numpy.random.randint() CourseNana.COM

command to create random binary streams for testing purposes. As the runtime depends on the CourseNana.COM

size of the data, you should generally use the smallest data set first, although in terms of accuracy CourseNana.COM

it may be advisable to use the larger datasets where the smallest images result in a small number CourseNana.COM

of bit errors, say . 25, to improve your accuracy in determining the bit-error-rate. CourseNana.COM

The following code reads in a grayscale image from a file to a 2 dimensional array of unsigned CourseNana.COM

integer values, and displays the image. If you are using Spyder, you can show graphics in CourseNana.COM

separate windows by setting Tools>Preferences>IPython console>Graphics>Backend CourseNana.COM

from Inline to Automatic. The unpackbits() command converts the integer values into a CourseNana.COM

flattened (1D) binary array. CourseNana.COM

import numpy as np CourseNana.COM

from PIL import Image CourseNana.COM

from matplotlib import pyplot as plt CourseNana.COM

import komm CourseNana.COM

tx_im = Image.open("DC4_150x100.pgm") CourseNana.COM

Npixels = tx_im.size[1]*tx_im.size[0] CourseNana.COM

plt.figure() CourseNana.COM

plt.imshow(np.array(tx_im),cmap="gray",vmin=0,vmax=255) CourseNana.COM

plt.show() CourseNana.COM

tx_bin = np.unpackbits(np.array(tx_im)) CourseNana.COM

1.3 Noisy Channel Simulation CourseNana.COM

Now we turn to the channel simulation which consists of 3 parts, namely (1) the channel coding, CourseNana.COM

(2) the transmission and reception over a noisy channel, and (3) the channel decoding. We shall CourseNana.COM

start with binary phase-shift keying (BPSK) which has two symbols. We will examine other CourseNana.COM

keying schemes with more symbols later. CourseNana.COM

The komm library provides functions for PSK modulation and demodulation and for simulating CourseNana.COM

an additive white gaussian noise source, as shown below. The modulated psk waveform CourseNana.COM

is by default unit average power. The scalar snr specifies the (linear) signal-to-noise ratio for CourseNana.COM

the channel, and the example below corresponds to 6 dB. tx_data and rx_data will consist of CourseNana.COM

complex arrays. CourseNana.COM

psk = komm.PSKModulation(2) CourseNana.COM

awgn = komm.AWGNChannel(snr=10**(6./10.)) CourseNana.COM

tx_data = psk.modulate(tx_bin) CourseNana.COM

rx_data = awgn(tx_data) CourseNana.COM

rx_bin = psk.demodulate(rx_data) CourseNana.COM

In Spyder, use the variable explorer and write down the value of Npixels, and the data type CourseNana.COM

and sizes of tx_bin, tx_data, rx_data and rx_bin. Check that the data types are correct, CourseNana.COM

and the comparison of the sizes of tx_data, rx_data to tx_bin, rx_bin corresponds to the CourseNana.COM

number of bits per symbol for the modulation scheme used. CourseNana.COM

1.4 Measuring Bit Error Ratio CourseNana.COM

Here we will investigate the influence of noise on the received data. An I-Q constellation CourseNana.COM

diagram can be displayed and inspected visually using the following where just the first 10000 CourseNana.COM

elements from rx_data is used so that the detail of the constellation is not obscured. CourseNana.COM

plt.figure() CourseNana.COM

plt.axes().set_aspect("equal") CourseNana.COM

plt.scatter(rx_data[:10000].real,rx_data[:10000].imag,s=1,marker=".") CourseNana.COM

plt.show() CourseNana.COM

You can also visually inspect the recovered image by rearranging the received data into a CourseNana.COM

decimal valued matrix corresponding to the original image dimensions, and using imshow as CourseNana.COM

you did previously. CourseNana.COM

rx_im = np.packbits(rx_bin).reshape(tx_im.size[1],tx_im.size[0]) CourseNana.COM

To determine the number of bit errors a bitwise comparison of the transmitted and received CourseNana.COM

binary matrices should be made, summing the case of unequal elements. The bit error ratio CourseNana.COM

(ber) is obtained by dividing the number of errors by the total number of bits, 8*Npixels. CourseNana.COM

Calculate the ber for a range of decibel values for the signal-to-noise ratio and plot them as ??? CourseNana.COM

(logarithmic axis) vs ??? in decibel. The following python code excerpt can be used to plot the CourseNana.COM

data contained in x and y arrays (same length) with a logarithmic vertical axis. CourseNana.COM

plt.figure() CourseNana.COM

plt.scatter(x, y) #plot points CourseNana.COM

plt.plot(x, y) #plot lines CourseNana.COM

plt.yscale("log") CourseNana.COM

plt.grid(True) CourseNana.COM

plt.show() CourseNana.COM

Include a curve showing the theoretical dependence for BPSK or QPSK, CourseNana.COM

1 CourseNana.COM

2 CourseNana.COM

erfc CourseNana.COM

√︂ CourseNana.COM

10??? ÅdBº.10 CourseNana.COM

? CourseNana.COM

where erfc is the complementary error function (available in the python scipy library, i.e. CourseNana.COM

scipy.special.erfc(x)) and ??? is the signal to noise in dB with ? bits per symbol. CourseNana.COM

1.5 Parity Check CourseNana.COM

In this task consider the data as consisting Npixels  8-bit words and replace the least significant CourseNana.COM

bit of each 8-bit word with a parity bit, which doesn’t make any discernable difference to your CourseNana.COM

view of the grayscale image. You are free to select whether you use even parity or odd parity: CourseNana.COM

setting the 8th bit to the modulo 2 (%2 in python) sum of the previous 7 bits corresponds to even CourseNana.COM

parity. CourseNana.COM

The parity test of the received data is done by looking at the modulo 2 sum of each 8-bit CourseNana.COM

word. If this is different from the parity setting you should do an Automatic Repeat-reQuest CourseNana.COM

(ARQ) and resend the word. Therefore you should amend your code to simulate the transmission CourseNana.COM

of an 8-bit word at a time as a step within a loop. Place a counter in your code to add up the CourseNana.COM

total number of ARQs. If you are unfamiliar with python, please note that control blocks, such CourseNana.COM

as initiated by CourseNana.COM

for i in range(start,stop,step): CourseNana.COM

are defined by indentation, that counters begin at i=start and the block is not executed for the CourseNana.COM

final value i=stop. CourseNana.COM

Visually inspect the received image and determine the bit error ratio. Plot the ??? as a CourseNana.COM

function of ??? in dB as before. Additionally plot the log of the ratio of the total number of CourseNana.COM

ARQs to the number of pixels as a function of ??? in dB. CourseNana.COM

Once you have obtained satisfactory results for BPSK format, repeat the exercise for Quadrature CourseNana.COM

Phase Shift Keying (QPSK) by setting CourseNana.COM

psk = komm.PSKModulation(4,phase_offset=np.pi/4) CourseNana.COM

Check that psk.bits_per_symbol is commensurate with your data array sizes. Note also that CourseNana.COM

the komm implementation uses gray coding by default (so that symbol errors will give rise to CourseNana.COM

mostly single-bit errors), which you can verify by inspecting psk.labeling. CourseNana.COM

1.6 QAM CourseNana.COM

Now adapt your code to undertake similar simulations with square QAM: 4-QAM (identical CourseNana.COM

to QPSK so verify that this matches the previous exercise), 16-QAM and 256-QAM. Again, CourseNana.COM

the komm implementation uses gray coding by default, which you can verify by inspecting CourseNana.COM

psk.labeling. The following code excerpts demonstrates the implementation of 4-QAM. CourseNana.COM

qam = komm.QAModulation(4,base_amplitudes=...) CourseNana.COM

tx_data = qam.modulate(...) CourseNana.COM

Check that qam.bits_per_symbol is commensurate with your data array sizes. base_amplitudes CourseNana.COM

is unity by default. However, to draw appropriate comparisons with PSK we should be CourseNana.COM

consistent with the average power per symbol (unity by default with PSK). Therefore inspect CourseNana.COM

the value qam.energy_per_symbol and set base_amplitudes to a value such that CourseNana.COM

qam.energy_per_symbol becomes unity. CourseNana.COM

1.7 Documentation CourseNana.COM

Python 3 https://docs.python.org/3/ CourseNana.COM

komm https://komm.readthedocs.io/en/latest/ CourseNana.COM

numpy and scipy https://docs.scipy.org/doc/ CourseNana.COM

matplotlib https://matplotlib.org/contents.html CourseNana.COM

pillow https://pillow.readthedocs.io CourseNana.COM

spyder https://docs.spyder-ide.org/ CourseNana.COM

Getting the python libraries CourseNana.COM

If you are using your own computer, make sure the Python libraries scipy, numpy, matplotlib CourseNana.COM

and pillow are installed. These libraries are installed by default with the Anaconda python CourseNana.COM

distribution. It is recommended that you use a suitable IDE for your project, such as Spyder. The CourseNana.COM

komm Python library is available from PyPI repository and, if required, can be installed using CourseNana.COM

pip. From a python-activated command line (such as Anaconda prompt), use the following CourseNana.COM

command to install in your user App config CourseNana.COM

pip install komm --user CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
UK代写,The University of Glasgow代写,ENG4052代写,Digital Communications 4代写,Bit Errors and Parity Checking代写,UK代编,The University of Glasgow代编,ENG4052代编,Digital Communications 4代编,Bit Errors and Parity Checking代编,UK代考,The University of Glasgow代考,ENG4052代考,Digital Communications 4代考,Bit Errors and Parity Checking代考,UKhelp,The University of Glasgowhelp,ENG4052help,Digital Communications 4help,Bit Errors and Parity Checkinghelp,UK作业代写,The University of Glasgow作业代写,ENG4052作业代写,Digital Communications 4作业代写,Bit Errors and Parity Checking作业代写,UK编程代写,The University of Glasgow编程代写,ENG4052编程代写,Digital Communications 4编程代写,Bit Errors and Parity Checking编程代写,UKprogramming help,The University of Glasgowprogramming help,ENG4052programming help,Digital Communications 4programming help,Bit Errors and Parity Checkingprogramming help,UKassignment help,The University of Glasgowassignment help,ENG4052assignment help,Digital Communications 4assignment help,Bit Errors and Parity Checkingassignment help,UKsolution,The University of Glasgowsolution,ENG4052solution,Digital Communications 4solution,Bit Errors and Parity Checkingsolution,