Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.

Similar presentations


Presentation on theme: "1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script."— Presentation transcript:

1 1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script Files or M-files

2 2 Basic Features Matlab is a tool for doing numerical computations with matrices and vectors. It can also display information graphically. The best way to learn to use Matlab is to run Matlab, trying the examples and experimenting.

3 3 Simple Math Matlab can be used as a calculator (Text in yellow is what you type, text in blue is what the computer “types” back): >> 2 + 4 + 6 ans = 12 >> 2 * 4 + 6*2 - 8/2 ans = 16

4 4 Operation and Symbol OperationSymbolExample Addition, a + b Subtraction, a – b Multiplication, a x b Division, a ÷ b Power, a + - * / ^ 2 + 3 5 - 4 3.14 *2.1 10/2.5 3^2

5 5 Expressions Expressions are evaluated from left to right with the power operation having the higher order of precedence, followed by both addition and subtraction having equal precedence Paratheses are used to alter this usual ordering. Evaluation initiates within the innermost parentheses and proceeds outward >>3^2 - 5 - 6 / 3*2 ans= 0

6 6 The Matlab Workspace Matlab remembers the command you enter as wellas the values of any variables you create. These command and variables are said to reside in the Matlab Workspace and can be recalled whenever you wish. >>a = 4 a = 4 >>a a = 4

7 7 Number Display Formats When a result is an integer, Matlab displays it as an integer. >> a = 4; >> b = 2; >> c = a*b; c = 8

8 8 Number Display Formats When a result is a real number, Matlab displays it with four digits to the right of t6he decimal point. >> a = 4; >> b = 2; >> c = a/b; c = 1.333

9 9 Variables in Matlab Variables are case sensitive (apple, Apple and APPLE). Variables can contain up to 19 characters. Variables must start with a letter, followed by any number of letters, digits, or underscores

10 10 When Matlab performs a calculation, it does so using the values it knows at the time the requested command is evaluated. >> a= 4; >> b= 3; >> c= a + b c= 7 >> b= 5; >> c= a + b c= 9

11 11 Variables in the Matlab workspace can be unconditionally deleted by using the command clear. >> clear a >> a ??? Undefined function or variable ‘a’ >> clear b >> b ??? Undefined function or variable ‘b’

12 12 Summary Matlab knows addition (+),substraction (-), multiplication (*), division (/), and power (^). Matlab evaluates expressions from left to right giving precedence to power over multiplication and division and these over addition and subtraction A semicolon(;) at the end of a Matlab statement suppresses printing of results. If statement too long, type three periods (…) followed by Enter to continue the Matlab statement on the next line.

13 13 Summary (cont.) As a default, Matlab stores results in the variable ans. Matlab remembers only the first 19 charactes of a variable name. Variable must begin with letter. Matlab is case sensitive. Comments in Matlab begin with %

14 14 Scientific Features Matlab offers many common functions important to mathematics, engineering, and the sciences. Matlab handles complex numbers

15 15 Common Mathematical Functions >> a=sqrt(9)/2 a = 1.5000 >> b=sin(a/2) b = 0.6816 >> c=round(a)*(b*180/pi) c = 78.1100

16 16 Complex numbers In matlab, the conversion between polar and rectangular form make use of the functions real, imag, abs, and angle: >> a=1-2i a = 1.0000 - 2.0000i >> abs(a) ans = 2.2361 >> real(a) ans = 1

17 17 >> imag(a) ans = -2 >> b_angle=angle(a) b_angle = -1.1071 >> b_degree=b_angle*180/pi b_degree = -63.4349

18 18 Script files, or M-files Matlab commands can be placed in a text file, called script or M-file. To create M-file choose New from the File menu and select M-file. This procedure brings up a text editor window. Commands within the M-file have acces to all variables in the Matlab workspace, and all variables created in the M-file become part of the workspace.

19 19 Matlab Graphics Creating Simple Plots Manipulating Plots

20 20 Creating Simple Plots Plots are a powerful visual way to interpret data Matlab has an extensive graphics capabilities

21 21 Case Study #1: y=sin( x ) Plot a sine function over one period: y = sin( x ) for 0≤ x ≤2π First we choose data point for the independent variable x. This data forms the horizontal axes of the plot. Then the sine of each data point is found – this provides the vertical axes of the plot. Each pair { x,y } is then marked on a suitable set of axes.

22 22 Case Study #1: y=sin( x ) (cont.) Matlab uses arrays to accomplish this task: >> x= linspace(0,2*pi,30); creates 30 points between 0 and 2π. >>y=sin(x); finds the sine of the point in x. >>plot(x,y) generates the plot.

23 23 Case Study #1: y=sin( x ) (cont.)

24 24 Case Study #1: y=sin( x ) (cont.) The Matlab function plot automatically chooses axis limits, Marks the individual data points, and Draws straight lines between them.

25 25 Options in the plot command allow us to plot multiple data sets on the same axes, Use different line types (dotted and dashes), Mark just the data points without drawing lines between them, Use different colors for curves, Place labels on the axes, a title on the top, Draw a grid at the tick marks.

26 26 >>z = cos(x); >>plot(x,y,x,z)

27 27 Plot 2sin(x)cos(x) using dashed lines >>plot(x,y,x,2*y*z,’--’)

28 28 Places a grid at the tick marks of the current plot. >>grid

29 29 Plots sine versus cosine >>plot(y,z)

30 30 Case Study #2:Plot the gain of the low pass filter versus the frequency. Given parameters are as follow: Range of the frequencies : 0Hz -100KHz. value of resistor and capacitor: R=10k ohm and C=0.0033µ Farads Cutoff frequency, ω=1/RC Theoretical Gain, G=1/√(1+(2πfRC)^2) Measured gain=[1 0.98 0.98 0.8 0.7.045 0.15 0.05] Frequencies at which gain were measured (Hz): =[100 300 1000 3000 4800 10000 30000 100000]

31 31 Case Study #2:Plot the gain of the low pass filter versus the frequency.(cont.) First you have to set the initial parameters >>f=0:100000; >>R=10000; C=3.3*10^(-9); Then calculate the theoretical cutoff frequency and theoretical gain >>fc=1/(2*pi*R*C); >>Gt=sqrt(1./(1+(2*pi*R*C.*f).^2)); Next, plot Gt versus f >> plot (f, Gt,’r’)

32 32 Case Study #2:Plot the gain of the low pass filter versus the frequency.(cont.)

33 33 EXERCISE SESSION


Download ppt "1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script."

Similar presentations


Ads by Google