Date post: | 14-Apr-2017 |
Category: |
Education |
Upload: | prerna-rathore |
View: | 76 times |
Download: | 1 times |
An Industrial Training Report on MATLAB 1
INTRODUCTION TO MATLAB
Version-R2008b
MATLAB is a high level language for technical computing .It stands for MATrices Laboratory . It is interactive environment for computing, visualizing and programming .It is a purely algorithm based language , scientific , programming based language .With the use of MATLAB we can analyze data, create model and develop algorithm ,Process on signals, in communications, in
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 2
image processing, in speech processing and in control systems we use MATLAB as a tool.
Getting startedMATLAB is available on department machines. You can also download MATLAB for your personal machine from http://software.caltech.edu.Type “matlab” at the Unix prompt to start. This will open the MATLAB desktop, which includes interactive menus and windows in addition to the command window. You can also start a command prompt-only version of MATLAB (useful if you are logged in remotely) by typing “matlab –nodesktop”.
Using MATLABThe best way to learn to use MATLAB is to sit down and try to use it. In this handout are a few examples of basic MATLAB operations, but after you’ve gone through this tutorial you will probably want to learn more. Check out the “Other Resources” listed at the end of this handout. The Beginning When you start MATLAB, the command prompt “>>” appears. You will tell MATLAB what to do by typing commands at the prompt. Creating matrices the basic data element in MATLAB is a matrix. A scalar in MATLAB is a 1x1 matrix, and a vector is a 1xn (or nx1) matrix.For example, create a 3x3 matrix A that has 1’s in the first row, 2’s in the second row, and 3’s in the third row:>> A = [1 1 1; 2 2 2; 3 3 3]The semicolon is used here to separate rows in the matrix. MATLAB gives you:A =1 1 12 2 23 3 3If you don’t want MATLAB to display the result of a command, put a semicolon at the end:>> A = [1 1 1; 2 2 2; 3 3 3];Matrix A has been created but MATLAB doesn’t display it. The semicolon is necessary when you’re running long scripts and don’t want everything written out to the screen! Suppose you want to access a particular element of matrix A:>> A(1,2)ans =1
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 3
Suppose you want to access a particular row of A:>> A(2,:)ans =2 2 2The “:” operator you have just used generates equally spaced vectors. You can use it to specify a range of values to access in the matrix:>> A(2,1:2)ans =2 2You can also use it to create a vector:>> y = 1:3y =1 2 3The default increment is 1, but you can specify the increment to be something else:>> y = 1:2:6y =1 3 5Here, the value of each vector element has been increased by 2, starting from 1, whileless than 6. You can easily concatenate vectors and matrices in MATLAB:>> [y, A(2,:)]ans =1 3 5 2 2 2You can also easily delete matrix elements. Suppose you want to delete the 2nd element of the vector y:>> y(2) = []y =1 5MATLAB has several built-in matrices that can be useful. For example, zeros(n,n) makes an nxn matrix of zeros.>> B = zeros(2,2)B =0 00 0A few other useful matrices are:zeros – create a matrix of zerosones – create a matrix of onesrand – create a matrix of random numbers
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 4
eye – create an identity matrixMatrix operationsAn important thing to remember is that since MATLAB is matrix-based, themultiplication operator “*” denotes matrix multiplication. Therefore, A*B is not the same as multiplying each of the elements of A times the elements of B. However, you’ll probably find that at some point you want to do element-wise operations (array operations). In MATLAB you denote an array operator by playing a period in front of the operator. The difference between “*” and “.*” is demonstrated in this example:>> A = [1 1 1; 2 2 2; 3 3 3];>> B = ones(3,3);>> A*Bans =3 3 36 6 69 9 9>> A.*Bans =1 1 12 2 23 3 3Other than the bit about matrix vs. array multiplication, the basic arithmetic operators in MATLAB work pretty much as you’d expect. You can add (+), subtract (-), multiply (*), divide (/), and raise to some power (^).MATLAB provides many useful functions for working with matrices. It also has many scalar functions that will work element-wise on matrices (e.g., the function sqrt(x) will take the square root of each element of the matrix x). Below is a brief list of useful functions. You’ll find many, many more in the MATLAB help index, and also in the “Other Resources” listed at the end of this handout.Useful matrix functions:A’ – transpose of matrix A. Also transpose(A).det(A) – determinant of Aeig(A) – eigenvalues and eigenvectorsinv(A) – inverse of Asvd(A) – singular value decompositionnorm(A) – matrix or vector normfind(A) – find indices of elements that are nonzero. Can also pass an
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 5
expression to this function, e.g. find(A > 1) finds the indices of elements ofA greater than 1.
A few useful math functions:
sqrt(x) – square root
sin(x) – sine function. See also cos(x), tan(x), etc.
exp(x) – exponential
log(x) – natural log
log10(x) – common log
abs(x) – absolute value
mod(x) – modulus
factorial(x) – factorial function
floor(x) – round down. See also ceil(x), round(x).
min(x) – minimum elements of an array. See also max(x).
besselj(x) – Bessel functions of first kind
MATLAB also has a few built-in constants, such as pi (π) and i (imaginary number). Symbolic math Although MATLAB is primarily used for numerical computations, you can also do symbolic math with MATLAB. Symbolic variables are created using the command “sym.”>> x = sym(‘x’);Here we have created the symbolic variable x. If it seems kind of lame to you to have to type in all this just to create “x”, you’re in luck—MATLAB provides a shortcut.>> syms xThis is a shortcut for x = sym(‘x’).Symbolic variables can be used for solving algebraic equations. For example, suppose we want to solve the equation “x^4 + 3*x^2 + 3 = 5”:>> y = solve('x^4 + 3*x^2 + 3 = 5',x)y =-1/2*(-6+2*17^(1/2))^(1/2)1/2*(-6+2*17^(1/2))^(1/2)-1/2*(-6-2*17^(1/2))^(1/2)
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 6
1/2*(-6-2*17^(1/2))^(1/2)Since MATLAB is solving for x, a symbolic variable, it writes the answer in symbolic form. That means that the solutions is written out as an expression rather than computed as a decimal value. If you want the decimal value, you need to convert to a double:>> double(y)ans =-0.74940.74940 - 1.8872i0 + 1.8872iHowever, sometimes you may want to see the symbolic expression. In that case, you might want MATLAB to write it out in a way that’s easier to read. For this, use the command “pretty”:>> pretty(y)[ 1/2 1/2][- 1/2 (-6 + 2 17 ) ][ ][ 1/2 1/2 ][ 1/2 (-6 + 2 17 ) ][ ][ 1/2 1/2][- 1/2 (-6 - 2 17 ) ][ ][ 1/2 1/2 ][ 1/2 (-6 - 2 17 ) ]Below are a few useful things you can do with symbolic variables in MATLAB. For more, look at the “Symbolic Math Toolbox” section of the MATLAB help.solve – symbolic solution of systems of algebraic equations
int(f,x) – indefinite integral of f with respect to x
int(f,x,a,b) – definite integral of f with respect to x from a to b.
diff(f,’x’) – differentiate f with respect to x
taylor – Taylor series expansion of symbolic expression
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 7
Features of Matlab
It is easy to learn.
It is an oop (object oriented programming) language.
It has less syntax so less errors.
In Matlab there is no need of declare data types and variable.
It can be use as a programming language.
Errors are interpreted by MATLAB.
We can simulate, model and control with help of Matlab.
Different types of windows according to their use are following Command Windows
Command History
Current Directory
Workspace
Figure Editor
Editor
Command Window- Command Window The window where you type commands and non-graphic output is displayed. A ‘>>’ prompt shows you the system is ready for input. The lower left hand corner of the main. window also displays ‘Ready’ or ‘Busy’ when the system is waiting or calculating. Previous commands can be accessed using the up arrow to save typing and reduce errors. Typing a few characters restricts this function to commands beginning with those characters.
Workspace- Shows the all the variables that you have currently defined and some basic information about each one, including its dimensions, minimum, and maximum values. The icons at the top of the window allow you to perform
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 8
various basic tasks on variables, creating, saving, deleting, plotting, etc. Double-clicking on a variable opens it in the Variable or Array Editor. All the variables that you’ve defined can be saved from one session to another using File>Save Workspace As (Ctrl-S). The extension for a workspace file is .mat.
Command History-Records commands given that session and recent sessions. Can be used for reference or to copy and paste commands.
Current directory- The directory (folder) that MATLAB is currently working in. This is where anything you save will go by default, and it will also influence what files MATLAB can see. You won’t be able to run a script that you saved that you saved in a different directory (unless you give the full directory path), but you can run one that’s in a sub-directory. The Current Directory bar at the top centre of the main window lets you change directory in the usual fashion — you can also use the UNIX commands cd and pwd to navigate through directories. The Current Directory window shows a list of all the files in the current directory.
Editor-The window where you edit m-files — the files that hold scripts and functions that you’ve defined or are editing — and includes most standard word-processing options and keyboard shortcuts. It can be opened by typing edit in the Command Window. Typing edit myfile will open myfile.m for editing. Multiple files are generally opened as tabs in the same editor window, but they can also be tiled for side by side comparison. Orange warnings and red errors appear as underlining and as bars in the margin. Hovering over them provides more information; clicking on the bar takes you to the relevant bit of text. Also remember that MATLAB runs the last saved version of a file, so you have to save before any changes take effect.
Figure Editor-MATLAB opens figures in separate windows, which includes the ability to fine-tune the appearance of the plot, zoom, etc. You can also use the Data Cursor to extract values and save them to the Workspace. See the Help
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 9
documentation for further detail. The figures can also be saved in a wide variety of formats — it’s usually a good idea to save them as an m-file (File>Generate M-file) if there’s any chance at all you might want to modify the figure later and you haven’t already saved the generating code in a m-file.
Different types of files in Matlab
.m files-when we write program and store in matlab the program is stored in .m extension.
M-files and functions
If you are doing a computation of any significant length in MATLAB, you will probably want to make an m-file. Anything that you would type at the command prompt you can put in the m-file (for example, “script.m”) and then run it all at once (by typing the name of the m-file, e.g. “script”, at the command prompt). You can even add comments to your m-file, by putting a “%” at the beginning of a comment line. You can also use m-files to create your own functions. For
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 10
example, suppose you want to make a function that increments the value of each element of a matrix by some constant. And suppose you want to call the function “incrementor.” You would make an m-file called “incrementor.m” containing the following:function f = incrementor(x,c)% Incrementor adds c to each element in the matrix x
.mat files- MAT-files are double-precision, binary , MATLAB format files. They can also be manipulated by other programs external to MATLAB.
.fig files-It is extension of figure or graphical or interface files created in matlab.
.asv files –It is auto save file or back up files which are automatically saved along with our original files as a backup.
Desktop Tools and Development EnvironmentCommand Work
exit - Terminates the current MATLAB session.
quit -Terminates the current MATLAB session.
Clc- Clear Command Window
Commandhistory- Open Command History window, or select it if already open.
diary -Save session to file.
Clear- Removes all variables from the workspace. This frees upsystem memory.
help -Help lists all primary help topics in the Command Window
exist- Check existence of variable, function, directory, or Java class
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 11
dir- Directory listing.
What- List MATLAB files in current directory.
Operations in MATLAB:
+ Addition
+ Unary plus
- Subtraction
- Unary minus
* Matrix multiplication
^ Matrix power
\ Backslash or left matrix divides
/ Slash or right matrix divide
' Transpose
.' Nonconjugated transpose
.* Array multiplication (element-wise)
.^ Array power (element-wise)
.\ Left array divide (element-wise)
./ Right array divide (element-wise)
Data Analysis commands in MATLAB
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 12
mean:- mean (A) returns the mean values of the elements along different dimensions of an array.
median:- returns the median values of the elements along different dimensions of an array.
conv:- 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.
convn:- convn(A,B) computes the N-dimensional convolution of the arrays A and B. The size of the result is size(A)+size(B)-1.
deconv:- deconv(v,u) deconvolves vector u out of vector v, using long division. The quotient is returned in vector q and the remainder in vector r such that v = conv(u,q)+r .
poly:- poly(r) where r is a vector returns a row vector whose elements are the coefficients of the polynomial whose roots are the elements of r.
polyval:- polyval(p,x) returns the value of a polynomial of degree n evaluated at x.
polyvalm:- polyvalm(p,X) evaluates a polynomial in a matrix sense. This is the same as substituting matrix X in the polynomial p.
roots:- returns a column vector whose elements are the roots of thepolynomial c.
fft:-Discrete Fourier transform.
fft2:-2-D discrete Fourier transform.
fftn:-N-D discrete Fourier transform.
ifft:-Inverse discrete Fourier transform.
ifft2:-2-D inverse discrete Fourier transform.
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 13
ifftn:-N-D inverse discrete Fourier transform.
Graphics commands:
plot:- plot(Y) plots the columns of Y versus their index if Y is a real number.
plot3:- The plot3 function displays a three-dimensional plot of a set of datapoints.
subplot:- divides the current figure into rectangular panes that are numberedrow wise. Each pane contains an axes object. Subsequent plots are output tothe current pane.
stem: - Plot discrete sequence data.
3-D Visualization Commands:-
surf:- surf(Z) creates a three-dimensional shaded surface from the z
components in matrix Z.
mesh:- mesh, meshc, and meshz create wireframe parametric surfaces
specified by X, Y, and Z, with color specified by C.
colormap:- A colormap is an m-by-3 matrix of real numbers between 0.0
and Each row is an RGB vector that defines one color.
zoom:-Turn zooming on or off or magnify by factor.
rotate3d:- Rotate 3-D view using mouse.
xlabel, ylabel, zlabel:-Label x-, y-, and z-axis.
contour:-Contour plot of matrix.
contour3:- 3-D contour plot.
hist:-Histogram plot.
sphere:-Generate sphere.
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 14
MATLAB Toolboxes: Toolboxes are collections of functions etc. for tackling particular classes of problems. They have to be purchased separately to use with MATLAB to increase its capabilities.
MATLAB contains the following Toolboxes:
SIMULINK Toolbox
Image Processing Toolbox
Control Systems Toolbox
Signal Processing Toolbox
Fuzzy Logic Toolbox
Neural Networks Toolbox
Optimisation Toolbox
Statistics Toolbox
Symbolic maths Toolbox
Mapping Toolbox
Wavelet and many more.
IMAGE PROCESSING IN MATLAB
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 15
Image processing toolbox:
Image: An image may defined as a 2-dimensional function, f (x,y), where x & y
are spatial (plane) coordinates, & the amplitude of f at any pair of coordinates (x,y) is called the intensity or gray level of the image at that point. When x,y & the amplitude values of f are all finite, discrete quantities, we call the image as Digital image.
A digital image differs from a photo in that the values are all discrete.
A digital image can be considered as a large array of discrete dots, each of which has a brightness associated with it. These dots are called picture
elements, or more simply pixels.
Image processing
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 16
An image processing refers to processing images by means of various algorithms.
A digital image processing refers to the processing of digital images by means of digital computer.
Formats of Images in MATLAB
MATLAB can import/export several image formats
BMP (Microsoft Windows Bitmap)
GIF (Graphics Interchange Files)
HDF (Hierarchical Data Format)
JPEG (Joint Photographic Experts Group)
PCX (Paintbrush)
PNG (Portable Network Graphics)
TIFF (Tagged Image File Format)
XWD (X Window Dump)
MATLAB can also load raw-data or other types of image data
Data types in MATLAB
1. Double (64-bit double-precision floating point)
2. Single (32-bit single-precision floating point)
3. Int32 (32-bit signed integer)
4. Int16 (16-bit signed integer)
5. Int8 (8-bit signed integer)
6. Uint32 (32-bit unsigned integer)
7. Uint16 (16-bit unsigned integer)
8. Uint8 (8-bit unsigned integer)
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 17
IMAGE IN MATLAB
• Binary images : {0,1}
• Intensity images : [0,1] or uint8, double etc.
• RGB images : m-by-n-by-3
• Indexed images : m-by-3 color map
• Multidimensional images m-by-n-by-p (p is the number of layers)
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 18
Image import and export
Read and write images in Matlab >> I=imread('cells.jpg');>> imshow(I)>> size(I)ans = 479 600 3 (RGB image)>> Igrey=rgb2gray(I);>> imshow(Igrey)>> imwrite(lgrey, 'cell_gray.tif', 'tiff')
Alternatives to imshow>>imagesc(I)>>imtool(I)>>image(I)
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 19
INVERTING AN IMAGE- To invert or to add two images we need to convert to double and then rescale the result back so that it looks like an imageInvImg= 1 - double(IMG1)/255;NewImg = uint8(round(InvImg*255)))Imshow(NewImg);
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 20
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 21
WORKING WITH IMAGE IN MATLAB-
Color Masking Sometimes we want to replace pixels of an image of one or more colors with pixels from another image. It is useful to use a “blue or green screen” in some instances.
Find an image with a big plot of one color. First we will replace that color. And then we will find another image for pixel replacement. Let us plot the color values of one chosen row…This will tell us the pixel values of the color we want to replace.
1. v = imread(‘myimg.jpg’)2. image(v)3. row= input(‘which row?’);4. red = v(row,:,1);5. green = v(row,:,2);6. blue = v(row,:,3);7. plot(red,’r’);8. hold on9. plot(green,’g’);
plot(blue,’b’);
Suppose we want to replace those values whose intensities exceed a threshold value of 160 in each color.
• v= imread(‘myimg.jpg’);• thresh= 160• layer = (v(:,:,1) > thresh) & (v(:,:,2) > thresh) (v(:,:,2) > thresh) • mask(:,:,1) = layer;• mask(:,:,2) = layer;• mask(:,:,3) = layer;
If you want to only mask a portion of the image you can use something like…>> mask(700:end,:,:)= false;Which sets the mask so that we do not affect rows 700 and aboveTo reset the color to red>>newv = v;>>newv(mask)(1) = 255
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 22
Or to replace pixels from a different image w use…>> newv(mask) = w(mask);
Image co-ordinate systems:
Pixel coordinates: In this coordinate system, the image is treated as a grid ofdiscrete elements, ordered from top to bottom and left to right.
Spatial Coordinates: In this spatial coordinate system, locations in an imageare positions on a plane, and they are described in terms of x and y (not r andc as in the pixel coordinate system).
Types of Digital Images
Binary: Each pixel is just black or white. Since there are only two possible values for each pixel (0,1), we only need one bit per pixel.
Grayscale: Each pixel is a shade of gray, normally from 0 (black) to 255 (white). This range means that each pixel can be represented by eight bits, or exactly one byte. Other grey scale ranges are used,but generally they are a power of 2.
True Colour, or RGB: Each pixel has a particular color; that color is described by the amount of red, green and blue in it. If each of these components has a range 0–255, this gives a total of 2563 different possible colors. Such an image is a “stack” of three matrices; representing the red, green and blue values foreach pixel. This means that for every pixel there correspond 3 values
Image Display and Exploration
1. colorbar:-Display color bar.
2. immovie:-Make movie from multiframe image.
3. implay:-Play movies, videos, or image sequences.
4. imshow:-Display image.
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 23
5. imtool:-Image Tool.
6. subimage:-Display multiple images in single figure.
Image Types and Type Conversions
1. double:-Convert data to double precision.
2. gray2ind:-Convert grayscale or binary image to indexed image.
3. im2bw:-Convert image to binary image, based on threshold.
4. im2double:-Convert image to double precision.
5. im2int16:-Convert image to 16-bit signed integers.
6. im2single:-Convert image to single precision.
7. im2uint16:-Convert image to 16-bit unsigned integers.
8. im2uint8:-Convert image to 8-bit unsigned integers.
9. ind2gray:-Convert indexed image to grayscale image.
10. ind2rgb:-Convert indexed image to RGB image.
11. mat2gray:-Convert matrix to grayscale image.
12. rgb2gray:-Convert RGB image or colormap to grayscale.
13. rgb2ind:-Convert RGB image to indexed image.
14. uint16:-Convert data to unsigned 16-bit integers.
15. uint8:-Convert data to unsigned 8-bit integers.
Modular Interactive Tools:
1. imageinfo:-Image Information tool.
2. imcontrast:-Adjust Contrast tool.
3. imdisplayrange:-Display Range tool.
4. imdistline:-Distance tool.
5. impixelinfo:-Pixel Information tool.
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 24
6. impixelregion:-Pixel Region tool.
7. impixelregionpanel:-Pixel Region tool panel.
Image Arithmetic
1. imabsdiff:-Absolute difference of two images.
2. imadd:-Add two images or add constant to image.
3. imcomplement:-Complement image.
4. imdivide:-Divide one image into another or divide image by constant.
5. imlincomb:-Linear combination of images.
6. immultiply:-Multiply two images or multiply image by constant.
7. imsubtract:-Subtract one image from another or subtract constant from
image.
Intensity and Binary Images
1. imbothat:-Bottom-hat filtering.
2. imclearborder:-Suppress light structures connected to image border.
3. imclose:-Morphologically close image.
4. imdilate:-Dilate image.
5. imerode:-Erode image.
6. imfill:-Fill image regions and holes.
7. imopen:-Morphologically open image.
8. imtophat:-Top-hat filtering.
9. strel:-Create morphological structuring element (STREL).
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 25
Image Enhancement1. histeq:-Enhance contrast using histogram equalization.
2. imadjust:-Adjust image intensity values or colormap.
Pixel Values and Statistics1. imcontour:-Create contour plot of image data.
2. imhist:-Display histogram of image data.
3. impixel:-Pixel color values
NOISE IN MATLAB1. ADDING NOISE
2. FILTERING NOISE
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 26
MEDIAN FILTER REMOVE GAUSSIAN NOISE
THRESHOLDING
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 27
GRAPHICAL USER INTERFACE (GUI) : A graphical user interface (GUI) is a graphical display that contains devices, or components, that enable a user to perform interactive tasks. To perform these tasks, the user of the GUI does not have to create a script or type commands at the command line. Often, the user does not have to know the details of the task at hand.The GUI components can be menus, toolbars, push buttons, radio buttons,list boxes, and sliders—just to name a few. In MATLAB, a GUI can also display data in tabular form or as plots, and can group related components.
Working of GUIEach component, and the GUI itself, is associated with one or more user-written routines known as callbacks. The execution of each callback is triggered by a particular user action such as a button push, mouse click, selection of a menu item, or the cursor passing over a component. The creator of the GUI provides these callbacks. In the GUI, the user selects a data set from the pop-up menu, then clicks one of the plot type buttons. Clicking the button triggers the execution of a callback that plots the selected data in the axes. This kind of programming is often referred to as event-driven programming. The event in the example is a button click. In event-driven programming, callback execution is asynchronous, controlled by events external to the software. In the case of MATLAB GUIs, these events usually take the form of userinteractions with the GUI.
Techniques used to implement the GUI
There are following two techniques toimplement the GUIs in the MATLAB:-
1. Creating a Simple GUI with GUIDE.
2. Creating a Simple GUI Programmatically.
GUIDE: A Brief Introduction: GUIDE, the MATLAB graphical user interfacedevelopment environment, provides a set of tools for creating graphical user
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 28
interfaces (GUIs). These tools simplify the process of laying out and programmingGUIs. The GUIDE Layout Editor enables you to populate a GUI by clicking and dragging GUI components — such as buttons, text fields, sliders, axes, and so on— into the layout area. It also enables you to create menus and context menusfor the GUI.
GUIDE Tools Summary
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 29
Programming a GUIWhen you save your GUI layout, GUIDE automatically generates anM-file that you can use to control how the GUI works. This M-file provides code to initialize the GUI and contains a framework for the GUI callbacks—the routines that execute in response to user-generated events such as a mouse click. Using the M-file editor, you can add code to the callbacks to perform the functions you want. Programming a Simple GUI shows you what code to add to the example Mfile to make the GUI work.
Starting a GUIDE: There are many ways to start GUIDE. We can start GUIDE fromthe:1. Command line by typing guide2. Start menu by selecting MATLAB > GUIDE (GUI Builder)3. MATLAB File menu by selecting New > GUI4. MATLAB toolbar by clicking the GUIDE buttonHowever we start GUIDE, it displays the GUIDE Quick Start dialog box shown in the following figure.
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 30
Blank GUIThe blank GUI template displayed in the Layout Editor is shown in thefollowing figure.
Creating GUIs Programmatically
1. Callback Execution:-Callback execution is event driven and callbacks from different GUIs share the same event queue. In general, callbacks are triggered by user events such as a mouse click or key press. Because of this, you cannot predict, when a callback is requested, whether or not another callback is executing or, if one is, which callback it is.Various functions used in creating GUIs programmatically aregiven below:-
Predefined Dialog Boxes1. errordlg:- Create and open error dialog box.
2. uigetfile:-Open standard dialog box for retrieving files.
3.uiopen:-Open file selection dialog box with appropriate file filters.
4. uisave:-Open standard dialog box for saving workspace variables.
5.msgbox:-Create and open message box.
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 31
6. warndlg:-Open warning dialog box.
7.questdlg:-Create and open question dialog box.
8. uiputfile:-Open standard dialog box for saving files.
Deploying User Interfaces
1. guidata:-Store or retrieve GUI data.
2. guihandles:-Create structure of handles.
3. movegui:-Move GUI figure to specified location on screen.
4. openfig:-Open new copy or raise existing copy of saved figure.
User Interface Objects
1. menu:- Generate menu of choices for user input.
2. uibuttongroup:- Create container object to exclusively manage radio
buttons and toggle buttons.
3. uicontextmenu:- Create context menu.
4. uicontrol:- Create user interface control object.
5. uimenu:- Create menus on figure windows.
6. uipanel:- Create panel container object.
7. uipushtool:- Create push button on toolbar.
8. uitoggletool:- Create toggle button on toolbar.
9. uitoolbar:- Create toolbar on figure
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 32
Adder using GUI : We have made a simple adder using GUI which can be deployed and can be used for adding purposes. By using the same GUI we can adder other functions also like subtract, divide, multiply etc. but we are only making adder here for learning purpose.Fig. Final GUI
Steps for making the Adder :
1. Type guide in command prompt:
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 33
2. This window will appear:
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 34
3. Select Blank GUI and press ok.
4. 3 edit boxes,1 static box and put it as shown in fig.
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 35
5. Go on property inspector and change the name.
6. Similarly do it for edit box and push button.
7. For programming part right click the button and press view callback then write the code in it.
Code:function input1_editText_Callback(hObject, eventdata, handles)% hObject handle to input1_editText (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of input1_editText as text% str2double(get(hObject,'String')) returns contents ofinput1_editText as a double%store the contents of input1_editText as a string. if the string%is not a number then input will be emptyinput = str2num(get(hObject,'String'));%checks to see if input is empty. if so, default input1_editText to zeroif (isempty(input))set(hObject,'String','0')end
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 36
guidata(hObject, handles);% --- Executes on button press in add_pushbutton.function add_pushbutton_Callback(hObject, eventdata, handles)% hObject handle to add_pushbutton (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)a = get(handles.input1_editText,'String');b = get(handles.input2_editText,'String');% a and b are variables of Strings type, and need to be converted% to variables of Number type before they can be added togethertotal = str2num(a) + str2num(b);c = num2str(total);% need to convert the answer back into String type to display itset(handles.answer_staticText,'String',c);guidata(hObject, handles);
8. Now click the green arrow or click run from the options or either write name i.e myadder in command window.
9. The below screen will appear, put the values and get the answer.Here we have put 4 and 20 ad we get 24 as result
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 37
VOICEBOX: Speech Processing Toolbox for MATLAB VOICEBOX is a speech processing toolbox consists of MATLAB routines that are maintained by and mostly written by Mike Brookes, Department of Electrical & Electronic Engineering, Imperial College, Exhibition Road, London SW7 2BT, UK. Several of the routines require MATLAB V6.5 or above and require (normally slight) modification to work with earlier versions. The routine VOICEBOX.M contains various installation-dependent parameters which may need to be altered before using the toolbox. In particular it contains a number of default directory paths indicating where temporary files should be created, where speech data normally resides, etc. You can override these defaults by editing voicebox.m directly or, more conveniently, by setting an environment variable VOICEBOX to the path of an initializing m-file. See the comments in voicebox.m for a fuller description. MATLAB doesn't really like unicode fonts; some non-unicode fonts containing IPA phonetic symbols developed by SIL are available here.
CONTENTS:-
Audio File Input/Output
Read and write WAV and other speech file formats
Frequency Scale
Convert between Hz, Mel, Erb and MIDI frequency scales
Fourier/DCT/Hartley Transforms
Various related transforms
Random Number and Probability Distributions
Generate random vectors and noise signals
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 38
Vector Distances
Calculate distances between vector lists
Speech Analysis
Active level estimation, Spectrograms
LPC Analysis of Speech
Linear Predictive Coding routines
Speech Synthesis
Text-to-speech synthesis and glottal waveform models
Speech Enhancement
Spectral noise subtraction
Speech Coding
PCM coding, Vector quantisation
Speech Recognition
Front-end processing for recognition
Signal Processing
Miscellaneous signal processing functions
Information Theory
Routines for entropy calculation and symbol codes
Computer Vision
Routines for 3D rotation
Printing and Display Functions
Utilities for printing and graphics
Voicebox Parameters and System Interface
Get or set VOICEBOX and WINDOWS system parameters
Utility Functions
Miscellaneous utility functions
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An Industrial Training Report on MATLAB 39
CONCLUSION During the training period we have studied that matlab can be used for variety of applications like computation and mathematical operations, Algorithm development, Data acquisition, Application development, including graphical user interface building, building graphs and plots. process digital images and many more.
REFERENCES
MATLAB primer R2012a.
http://www.imc.tue.nl/IMC-main/IMC-main-node8.html#Ch1.6
http://www.mathworks.in/products/
http://en.wikipedia.org/wiki/MATLAB
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA