Vous êtes sur la page 1sur 11

COMSATS Institute of Information Technology

Park Road, Islamabad Department of Electrical Engineering

Course Title: Digital Communications


Course code: EEE353 Semester: BS Electrical (Telecom) Engineering 7 Course Instructors: Dr. Shurjeel Wyne Lab Instructor: Noaman Naseer

Lab 1 Introduction to Communications Principles Using Matlab

Lab#1

DCS (EEE353) Fa2012

Overview
Everything in MATLAB is a matrix, thats why its matrix manipulation is fast and feasible. The primary goal of this lab is to familiarize you with Communication principles using Matlab. In this lab, you will: 1. Learn to write and edit your own script files in MATLAB, and run them as commands. 2. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization. 3. Perform Convolution and FFT operation in Matlab.

The following steps will introduce you to Matlab and Communication Principles in Matlab.

MATLAB Short Review:


(1) Complex numbers are natural in MATLAB. The basic operations are supported. Try the following: z = 3 + 4i, w = -3 + 4j real(z), imag(z) abs([z,w]) %<-- Vector constructor conj(z+w) angle(z) exp( j*pi )

Lab#1 exp(j*[ pi/4, 0, -pi/4 ])

DCS (EEE353) Fa2012

You will see that whatever you are typing in the command prompt, as it is evaluated; its results are shown on the screen. If a command is entered with a semi-colon (;) at the end, then its results are not shown on the screen.

MATLAB Array Indexing: (2) Make sure that you understand the colon notation. In particular, explain in words what the following MATLAB code will produce jkl = 0 : 6 jkl = 2 : 4 : 17 jkl = 99 : -1 : 88 ttt = 2 : (1/9) : 4 tpi = pi * [ 0:0.1:2 ];

(3) Extracting and/or inserting numbers into a vector is very easy to do. Consider the following definition of xx:

Lab#1 xx = [ zeros(1,3), linspace(0,1,5), ones(1,4) ] size(xx) length(xx) xx(2:2:length(xx)) yy = xx; yy(4:6) = pi*(1:3)

DCS (EEE353) Fa2012

Explain the results echoed from the last four lines of the above code.

(4) Plotting is easy in MATLAB for both real and complex numbers. The basic plot command will plot a vector y versus a vector x connecting successive points by straight lines. Try the following: x = [-3 -1 0 1 3 ]; y = x.*x - 3*x; plot( x, y ) z = x + y*sqrt(-1) plot( z ) %<---- complex values: plot imag vs. real Use help arith to learn how the operation xx.*xx works when xx is a vector; compare to matrix multiply.
When unsure about a command, use help.

Lab#1

DCS (EEE353) Fa2012

(5) Use the built-in MATLAB editor to create a script file called mylab1.m containing the following lines: tt = -1 : 0.01 : 1; xx = cos( 5*pi*tt ); zz = 1.4*exp(j*pi/2)*exp(j*5*pi*tt); plot( tt, xx, b-, tt, real(zz), r-- ), grid on %<--- plot a sinusoid title(TEST PLOT of a SINUSOID) xlabel(TIME (sec)) Explain why the plot of real(zz) is a sinusoid. What is its phase and amplitude? Make a calculation of the phase from a time-shift measured on the plot.

(6) Run your script from MATLAB. To run the file mylab1 that you created previously, try mylab1 %<---will run the commands in the file type mylab1 %<---will type out the contents of % mylab1.m to the screen

Convolution and Frequency analysis: (7) Now you will process signals in time domain and frequency domain.

Lab#1

DCS (EEE353) Fa2012

Any Linear Time Invariant (LTI) system is described by property of convolution. Convolution is the process by which input signal is modified by LTI system to produce output. Thus, output signal is convolution of input and impulse response of the system. So, in time analysis of signals and systems, output = input * impulse response, or

y (t) = x (t) * h (t)


When we view of system in frequency domain, convolution is transformed into multiplication. Thus, in Fourier domain, output spectrum is input spectrum multiplied with systems frequency response, i.e.

Y(f) = X(f) H(f)


Both processes are equal and valid; the only difference is domain of operation. In following lab, you will process signals in time as well as frequency domain. Few helpful functions to be used in this lab are:

fft

fftshift

abs

real

conv

If you dont know any of these functions, just type help <function name> in command window. Take care while dealing with imaginary numbers, you can not directly plot them. Either you plot their magnitude or real part, as per requirements.

Lab Tasks:

Lab#1

DCS (EEE353) Fa2012

Task A: Manipulating Sinusoids with MATLAB

In this task, you will generate sinusoids with different characteristics (amplitudes and frequencies), and their composite signal. Perform different steps as mentioned below. 1. Create a new m-file, name it to lab1.m, and perform clearance of variables & screen, and closure of all graphs. 2. Initialize amplitude and frequency vectors as 3. A=[2 3 1 1.5 2.5] 4. f= [1 10 2 5 12] 5. Create an appropriate time vector as t=start:increment:end; Choose your starting, incremental and ending time according to frequency, so that graphs are visible. 6. Generate 5 different signals with above amplitudes and frequencies. 7. Plot these signals on one figure using subplot function. You may use axis function to properly set the axis of figure. 8. Add up all these signals to get a composite signal. 9. Plot this signal on that figure too, using subplot. 10. Repeat all this, but this time you should use loop to generate different signals, and add them within loop to get composite signal.

Lab#1 Task B: Convolution and Frequency Analysis

DCS (EEE353) Fa2012

1) Generate two rectangular pulses of duration 1msec in time domain, plot them properly (properly define time index, their axis, title, and labels) 2) Convolve these two signals, and properly plot the result. 3) By processing in frequency domain, multiply both signals. You will have to convert both signals into Fourier domain, using fft function. 4) Convert back the output signal into time domain, and compare both outputs. 5) What is default value of samples taken by FFT? 6) What is zero padding? 7) What is relation between frequency resolution and number of samples? 8) How can we determine signal frequency from normalized spectrum produced by fft() functions.

Task-C 1. Write your own convolution function, myconv. Compare results of your written code, and available function conv. You will write your script in m-file and have to save it with the same name as of function name, e.g. myconv.m. For more help, see help

function.

Lab#1

DCS (EEE353) Fa2012

Lab#1

DCS (EEE353) Fa2012

Appendix A:
MATLAB is MATrix LABoratory, developed by Mathworks, and is extensively used in academia, research, and industry. This software is very heavily used in communication, signal processing, & control industry. Different toolbars available in MATLAB make it easy to use for different purposes. This is the basic tool that will be used throughout labs. MATLAB is installed on all computers, in the lab. After logging in, you can start MATLAB by double-clicking on a MATLAB icon, typing MATLAB/matlab in a terminal window, or by selecting MATLAB from a menu such as the START menu under Windows-XP/Fedora. Programming in MATLAB is sequential, and very like C language, and even much easier than that.

MATLAB Help
(a) Run the MATLAB help desk by typing helpdesk. The help desk provides a hypertext interface to the MATLAB documentation. Two links of interest are Getting Help (at the bottom of the right-hand frame), and Getting Started which is under MATLAB in the lefthand frame. (b) Explore the MATLAB help capability available at the command line. Try the following: help help plot

Lab#1 help colon %<--- a VERY IMPORTANT notation help ops help zeros lookfor filter %<--- keyword search

DCS (EEE353) Fa2012

Vous aimerez peut-être aussi