exp-0 CS
exp-0 CS
11 | P a g e
At its core ,MATLAB is essentially a set (a “toolbox”) of routines (called “m files” or “mex
files”) that sit on your computer and a window that allows you to create new variables
with names (e.g. voltage and time) and process those variables with any of those
routines (e.g. plot voltage against time, find the largest voltage, etc).
It also allows you to put a list of your processing requests together in a file and
save that combined list with a name so that you can run all of those commands in the
same order at some later time. Furthermore, it allows you to run such lists of commands
such that you pass in data and/or get data back out (i.e. the list of commands is like a
function in most programming languages). Once you save a function, it becomes part of
your toolbox (i.e. it now looks to you as if it were part of the basic toolbox that you
started with). For those with computer programming backgrounds: Note that MATLAB
runs as an interpretive language (like the old BASIC). That is, it does not need to be
compiled. It simply reads through each line of the function, executes it, and then goes
on to the next line. (In practice, a form of compilation occurs when you first run a
function, so that it can run faster the next time you run it.)
The name MATLAB stands for matrix laboratory. MATLAB was originally written to
provide easy access to matrix software developed by the LINPACK and EISPACK projects.
Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the
state of the art in software for matrix computation. MATLAB has evolved over a period
of years with input from many users. In university environments, it is the standard
instructional tool for introductory and advanced courses in mathematics, engineering,
and science. In industry, MATLAB is the tool of choice for high-productivity research,
development, and analysis.
12 | P a g e
The main features of MATLAB
1. Advance algorithm for high performance numerical computation, especially in the Field matrix
Algebra.
2. A large collection of predefined mathematical functions and the ability to define one’s own
functions.
3. Two-and three dimensional graphics for plotting and displaying data.
4. A complete online help system.
5. Powerful, matrix or vector oriented high level programming language for individual
applications.
1.Command Window : This is the main window .It is characterized by MATLAB command
prompt >> when you launch the application PROGRAM MATLAB puts you in this window all
commands including those for user-written PROGRAMs ,are typed in this window at the MATLAB
prompt .
2.Graphics window: the OUTPUT of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background color
the user can create as many windows as the system memory will allow .
3. Edit window: This is where you write, edit, create and save your own PROGRAMs in files
called M files.
13 | P a g e
Data Type: the fundamental data–type in MATLAB is the array. It encompasses several
distinct data objects- integers, real numbers, matrices, character strings, structures and
cells. There is no need to declare variables as real or complex, MATLAB automatically
sets the variable to be real.
The functional unit of data in any MATLAB PROGRAM is the array. An array is a collection of
data values organized into rows and columns, and known by a single name.
MATLAB variable is a region of memory containing an array, which is known by a user specified
name. MATLAB variable names must begin with a letter, followed by any combination of letters,
numbers, and the underscore (_) character. Only the first 31 characters are significant; if more
than 31 are used, the remaining characters will be ignored. If two variables are declared with
names that only differ in the 32nd character, MATLAB will treat them as same variable.
Spaces cannot be used in MATLAB variable names, underscore letters can be substituted to
create meaningful names.
It is important to include a data dictionary in the header of any PROGRAM that you write. A
data dictionary lists the definition of each variable used in a PROGRAM. The definition should
include both a description of the contents of the item and the units in which it is measured.
The most common types of MATLAB variables are double and char.
MATLAB is weakly typed language. Variables are not declared in a PROGRAM before it is used.
MATLAB variables are created automatically when they are initialized. There are three
14 | P a g e
The semicolon at the end of each assignment statement suppresses the automatic
echoing of values that normally occurs whenever an expression is evaluated in an
assignment statement.
15 | P a g e
Basic Instructions in MATLAB:
10. stem (t,x) :- This instruction will display a figure window as shown
11. Subplot: This function divides the figure window into rows and columns. Subplot (2 2 1)
divides the figure window into 2 rows and 2 columns 1 represent number of the
figure
16 | P a g e
Subplot (3 1 2) divides the figure window into 3 rows and 1 column 2 represent the
figure number
12. Conv Syntax: w = conv(u,v) Description: w = conv(u,v) convolves vectors u and v.
Algebraically, convolution is the same operation as multiplying the polynomials whose
coefficients are the elements of u and v.
13. Disp Syntax: disp(X) Description: disp(X) displays an array, without printing the array name. If
X contains a text string, the string is displayed. Another way to display an array on the screen is
to type its name, but this prints a leading "X=," which is not always desirable.
Note: disp does not display empty arrays.
16. Title Syntax : title('string') Description: title('string') OUTPUTs the string at the top and in the
center of the current axes.
17. grid on Syntax : grid on Description: grid on adds major grid lines to the current axes.
17 | P a g e
18. FFT Discrete Fourier transform. FFT(X) is the discrete Fourier transform (DFT) of vector X. For
matrices, the FFT operation is applied to each column. For N-D arrays, the FFT operation operates on the
first non-singleton dimension. FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points
and truncated if it has more.
19. ABS Absolute value. ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is
the complex modulus (magnitude) of the elements of X.
20. ANGLE Phase angle. ANGLE (H) returns the phase angles, in radians, of a matrix with complex
elements.
21. INTERP Resample data at a higher rate using lowpass interpolation. Y = INTERP(X,L) resamples the
sequence in vector X at L times the original sample rate. The resulting resampled vector Y is L times
longer, LENGTH(Y) = L*LENGTH(X).
22. DECIMATE Resample data at a lower rate after low pass filtering.
Y = DECIMATE(X, M) resample the sequence in vector X at 1/M times the original
sample rate. The resulting resample vector Y is M times shorter, i.e., LENGTH(Y) = CEIL
(LENGTH(X)/M). By default, DECIMATE filters the data with an 8th order Chebyshev Type I low
pass filter with cutoff frequency .8*(Fs/2)/R, before resampling.
18 | P a g e