Laboratory Manual for Computer Applications Software

Embed Size (px)

Citation preview

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    1/27

    ELECTRONICS AND COMMUNICATIONS ENGINEERING DEPARTMENT

    COLLEGE OF ENGINEERING

    XAVIER UNIVERSITY ATENEO DE CAGAYAN

    LABORATORY MANUALCOMP 13 COMPUTER APPLICATIONS SOFTWARE

    Majiah S. Collado, ECEInstructor

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    2/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 1

    INTRODUCTION TO ELECTRONICS WORKBENCH SOFTWARE

    Experiment No.

    OBJECTIVES:

    1. To familiarize the capabilities of Electronics Workbench Software

    2. To use this software to analyze digital circuits

    EQUIPMENT:

    Computer unit with Electronics Workbench installed.

    INTRODUCTION:

    The various circuits were adapted to familiarize the usage of Electronics Workbench software. The

    experiments are as simple as voltage divider, bode plotting and to some basic digital circuits.

    PROCEDURES:

    We will build and analyze a circuit with a voltage source and a few resistors.

    Figure 1.1: Sample Electronics Workbench circuit

    Figure 1.2: Different parts of the EWB screen

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    3/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 2

    Important points to remember:

    1. As you draw more complicated circuits, your drawing may appear to be extremely cluttered. Take care

    through the whole design to add connections to the correct side of a node (top, bottom, right or left) move

    lines away from objects that interfere with other lines. (Just click & drag the line) save your work as you

    go - dont wait until it is complete to save.

    2. If it appears that a line has disappeared, it is possible that the software has drawn a line on top of an

    existing line. Try to move the line by clicking where the line disappeared and dragging it. If all goes well,

    both lines should appear once theyre separated.

    3. Remember that normal circuit design principles still apply - a resistor with one connection cannot have

    current through it, circuits with no sources will do nothing, ammeters belong in series, voltmeters belong in

    parallel, etc.

    4. Electronics Workbench builds the circuit in the center of the workspace. This can lead to printing

    problems (a simple printout may take 4 pages). To avoid this, choose:

    Edit -> Select All

    which should highlight everything in the circuit. Then click on any red item and drag to the top left (to

    push the picture to the top left, you may have to move the pointer off of the workspace toward the upper

    left). This should put your circuit on one page of paper.

    5. When printing, be sure to check off everything you want to print. Your choices should be clearly seen

    in the printing dialog box.

    6. Be sure to save your work. It may not be on the hard drive when you return. (The systems are subject

    to being rebuilt at any time).

    7. Be sure to check your printout before deleting or significantly modifying your circuit.

    1. Choose the correct part library. Passive components (like resistors) are located in the Basic library;

    voltage sources are in the Sources library. Choose the library by clicking on the appropriate icon.

    Figure 1.3: Selecting a component

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    4/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 3

    As you use the program, if the necessary part is not available in the parts bin currently in use, check in a

    different part library. For example, the Ammeter and Voltmeter are in the Indicators library. Choose this

    library at the appropriate time just like the Basic library was chosen here.

    2. Drag the picture of the voltage source into the work area, then drop. Repeat with a resistor (note that a

    new resistor is available as one is taken from the parts bin). It is easiest to drop components to roughly the

    same position as in the final circuit. See figure 1.5.

    3. To change the properties of a component, double click on that component. For example, to change the

    value of the 1k resistor to 7k: double click, and change the resistance.

    Figure 1.4: Changing Component Properties

    4. Repeat for other resistors - see figure 1.5.

    Figure 1.5: Resistors in the work area

    5. To make connections between two components (with lines):

    Move the mouse over the starting point. When you are located on a valid starting point, you should see alarge dot appear under the cursor.

    Figure 1.6

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    5/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 4

    Figure 1.7

    While the starting point is highlighted, click and hold the left mouse button.

    While holding the left button, drag away from the part. You should have a wire extending from the starting

    point to your cursor. Drag the cursor over the desired ending point; release the left mouse button when you

    see the dot appear.

    The parts should be connected. If the wire disappears, repeat the above steps. This usually means that the

    left button was released while the dot wasnt visible.

    To run wires from an input or output to a node, start at the input or output and draw to a wire. To make aconnection from a wire, place a node (a dot from the Basic parts bin) on the wire and wire from the node.

    Notice that a node has four entry points for a connection - top, left, right, bottom. The connection will

    appear different depending on where the connection is made. Take care to make connections at the right

    location.

    To remove a wire: Left click on one end of the wire (on the large dot) and drag the wire off of the

    connection.

    Choose the Indicator library and place the ammeter and voltmeter into the circuit. Connect the inputs

    and outputs of the components placed so far:

    Figure 1.8:

    6. Multimeter: The multimeter is one of the instruments in the Instrument library. There is only one ofeach instrument available at a time. To use an instrument, drag and drop it into the workspace. The

    multimeter has two inputs, labeled + and -. These are valid endpoints for wires (like the inputs and outputs

    of components). To expand the multimeter (or any other instrument), double click the instrument. The

    connections that are visible on the small instrument are labeled on the larger instrument.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    6/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 5

    Figure 1.9: Multimeter & the 'Instruments library'

    Figure 1.10: Multimeter (small & expanded views)

    Drop the multimeter into the workspace.

    7. Connect the multimeter to measure the voltage across the 1kohm resistor. Double click the multimeter,

    and choose voltage to measure. Notice that the connections on the small picture match the connections

    shown on the large image when expanded.

    8. Notice that, like all Instruments, there is only one multimeter. There are unlimited ammeters and

    voltmeters in the Indicator library.

    9. To activate the circuit, turn the power switch (top right) on.

    10. Disconnecting the 7k resistor, how much is the voltage across the resistor 1k? What basic law of

    electric circuits does this experiment illustrate?

    Figure 1.11

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    7/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 6

    11. Write down what you have observed regarding the circuit. Refer to figures 1.1 and 1.11.

    12. Connect the components of the circuit as shown.

    13. Activate the power on button.

    14. The bulb should light when the power is turned on. What is the voltage reading across the voltmeter?

    What is the current reading across the ammeter?

    15. Change the DC source to 15V. What happens to the circuit?

    16. Write down your observation regarding the circuit. Refer to figure 2.1.

    17. Connect the components of the circuit shown. See figure 3.1.

    18. Take out the oscilloscope from the instruments bin. The bottom 2 dots resemble the A and B channel,

    respectively, while the upper right dot of the icon refers to the ground. See figure 3.2(a).

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    8/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 7

    19. Highlight a terminal on the oscilloscope icon and drag a wire to connect A in the circuit. Do the same

    with the other terminal on to connector B in the circuit.

    20. From the same bin, take out the function generator. The left most terminal is negative, the right is

    positive and the middle terminal is common or neutral.

    21. Open the function generator. If it covers the oscilloscope, drag it to a new direction. Check if the

    parameters are similar to that of figure 3.3b.

    22. If they are similar, turn the power switch on.

    23. To see the graph of the circuit, double click on the oscilloscope icon. Describe the graph.

    24. Increase the frequency of the function generator to 1kHz and adjust the amplitude and time base of

    your circuit accordingly. What can you say about the waveform? What filter is the circuit you just

    analyzed?

    25. Remove the oscilloscope and replace it with the Bode Plotter and rearrange the circuit as shown.

    26. Set up the Bode Plot according to the values in figure 3.5

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    9/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 8

    27. The Bode Plotter begins to generate a series of frequencies starting at the initial value (1.0 mHz) and

    ending at the final value (1 kHz). It plots the ratio of the output voltage to input voltage as a function of

    frequency.

    28. Drag the vertical cursor on the left edge of the Bode Plotter display to the half-power point

    approximately -3.00 dB on the plot. What is the cutoff frequency?

    29. Write down your observation regarding the circuit. Refer to figure 3.4.

    30. Assemble the circuit shown in figure 4.1

    31. Take out the Word Generator from the Instruments Bin.

    The word generator can drive a digital circuit by producing streams of 16 bit words. Use it to send

    digital words or patterns of bits into circuits to test them. The word generator and its icon is shown in

    figure 4.2

    32. Attach the word generator to the circuit. From left to right, there are 16 terminals in the word generator

    (the other two terminals are for external trigger, and data ready). Of the 16 terminals, the right most is

    connected to the Set input (S). The second right most terminal is connected to the R input.

    33. Open the word generator. You should see a number of buttons, a hex field, and an ASCII field. You

    can use any one of the fields to enter words in the generator. In this exercise, you will use the binary

    field to input 16-bit words. Since the RS flip-flop circuit you are building has two inputs, you only

    need to create a bit pattern in the word generators first five rows.

    34. Enter the inputs S and R for the predicted outputs Q and Q, as shown in table 4.1.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    10/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 9

    35. Make sure you are in address 0000. Place your cursor in the first word in the scrolling hex field (the

    edit field should read 0000)

    36. The first condition in the truth table is S = 1 and R = 0. In the binary field, highlight the second zero

    from the right and type 1. The first word in the hex field should change to 0002.

    37. In the third condition, S = 0 and R = 1, so place your cursor on the third word down the hex field. The

    edit field should read 0002, as the first word address is 0000. In the binary field, change the least

    significant bit (the bit furthest to the right) to 1.

    38. The fifth condition in the truth table is S = 1 and R = 1. Change the word five (address 0004) to show

    binary 0000000000000011. The hex field for the fifth word should read 0003.

    39. The second and forth conditions are zeros, so you do not have to change the word generator.

    40. Change the final address to 0004.

    41. Change the frequency to 1 Hz to slow down the cycle.

    42. While watching the probes, send the bits into the circuit by clicking the step button on the word

    generator three times. When the state changes, the alternate probe lights up.

    43. Fill up the output spaces of table 4.1

    44. Write down your observation regarding the experiment. Refer to figure 4.1.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    11/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 10

    ELECTRONICS WORKBENCH CIRCUIT SIMULATION

    Experiment No.

    OBJECTIVES:

    1. To familiarize the capabilities of Electronics Workbench Software

    2. To enable the students to appreciate time saved, and actual real world relation of simulation actual

    circuit designing.

    EQUIPMENT:

    Computer unit with Electronics Workbench installed.

    INTRODUCTION:

    The next couple of circuits will show a simulation of some of the most common circuits in electronics.

    These experiments will now test the students understanding of the theories.

    PROCEDURES:

    1. Construct the circuit shown below.

    Questions:

    a) Based on the input and output condition of the circuit, what do you call this type of circuit?

    b) What is the formula for the frequency calculation of this circuit?

    c) Solve for the frequency using the formula. How much is it?

    d) What is the frequency of the circuit as measured on the EWB?

    e) What is the amplitude?

    f) Perform an ac analysis on the circuit. What is the waveform that you see? Why do you think

    so?

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    12/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 11

    2. Reconstruct the figure so it would look like the figure below. Attach a function generator to the CON

    terminal (input). Set the function generator to 50 Hz with a duty cycle of 50%, amplitude 2 Volts.

    Attach an oscilloscope leads to both input and output. What is the figure that you see?

    Questions:

    a. Describe the output frequency?

    b. Based on your answer above, what do you say this circuit is?

    3. By changing the amplitude of the function generator from 2 to 5V, what do you notice about the output

    of the circuit?

    a. What is your observation of this experiment?

    4. Construct the circuit shown below.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    13/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 12

    5. Do a transient and Montecarlo analysis on the output node. What is the mean of the output?

    a. From the information given by the figures of the transient and montecarlo analysis, what

    would you say this circuit is called? Describe the circuit.

    6. Construct the circuit below.

    7.

    Set the function generator frequency to 100 Hz. With the oscilloscope set as shown, what is the inputvs output amplitude and frequency?

    8. Find the minimum operating input frequency for this circuit?

    Questions:

    a. What is the phase change when the circuit is operating in the minimum frequency?

    b. What is the circuit called?

    c. What have you observed about the circuit?

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    14/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 13

    ELECTRONICS WORKBENCH CIRCUIT SIMULATION

    Experiment No.

    OBJECTIVES:

    1. To familiarize the capabilities of Electronics Workbench Software

    2. To enable the students to appreciate time saved, and actual real world relation of simulation actual

    circuit designing.

    EQUIPMENT:

    Computer unit with Electronics Workbench installed.

    INTRODUCTION:

    The circuit below when connected properly to the right terminals will give the student a more thorough

    understanding on how LCDs are controlled and made to function.

    PROCEDURES:

    1. Construct the circuit given below.

    2. Follow the pattern of the word generator given.

    3. Run the simulation.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    15/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 14

    Questions:

    a. Do you see a pattern in the output of the LCD? If so what is it?

    b. Having seen its function, what is this circuit called then?

    4. Write your observations about this circuit.

    5. Construct the circuit below. You can get the Op-Amp ICs at the misc bin category.

    6. The bode plotter gives you enough information on this circuit, what is it called?

    7. Apply 1 kHz sine wave at 10 V at the input, what is the frequency and amplitude at the output?

    8. Keep increasing the frequency of the input by increments of 2 kHz and record the frequency and

    amplitude in the table given below.

    Frequency Amplitude

    1 kHz

    a. What is the low frequency and high frequency cutoff of this circuit? What is its center

    frequency?

    9. Write your observation of this circuit here.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    16/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 15

    INTRODUCTION TO MATLAB SOFTWARE

    Experiment No.

    OBJECTIVES:

    1. To learn about the MATLAB Environment

    2. To learn about the different windows of the MATLAB Desktop

    EQUIPMENT:

    Computer unit with MATLAB installed.

    INTRODUCTION:

    In this experiment, the student will find the way around MATLAB Environment. When first launched with

    MATLAB, the figure below is the typical MATLAB Environment which consists of four main windows:

    Command Window, Command History, Current Directory Browser and Workspace browser.

    PROCEDURES:

    1. To run MATLAB, double-click on the Matlab icon or select Matlab from Start/Programs.

    2. You will see on the right hand side the Command Window, this is where you enter commands or

    instructions to MATLAB. Enter commands and data, display results in the prompt >>

    3. Type help on the command window and press the enter key. It will display all the MATLAB help

    topics.

    4. Type clc on the prompt >> and enter. What do you notice with your Command Window?5. Get the help of the said command, help commandprovides help for the specified command. What is

    the command for?

    6. The Workspace is where your data is stored in MATLAB. The data shown in the workspace is only

    available to use during your current MATLAB session.

    7. Type intro and press enter key.

    8. Close the Figure No.1 window. We will learn more of plotting graphics later in our experiments.

    9. Scroll up your Command Window and describe the data found on the window.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    17/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 16

    10. Type whos and enter. What is this command for?

    11. Describe the data shown.

    12. Type clear on the prompt >> and enter. What do you notice with your Command Window? How about

    your Workspace Window?

    13. See your Command History Window. It is located in the bottom left corner. What have you noticed on

    the window?

    14. Describe the window.

    15. Click on the Current Directory tab. The Current Directory is the folder where you can save your work.

    The current directory field is located on the top right, and displays the current MATLAB working

    directory. To change it, click the browse for folder button.

    16. To access MATLAB files that are not current directory, you need to include it in the list of paths that

    MATLAB searches through, or commonly referred to as the MATLAB search path. To view and editthe MATLAB search path, use the Set Path dialog box.

    17. Click on File then Set Path.

    18. Add the folder that the Laboratory Computer allows you to save your files.

    19. Save and Close then set the current directory to the directory you have saved on the Set Path dialog

    box. Now you are ready to save your work.

    20. The following Help from MATLAB:

    help topic provides help for the specified topic

    help help provides information on use of the help command

    helpwinOn-line help, separate window for navigation.

    helpdeskComprehensive hypertext documentation and troubleshooting

    demoRun demonstrations

    21. Terminating and interrupting MATLAB keys are as follows:

    Ctrl-C (pressing the Ctrl and c keys simultaneously): Interrupts (aborts) processing, but does not

    terminate Matlab. You may want to interrupt Matlab if you mistakenly command it to display

    thousands of results and you wish to stop the time-consuming display.

    quit: Terminates Matlab

    exit: Terminates Matlab

    Select Exit under File menu: Terminates Matlab (MS Windows)

    22. Give a summary of the help commands.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    18/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 17

    MATLAB SCRIPT M-FILES

    Experiment No.

    OBJECTIVES:

    1. To learn how to make simple script files.

    2. To learn how to save and retrieve Script M-files.

    3. To use M-files to edit commands.

    EQUIPMENT:

    Computer unit with MATLAB installed.

    INTRODUCTION:

    A MATLAB script is an ASCII text file that contains a sequence of MATLAB commands;

    Scripts in MATLAB are also called "M-files" because of this, and the ".m" suffix tells MATLAB that the

    file is associated with MATLAB.

    PROCEDURES:

    Important points to remember:

    1. The name of a script file must follow the MATLAB convention for naming variables; that is, the name

    must begin with a letter and may include digits and the underscore character.

    2. Do not give a script file the same name as a variable it computes, because MATLAB will not be able

    to execute that script file more than once unless the variable is cleared. Recall that typing a variable

    name at the command prompt causes MATLAB to display the value of that variable. If there is no

    variable by that name, then MATLAB searches for a script file having that name. For example, if the

    variable rqroot was created in a script file having the name rqroot.m, then after the script is executed

    the first time, the variable rqroot exists in the MATLAB workspace. If the script file is modified and an

    attempt is made to run it a second time, MATLAB will display the value of rqroot and will not execute

    the script file.

    3. Do not give a script file the same name as a MATLAB command or function. You can check to seewhether a function already exists by using the the which command. For example, to see whether rqroot

    already exists, type which rqroot. If it doesnt exist, MATLAB will display rqroot not found. If it does

    exist, MATLAB will display the full path to the function. For more details as to the existence of a

    variable, script, or function having the name rqroot, type exist(rqroot). This command returns one of

    the following values:

    0 ifrqroot does not exist

    1 ifrqroot is a variable in the workspace

    2 ifrqroot is an M-file or a file of unknown type in the Matlab search path

    3 ifrqroot is a MEX-file in the Matlab search path

    4 ifrqroot is a MDL-file in the Matlab search path

    5 ifrqroot is a built-in Matlab function

    6 ifrqroot is a P-file in the Matlab search path7 ifrqroot is a directory

    4. As in interactive mode, all variables created by a script file are defined as variables in the workspace.

    After script execution, you can type who or whos to display information about the names, data types

    and sizes of these variables.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    19/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 18

    1. Set path the current directory where you will save M-files (Files>Set Path).

    2. To create a new MATLAB M-file. You must first access the MATLAB Editor.

    3. To open the MATLAB editor, select File > New > M-file. The MATLAB editor is where you construct

    a MATLAB script.

    4. Type in any valid MATLAB command in the editor the same way as if you were typing in the

    Command window.

    5. On the editor, type the sample script below:

    % a simple MATLAB m-file to calculate the

    % average of 5 numbers.

    % first define variables for the 5 numbers:

    a = 5;

    b = 10;

    c = 15;

    d = 20;

    e = 25;

    % now calculate the average of these and print it out:

    five_number_average = (a + b + c + d + e) / 5;

    five_number_average

    6. You should notice that the line with a percent sign automatically highlighted in green. What does thismean?

    7. You can save a MATLAB script by selecting File > Save > or File > Save As

    8. The MATLAB program is automatically saved with a .m extension, you dont need to add the .m

    extension, MATLAB automatically does this. You can select the directory to save the script.

    9. The M-file can be reused or executed inside the MATLAB editor by clicking the run button.

    10. Where do you think will the result show?

    11. Close the M-file and execute the script by typing the name of the M-file in the command window.

    12. Write your observation regarding the operation.

    13. Create a new M-file. Type the following script below:

    % "flower petal" plotstheta = -pi:0.01:pi; % Computations

    rho(1,:) = 2 * sin(5 * theta) .^ 2;

    rho(2,:) = cos(10 * theta) .^ 3;

    rho(3,:) = sin(theta) .^ 2;

    rho(4,:) = 5 * cos(3.5 * theta) .^ 3;

    for k = 1:4

    polar(theta, rho(k,:)) % Graphics output

    pause

    end

    14. Save and execute the script. What do you think is the output?

    15. Write your observation of the output in relation to engineering application.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    20/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 19

    Obtaining Step response of electric Circuits:

    The transfer function for a second-order low-pass filter is given by ,

    where K is the dc gain, c is the corner frequency and is the damping ratio associated with the second-

    order characteristic.

    16. Create new M-file. Type the sample transfer function script on the editor:

    K=10; wc=1000; dratio=0.05;

    num=K;

    den1=[(1/wc)^2 2*dratio/wc 1];

    % Obtain transfer function

    H1=tf(num,den1);

    %Step response of the system

    step(H1); % this step plots the step response of the system for the given transfer function

    Hold

    % the current plot will be held.

    % This feature is useful to obtain the plots for different damping ratios on the same graph.

    17. Save and execute the M-file.

    18. On the editor, change the damping ratio to 0.3 and the step response to step(H1,0.1);

    This step plots the step response of the system for the given transfer function from t=0 to t=0.1 sec.

    19. Save and execute the M-file.

    20. This time the Figure will show you the step response of two transfer functions.

    21. On the editor again, change the damping ratio to 0.707 and put a percent sign before Hold.

    22. Save and execute.

    23. What does the figure show you?

    24. Write down your observation regarding the figure.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    21/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 20

    ARRAYS and MATRICES

    Experiment No.

    OBJECTIVES:

    1. To learn how to create variables.

    2. To handle matrix operations.

    EQUIPMENT:

    Computer unit with MATLAB installed.

    INTRODUCTION:

    MATLAB stores data in memory in the form of variables. You can think of MATLAB variables as data

    containers. Important attribute of these containers, firstly, all variables are arrays. The fundamental data

    type is a matrix, even the scalar variables are treated as 1 x 1 arrays. Variables come in different types, for

    now we will concentrate on the default numerical data type which is the double.

    PROCEDURES:

    1. Set the current directory path. (File>Set Path)

    2. The syntax for creating a variable is the Variable Name followed by the assign operator which is the

    equal sign and then the Value. The variable name has to be on the right of the assign operator.

    3. On your command window, assign the following variables:

    4. You can format the resulting value of the variable. Typing format long on the command window then

    press enter key.

    5. Type the name of the variable and press enter key. How many decimal places are there?

    6.

    To go back to its default format, type format short.7. Complete the calculation above. What is the answer for y?

    8. Let us move on to creating arrays of data. Vectors are arrays with one dimension of length 1, such as

    the row or column vector.

    9. On the command window, type x = 0:2:6 then enter

    10. What does it show you?

    11. Again type x = linspace(0,6,4) then enter

    12. Compare the values and explain the two methods of creating a sequential vector.

    13. Type x then enter.

    14. What does it show you? What is now the new variable shown?

    15. Type t = 0:0.1:100 then enter

    16. What does it show you? Type the above t again but with a semicolon then enter.

    17. What happened then? Explain.

    18.

    Type A = [1,2,3;4,5,6;7,8,9] then enter key19. Type A again but instead of comma between the numbers, use space.

    20. Does it give you the same result?

    21. Differentiate the comma separator and the semicolon separator.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    22/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 21

    22. Having created vectors and matrices, let us apply these variables in mathematical operation. Evaluate

    the given below:

    A =

    B = 2 * A

    B = A + 2

    C = A * B

    23. Write your observation about the matrix operation.

    24. Evaluate the given Systems of Linear Equations:

    25. To get the matrix division, x = A\b

    26. What are the values of x?

    27. Type A * x then enter. What do the results mean?

    28. Perform these MATLAB entry shortcuts:

    A = eye(3)

    A = eye(3,3)

    B = ones(3,3)

    C = diag([1 2 3 4])

    D = magic(4)

    29. Explain the said entries.

    30. Solve the following Engineering application:

    The container of a breakfast usually lists the number of calories and the amounts of protein,

    carbohydrates, and fat contained in one serving of the cereal. The amounts for two common cereals are

    given below:

    Nutrient Information per serving

    Nutrient General Mills

    Cheerlos

    Quaker 100%

    Natural Cereal

    Calories 110 130

    Protein (g) 4 3

    Carbohydrate (g) 20 18

    Fat (g) 2 5

    Suppose a mixture of these two cereals is to be prepared that contains exactly 295 calories, 9 g ofprotein, 48 g of carbohydrate, and 8 g of fat.

    Set up a vector equation for this problem. Include a statement that says what your variables in the

    equation represent.

    Write an equivalent matrix equation and then determine if the desired mixture of the two cereals can be

    prepared.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    23/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 22

    MATLAB FUNCTION M-FILES

    Experiment No.

    OBJECTIVES:

    1. To learn how to create Function M-files.

    2. To use Script M-files for Function M-files.

    EQUIPMENT:

    Computer unit with MATLAB installed.

    INTRODUCTION:

    Another type of M file is a function file. Unlike a script file, all the variables in a function is local, which

    means their values are available only within the function. Function files are useful when you need to repeat

    a set of command several times. Function files are like function in C, subroutines in FORTRAN and

    BASIC, and procedures in Pascal. They are the building blocks of larger programs.

    The first line in a function must begin with a function definition line that has a list of input og inputs andoutputs. This line distinguishes a function M-file from a script M-file. Its syntax is as follows:

    function [output variables] = function_name(input variables)

    PROCEDURES:

    Important points to remember:

    The name of a function M-file has the form function_name.m, where function_name is the name you

    choose to call the function. While this name can be almost anything, there are a few rules.

    The name must start with a letter (either upper case or lower case).

    The name must consist entirely of letters, numerals, and underscores ( ). No other symbols are allowed. In

    particular, no periods are allowed.

    The name can be arbitrarily long, but MATLAB will only remember the first 31 characters.

    Do not use names already in use such as cos, plot, or dfield6. If you do, MATLAB will not complain, butyou will eventually suffer from the name duplication problem described earlier

    1. Set path for the current directory. (File>Set Path)

    2. Open the MATLAB editor.

    3. Create a function M-file for the function f (x) = x2 1. and enter the following three lines (one of them

    is blank, and is provided for readability):

    function y = f(x)

    y = x^2-1;

    4. The first line of a function M-file must conform to the indicated format. It is this first line that

    distinguishes between a function M-file and a script M-file. The very first word must be the wordfunction. The rest of the first line has the form

    dependent_variables = function_name(independent_variables)

    5. The rest of the function M-file defines the function using the same syntax we have been using at the

    MATLAB prompt. Remember to put a semicolon at the end of lines in which computations are done.

    Otherwise the results will be printed in the Command Window.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    24/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 23

    6. We will solve the following application and save it as a Function M-file.

    An object thrown in the air obeys the initial value problem.

    We solve this linear equation, and we find that

    Where y is the height in meters of the object ground level after t seconds. Estimate the height of the

    ball after 5 seconds.

    7. Open a new M-file editor. Enter the following:

    function y = height(t)

    y = -(49/5)*t + (649/5)*(1 - exp(-t));

    8. Save it as height.m

    9. This time we needed no additional periods to make the function array smart.

    It is now a simple matter to find the height at t= 5 seconds.

    10.

    On your command window, type y = height(5) then press enter key.11. What do you think is the output?

    12. Let us plot the height of the object versus time and use your graph to estimate the maximum height of

    the object and the time it takes the object to return to ground level.

    Although we could operate strictly from the command line to obtain a plot, we will use a script M-file

    to do the work for us.

    13. Open a new M-file, enter the commands:

    close all

    t = linspace(0,15,200);

    y = height(t);

    plot(t,y)

    grid on

    xlabel('time in seconds')

    ylabel('height in meters')

    title('Solution of y'''' = -9.8 - y'', y(0) = 0, y''(0) = 120')

    14. Save it in a file named height_drv.m. Notice that, since the first line does not begin with the word

    function, this is a script M-file, not a function M-file.

    The command close all will close all open figure windows. The purpose of this command is to prevent

    figure windows from accumulating as we execute versions of the script. However, you should be

    cautious about using it, since you may close figures you want to have open.

    15. You can execute the script M-file by typing height_drv at the MATLAB prompt. However, you can

    also select DebugRun from the editor menu. This menu item has the accelerator key F5. This means

    that after you edit the file, you can both save it and execute it with F5. The routine of editing, followed

    by F5 can be a great time saver as you refine an M-file.

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    25/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 24

    16. Running your script M-file should produce an image similar to that shown in the Figure below.

    17. Examine the graph. Give your observation about it.

    18. Explain why we have to use both the M-files to produce the graph.

    19. Solve the following problem:

    A simple RC-circuit with emfV (t) = 3 cos(t) is modeled by the initial value problem

    where Ris the resistance, Cthe capacitance, is the driving frequency, and VCis the voltage responseacross the capacitor. Show that the solution is

    Create a function M-file for this solution as follows:function V = f(t,R,C,w)

    V = (R*C*w*sin(w*t) + cos(w*t) - exp(-t/(R*C)))/(1 + R^2*C^2*w^2);

    Now, call this function with the following script.

    R = 1.2; C = 1; w = 1;

    t = linspace(0,2*pi,1000);

    V = f(t,R,C,w);

    plot(t,V)

    Run this script for = 1, 2, 4, and 8, keepingR = 1.2 ohms and C= 1 farad constant. What happens to

    the amplitude of the voltage response across the capacitor as the frequency of the emf is increased?

    Why do you think this circuit is called a low pass filter?

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    26/27

    Electronics and Communications Engineering Department Comp 13 Laboratory Manual 25

    MATLAB GRAPHICS

    Experiment No.

    OBJECTIVES:

    1. To learn how to visualize data.

    2. To use plot function to graph data.

    EQUIPMENT:

    Computer unit with MATLAB installed.

    INTRODUCTION:

    MATLAB provides a wide variety of techniques to display data graphically. Interactive tools enable you to

    manipulate graphs to achieve results that reveal the most information about your data. You can also

    annotate and print graphs for presentations, or export graphs to standard graphics formats for presentation

    in web browsers or other media.

    Plot is the simplest way of graphing and visualizing the data. If x is a vector, plot (x) will plot the elementsof x against their indices. The plot function has different forms, depending on the input arguments. If y is a

    vector, plot(y) produces a piecewise linear graph of the elements of y versus the index of the elements of y.

    If you specify two vectors as arguments, plot(x,y) produces a graph of y versus x.

    PROCEDURES:

    1. Set path for the current directory. (File>Set Path)

    2. Open the MATLAB editor.

    3. Type the following script:

    >>x = 0:pi/100:2*pi;

    >>y = sin(x);

    >>plot(x,y)Now label the axes and add a title. The characters \pi create the symbol p.

    >>xlabel('x = 0:2\pi')

    >>ylabel('Sine of x')

    >>title('Plot of the Sine Function','FontSize',12)

    4. Save and execute. What does this figure show you?

    5. In a separate editor, type the following:

    >>x = 0:pi/100:2*pi;

    >>y2 = sin(x-.25);

    >>y3 = sin(x-.5);

    >>plot(x,y,x,y2,x,y3)

    6. Save and execute. Write down your observation on the figure.

    7. The legend command provides an easy way to identify the individual plots. Add the following syntax:

    >>legend('sin(x)','sin(x-.25)','sin(x-.5)')

  • 8/3/2019 Laboratory Manual for Computer Applications Software

    27/27

    8. If you specify a marker type but not a linestyle, MATLAB draws only the marker. You may also want

    to use fewer data points to plot the markers than you use to plot the lines. Explore the following lines

    in your editor:

    >>x1 = 0:pi/100:2*pi;

    >>x2 = 0:pi/10:2*pi;

    >>plot(x1,sin(x1),'r:',x2,sin(x2),'r+')

    This plot shows the data twice using a different number of points for the dotted line and marker plots.

    9. The subplot command enables you to display multiple plots in the same window or print them on the

    same piece of paper. Typing subplot(m,n,p) partitions the figure window into an m-by-n matrix of

    small subplots and selects the pth subplot for the current plot. The plots are numbered along first the

    top row of the figure window, then the second row, and so on.

    10. Type this lines in a new editor.

    >>t = -pi:2*pi/100:pi;

    >>f1=sin(t.^2);

    >>f2=(sin(t)).^2;

    >>f3=cos(t.^2);

    >>f4=(cos(t)).^2;

    >>subplot(2,2,1);plot(t,f1);

    >>title('sin(t^2)')>>subplot(2,2,2);plot(t,f2);

    >>title('sin(t)^2')

    >>subplot(2,2,3);plot(t,f3);

    >>title('cos(t^2)')

    >>subplot(2,2,4);plot(t,f4);

    >>title('cos(t)^2')

    11. Write down your observation about the graph.

    12. Save the figure. To save a figure, select Save from the File menu. To save it using a graphics format,

    such as JPEG, for use with other applications, select Export from the File menu. You can also save

    from the command line - use the save as command, including any options to save the figure in a

    different format.

    13. The next example evaluates and graphs the two-dimensional sinc function, sin(r)/r, between the x andy directions. R is the distance from origin, which is at the center of the matrix. Explore the following

    lines in your editor:

    >>[X,Y] = meshgrid(-8:.5:8);

    >>R = sqrt(X.^2 + Y.^2);

    >>Z = sin(R)./R;

    >>mesh(X,Y,Z,'EdgeColor','black')

    14. On a new editor, type the following:

    functionz =x exp(x2y2):

    >>[X,Y] = meshgrid(-2:.2:2,-2:.2:3);

    >>Z = X.*exp(-X.^2-Y.^2);

    >> surf(x,y,z)

    >> title('z=x e^{(x^2-y^2)}')%The contour plot is given by:

    >> [C,f]=contourf(Z);

    >>clabel(C,f);

    >>colorbar

    %A combination of the two is given by

    >> surfc(x,y,z)

    15. Write down your observation on the figure.