lab1

Upload: maheen-islam

Post on 09-Jan-2016

3 views

Category:

Documents


0 download

DESCRIPTION

Matlab Help

TRANSCRIPT

  • Signals and

    Systems Lab 1 Lab instructor : Maheen Islam

    Contact: [email protected]

    Signals And Systems Lab - Lab engineer Maheen Islam- Electrical Department-Air University 1

  • Announcements

    CR

    Class group-mail

    Manuals to be submitted in each lab and to be collected from office by CR before Friday every week.

    Lab manual to be followed

    Marks division

    Quizzes 6%

    Project 6%

    Lab Notebook 3%

    Assignments 3%

    Lab performance 2%

    Sig

    nals

    And S

    yst

    em

    s Lab -

    Lab e

    ngin

    eer

    Maheen Isl

    am

    -Ele

    ctr

    ical

    Depart

    ment-

    Air

    Univ

    ers

    ity

    2

  • Introduction

    Lab manual (individual)

    Matlab Excercises practiced in lab

    Submission in every Lab, Cr to collect manuals every Friday

    from office.

    Quiz (Unannounced Anytime in Lab)

    Assignments (done in manual)

    Project Submission

    Attendance within First 10 minutes

    Sig

    nals

    And S

    yst

    em

    s Lab -

    Lab e

    ngin

    eer

    Maheen Isl

    am

    -

    Ele

    ctr

    ical

    Depart

    ment-

    Air

    Univ

    ers

    ity

    3

  • Objective of the Lab

    Signals and systems analysis - a fundamental course

    with various topics having applications in many areas

    of engineering such as

    Sig

    nals

    And S

    yst

    em

    s Lab -

    Lab e

    ngin

    eer

    Maheen Isl

    am

    -Ele

    ctr

    ical

    Depart

    ment-

    Air

    Univ

    ers

    ity

    Signals and System

    Digital signal

    processing

    Communication

    systems

    Control engineering

    Image Processing

    Radar Engineering

    System-Design

    4

    Announcement Regarding Projects

    Project Proposal deadline: Week

    before mids.

    Failure of submission till

    deadline will result

    in deduction of 2%

    marks and a project

    will be assigned.

  • Flow of the Lab

    Introduction of Matlab

    Introduction of signals

    Difference of continuous time and discrete time signals, system properties

    Topics under focus

    Convolution, Fourier series, Continuous time Fourier transform (CTFT), discrete time Fourier transform (DTFT), Z- transform.

    Sig

    nals

    And S

    yst

    em

    s Lab -

    Lab e

    ngin

    eer

    Maheen Isl

    am

    -

    Ele

    ctr

    ical

    Depart

    ment-

    Air

    Univ

    ers

    ity

    5

  • Signals and Systems Labs

    Lab 1 GETTING STARTED WITH MATLAB

    Lab 2 LOOPS & DECISION MAKING

    Lab 3 WORKING WITH FUNCTIONS IN MATLAB

    Lab 4 HOW TO PLOT DIFFERENT FUNCTIONS IN MATLAB

    Lab 5 TRANSFORMATION OF SIGNALS IN MATLAB

    Lab 6 CONVOLUTION OF LTI SYSTEMS IN MATLAB

    Lab 7 FOURIER SERIES REPRESENTATION OF PERIODIC SIGNALS IN MATLAB

    Lab 8 FOURIER TRANSFORM OF DIFFERENT SIGNALS IN MATLAB

    Lab 9 Z-TRANSFORM & INVERSE Z-TRANSFORM

    Sig

    nals

    And S

    yst

    em

    s Lab -

    Lab e

    ngin

    eer

    Maheen Isl

    am

    -Ele

    ctr

    ical

    Depart

    ment-

    Air

    Univ

    ers

    ity

    6

  • GETTING STARTED WITH

    MATLAB

    Lab 1

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 7

  • Introduction

    Product by MathWorks

    Supported Platforms-Windows, MAC and LINUX

    Strong Online Help by MathWorks

    http://www.mathworks.com

    Versatile Tool

    Contains a large collection of built- in functions and commands used in

    an interactive mode, when you are in the command window

    Special Packages for disciplines like control systems, digital signal

    processing, communications engineering, and image processing.

    More than 20 sets known as toolboxes

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University

    8

    Numerical

    Computation

    Data

    Analysis

    Graphical

    Visualization

    Software

    and

    Hardware

    interface

  • Matlab GUI

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 9

    Command

    Window

    Matlab

    Workspace

    Current

    Folder

    Editor

    Window Simulink

    Figure Window- all figures and plots generated by plot commands

    appear in this window

  • Commands

    THE SAVE COMMAND: If you want to save the variables in the workspace before you quit, use the command SAVE. This automatically

    saves all the variables in a file called matlab.mat. When you enter

    MATLAB again, you can restore these variables with the command

    LOAD.

    clc COMMAND: It clears the command window during a work session.

    Clear COMMAND: It deletes all the variables in the workspace. All

    variables are cleared & cannot be retrieved.

    Help COMMAND: simplest way to determine the syntax & behaviour of

    a particular function.

    Try help whos

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 10

  • Notes

    Data type LESS language, caters everything in the form matrices

    MATLAB is case sensitive i.e; time, Time, TIME are three different variables.

    To recall previous commands MATLAB uses the up & down arrow keys.

    Keys are used to edit the commands.

    All text after percent sign (%) is taken as a comment statement.

    Multiple commands can be placed on one line if they are separated by commas (,) or semicolons (;).Commas tell MATLAB to display results, semicolons suppress printing.

    Ctrl+R => comment, ctrl+T=> uncomment

    If a statement does not fit on one line use three periods,, followed by Enter to indicate that the statement continues on the next line. The maximum number of characters allowed on a single line is 4096.

    You can interrupt MATLAB execution at any time by pressing CTRL+C.

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 11

  • Vector, Array and Matrices

    Notation used by Matlab is the standard linear algebra notation

    Vectors and scalars- special cases of a matrixall of which are represented as arrays in MATLAB

    A scalar is an array of 1 1 dimension

    A row vector is an array of 1 n dimension

    A column vector is an array of n 1 dimension.

    When elements of an array are typed in a row within square brackets,

    with a space between the elements, MATLAB displays it as a row vector

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 12

  • Vector, Array and Matrices

    Try it

    A = [1 2 0 3 1 5] % A row vector with name A

    [1 2 0 3 1 5] % will create a row vector with default name ans

    B=[1 2 0; 3 1 5; 0 4 -2] % will display a 3x3 matrix, each ; shows next row

    >> x = 5 % Real scalar

    >> x = 5+10j (or >> x = 5+10i) % Complex scalar

    >> x = [1; 2; 3] % Column vector

    Note

    Complex elements of a matrix should not be typed with spaces, i.e.,

    -1+2j is ne as a matrix element, -1 + 2j is not. Also, -1+2j is interpreted correctly whereas -1+j2 is not (MATLAB interprets the j2 as the name of a variable. You can always write -1+j*2

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 13

  • Matrix Operations-Arithmetic Operators Some more operations and their syntax

    Addition +

    Subtraction -

    Multiplication *

    Power or exponent ^

    Transpose e.g A

    Left division \

    Note: x=M\b gives solution to M*x=b solution is given by x = 1 b

    Right division /

    Note: x=M/b gives solution to x*M=b given by x=M* 1

    x = 5;

    F=x*C ;

    FF=C/x; % will give error at x/C as matrix dimension wont be matching,

    to cater this error use dot operator will be discussed later.

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 14

  • Matrix Operations-Relational Operators

    < less than

    greater than

    >= greater than or equal to

    == equal to

    ~= not equal to

    THE LOGICAL OPERATORS, e.g., & (and), | (or), and ~

    (not).

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 15

  • Matrix Operations Dot Operator:use a dot before the sign for the mathematical

    operation between the two matrices. e.g (.*), (./), (.^)

    Concatenation: A matrix can be expanded by adding new matrices

    and column or row vectors

    Colon Operator: : J:k IS THE SAME AS [ J, J+1 K] and J:K IS EMPTY IF J>K

    Try It:

    A=[1 2 1;0 1 1;2 1 1];

    B=[2 1 0;1 1 1;-1 2 1];

    F=[A B] % horizontal concatenate

    b=[5 4 2];

    G=[A;B;b]; % vertical concatenate

    G(7,2) %access element in 7th row, 2nd column

    G(7,2)=6 % change its value to 6

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 16

  • Matrix Operation

    Colon Operator:

    Can be used to extract a sub matrix from a matrix

    Q(:,2) gives a sub matrix with elements in all rows and the second column only.

    The command Q(3,:) gives the elements in all columns and the third row only.

    The command Q(1:2,2:3) gives the elements in the rows from 1 to 2 and in the columns from 2 to 3

    Q(:,:)

    rot90(A) Rotates the matrix array by 90?

    fliplr(A) Flips the columns left to right

    flipud(A) Flips the rows up to down

    triu(A) Gives the upper triangular part of the matrix

    tril(A) Gives the lower triangular part of the matrix

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 17

    it will return the whole matrix.

  • Few Special Matrices and Variables

    ones(m,n), which gives a matrix with the number one in all its m rows and n columns

    zeros(m,n), which gives a matrix with zeros in all its m rows and n columns

    eye(m), which gives the identity ma trix of order m m.

    Ans the default variable used for the most recent result. And this variable is also used as a default variable to store any value.

    Pi it has the value of 3.14

    Eps the smallest number such that when added to 1 creates a number greater than 1

    Inf stands for infinity (8 1/0)

    I or j i=j=v-1

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 18

  • Special Operations with

    Complex Numbers

    >> x = 3+4j % Complex scalar

    x >> real(x) = 3 % Real part

    x >> imag(x) = 4 % Imaginary part

    x >> abs(x) = 5 % Magnitude

    x >> angle(x) = 0.9273 % Angle

    x >> conj(x) = 3 - 4i % Complex conjugate

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 19

  • Pre-defined functions

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 20

    Try your self using Matlab Help. Included in course

  • Notes

    When we use the same variables used above but define

    them with new values, they become the current values

    for the variables

    Solve Exercise 1.91 from manual

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 21

  • Exercise-1.91

    1. Create a vector

    a) A of even whole numbers between 31 and 75.

    b) B of odd whole numbers between 74 and 131.

    2. Let x=[2 5 1 6];

    a) Add 16 to each element.

    b) Add 3 to the odd indexed element.

    c) Compute the square root of each element.

    d) Compute the square of each element.

    3. Let x = [3 2 6 8] and y = [4 1 3 5]

    a) Add the sum of the elements of x to y

    b) Raise each element of x to the power specified by the corresponding element of y.

    c) Multiply each element in x by the corresponding element in y and store the result in z.

    d) Evaluate x*y and interpret the result

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 22

  • Exercise-1.91

    4. given a vector t = [1:0.2:2] write down the MATLAB

    expressions that will correctly compute the following

    a) ln(2 + t + t2 )

    b) ( 1+ cos(3t) )

    c) cos2(t) + sin2(t)

    d) tan-1 (1)

    e) 1+2t

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 23

  • Practice Lab Task

    Create a matrix of dimensions 4x4.

    Find the number of diagonal entries and Add even

    number to each diagonal locations of the matrix.

    That is:

    A =

    1 2 3 4

    4 5 6 6

    7 8 9 0

    1 2 4 0

    Signals And Systems Lab - Lab engineer Maheen Islam-Electrical Department-Air

    University 24

    A =

    1 2 3 4

    4 7 6 6

    7 8 13 0

    1 2 4 6