31
EE 3350 MATLAB INTRODUCTION Instructor: Dr. Duncan MacFarlane Teaching Assistant: Yuan Hu

Simulation of a Radio Communication Channel

  • Upload
    vanphuc

  • View
    228

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Simulation of a Radio Communication Channel

EE 3350 MATLAB INTRODUCTION

Instructor: Dr. Duncan MacFarlane Teaching Assistant: Yuan Hu

Page 2: Simulation of a Radio Communication Channel

2

WHAT IS MATLAB?

• MATLAB is a numerical computing environment developed by MathWorks. • MATLAB allows matrix manipulations, plotting of functions and data, and implementation of algorithms. • MatLab program and script files always have filenames ending with ".m“. • The programming language is exceptionally straightforward since almost every data object is assumed to be an array.

Page 3: Simulation of a Radio Communication Channel

3

MATLAB WINDOWS

• We can type the commands in the command window. • As for programming, .m file script is preferred. File � New � Script

Page 4: Simulation of a Radio Communication Channel

GETTING HELP

� Online help is available from the Matlab prompt (a double arrow)

� ggenerally (listing all available commands): >> help

[a long list of help topics follows] � specific commands: >> help fft [a help message on the fft function follows].

Page 5: Simulation of a Radio Communication Channel

DATA REPRESENTATIONS IN MATLAB

� VVariables: Variables are defined as the assignment operator “=” . The syntax of variable assignment is

variable name = a value (or an expression) � Example:

Page 6: Simulation of a Radio Communication Channel

DATA REPRESENTATIONS IN MATLAB

� VVectors/Matrices : MATLAB can create and manipulate arrays of 1 ( vectors) , 2 (matrices), or more dimensions.

� row vectors: a = [1, 2, 3, 4] is a 1X4 matrix � column vectors: b = [5; 6; 7; 8; 9] is a 5X1 matrix � Example:

Page 7: Simulation of a Radio Communication Channel

ARITHMETIC OPERATIONS

� Five basic arithmetic operators

Page 8: Simulation of a Radio Communication Channel

ARITHMETIC OPERATIONS

� Three operators working on an element-by element basis.

The results of the three examples are the same as those of * / ^. But what will happen when it comes to the vector operations?

Page 9: Simulation of a Radio Communication Channel

VECTOR OPERATIONS

Consider the vectors:

The following operations indicate the resulting vectors:

Page 10: Simulation of a Radio Communication Channel

VECTOR OPERATIONS

EExamples: (1)Compute the dot product:

(2) Compute an element-by-element multiplication of two vectors:

Page 11: Simulation of a Radio Communication Channel

RELATIONAL & LOGICAL OPERATORS

Relational Operators Logical Operators

Page 12: Simulation of a Radio Communication Channel

CONTROL FLOW

� iif statements � for loops � while loops

.m files have the following control flow constructs:

Each of the constructs needs to terminate with an end statement.

Page 13: Simulation of a Radio Communication Channel

CONTROL FLOW iif: conditional execution of certain parts of a code

Matlab code:

Results:

Example:

Page 14: Simulation of a Radio Communication Channel

CONTROL FLOW ffor : repeat certain commands in a predetermined way

Matlab code:

Results:

Example:

Page 15: Simulation of a Radio Communication Channel

CONTROL FLOW wwhile: repeats a sequence of commands as long as some condition is met.

Matlab code:

Results:

Example:

Page 16: Simulation of a Radio Communication Channel

MATHEMATICAL FUNCTIONS IN MATLAB

� MATLAB offers many predefined mathematical functions for technical computing, e.g.

� CColon operator (:) Suppose we want to enter a vector x consisting of points (0,0.1,0.2,0.3,…,5).We can use the command

Page 17: Simulation of a Radio Communication Channel

FFT FUNCTION IN MATLAB � fft function uses the Fast Fourier transform algorithm to

compute Discrete Fourier transform. � SSyntax YY=fft(x) Y=fft(x,n) � Definition The functions Y=fft(x) and y=ifft(X) implement the transform

and inverse transform pair given for vectors of length N by:

Is an Nth root of unity

Page 18: Simulation of a Radio Communication Channel

FFT FUNCTION IN MATLAB

� DDescription Y =fft(x) returns the DFT of vector x, computed

with a fast Fourier transform algorithm. Y=fft(x,n) returns the n-point DFT. If the length of

x is less than n, x is padded with trailing zeros to length n. If the length of x is greater than n, the sequence x is truncated.

Page 19: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB � MATLAB has an excellent set of graphic tools. Plotting a given

data set or the results of computation is possible with very few commands .

� The MATLAB command to plot a graph is pplot(x,y), e.g.

� MATLAB enables you to add axis labels and titles, e.g.

Page 20: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB

Page 21: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB EExample 1: Sine Wave

Matlab code:

Page 22: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB EExample 1: Sine Wave

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1Sine Wave Signal

Time (s)

Am

plitu

de

Plot: signal in time domain

Page 23: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB EExample 1: Sine Wave

Plot: signal in frequency domain

-80 -60 -40 -20 0 20 40 60 800

10

20

30

40

50

60

70

80Spectrum of a Sine Wave

Frequency (Hz)

Am

plitu

de

Page 24: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB EExample 2:Multiplication of two Cosine Waves

f1 = 20; f2=10

Matlab code:

Page 25: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB EExample 2:Multiplication of two Cosine Waves

f1 = 20; f2=10

Plot: signal in time domain

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1Multiplication of two coine Wave Signals

Time (s)

Am

plitu

de

Page 26: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB EExample 2:Multiplication of two Cosine Waves

f1 = 20; f2=10

Plot: signal in frequency domain

-100 -80 -60 -40 -20 0 20 40 60 80 1000

10

20

30

40

50

60Spectrum of a Sine Wave

Frequency (Hz)

Am

plitu

de

Page 27: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB EExample 2:Multiplication of two Cosine Waves

What happens when f1=f2?

Page 28: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB EExample 2:Multiplication of two Cosine Waves

f1 = 10; f2=10

Plot: signal in time domain

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Multiplication of two coine Wave Signals

Time (s)

Am

plitu

de

Page 29: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB EExample 2:Multiplication of two Cosine Waves

f1 = 10; f2=10

Plot: signal in frequency domain

-100 -80 -60 -40 -20 0 20 40 60 80 1000

20

40

60

80

100

120Spectrum of a Sine Wave

Frequency (Hz)

Am

plitu

de

It has 3 spectrum components instead of 4. Why?

Page 30: Simulation of a Radio Communication Channel

BASIC PLOTTING IN MATLAB EExample 2:Multiplication of two Cosine Waves

f1 = 10; f2=10

Plot: signal in frequency domain

It has 3 spectrum components instead of 4. Why?

Hints:

1 2 1 21 2

cos(2 ( ) ) cos(2 ( ) )cos(2 ) cos(2 )2

f f t f f tf t f t � �� � � � �� �

Page 31: Simulation of a Radio Communication Channel