Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lab Experiment # 02
Implementation of Basic Signals using MATLAB Graphics.
Objective
This lab provides an introduction to line specification commands to alter line color, marker
symbol, marker style. The lab also provides an introduction to basic signals like unit step and
unit impulse signal and how they are made.
Apparatus
Pc having Matlab
Theory
Graphics objects are the basic elements used to display graphs. When a plotting function is
called, MATLAB® creates the graph using various graphics objects, such as a figure window,
axes, lines, text, and so on. Each object has a fixed set of properties, which you can use to
control the behavior and appearance of the graph.
Common Graphics Objects
When you call a function to create a graph, MATLAB creates a hierarchy of graphics objects.
For example, calling the plot function creates the following graphics objects:
Figure — Window that contains axes, toolbars, menus, and so on.
Axes — Coordinate system that contains the object representing the data
Line — Lines that represent the value of data passed to the plot function.
Text — Labels for axes tick marks and optional titles and annotations.
Different types of graphs use different objects to represent data. Because there are many
kinds of graphs, there are many types of data objects. Some are general purpose, such as lines
and rectangles and some are highly specialized, such as legends etc. Plotting functions can
return the objects used to create the graph.
Example: The following statements create a graph and return the line object created by
the plot function:
x = 1:10;
y = x.^3;
h = plot(x,y)
Its output graph is shown below in Fig. 2.1.
1000
900
800
700
600
500
400
300
200
100
0
1 2 3 4 5 6 7 8 9 10
Use h to set the properties of the line object. For example, set its Color property.
h.Color = 'red';
Line properties can also be specified when calling the plotting function.
h = plot(x,y,'Color','red');
You can query the line properties to see the current value:
h.LineWidth
ans =
0.5000
Line Specification
Various line types, plot symbols and colors may be obtained with PLOT(X,Y,S) as shown in
Table 2.1, where S is a character string made from one element from any or all the following
3 columns:
Table 2.1: Line specifications
Line Style
This example shows how to create a plot using a dashed dot line. Add the optional line
specification, '-.', to the x,y pair.The general syntax is Plot(x,y,’linestyle’,….)
>> x = linspace(0,2*pi,50);
>> y = sin(x);
>> plot(x,y,'-.')
EE-311 Lab Manual, EE Department, Wah Engineering College
y=sin(x)
z=cos(x)
plot(x,y,'-g.',x,z,'--r*')
legend('y=sin(x)','z=cos(x)')
Its output graph is shown below in Fig. 2.6.
Lab Task
Task 1: Create a function of your name ‘name(a,n)’ which acquires amplitude (a) and index
sequence (n) as a function argument and plots unit step u[n] and unit impulse δ[n] functions
in same window using subplot. All functions must have same amplitude value a and index
range [n].
Task 2: Write a MATLAB program to generate a sinusoidal sequence. x[n] = Acos( wn + φ
)and plot the sequence using the stem function. The input data specified by the user is the n,
amplitude A, the angular frequency w, and the phase φ where 0 < w <π and 0 < φ < 2 π.
Task 3: Write a MATLAB function with name expsignal(A,a) that generates and plots the
real exponential sequence given as x[n]= AanWhere A is the amplitude and n is the time
indexing value. Solve it for the following cases
Growing exponential when a>1
Decaying exponential when a<1
a=-1 and (iv) a=1
Observe the output and comment about them
Task 4: Plot each of the following signals in the interval 0 ≤ n ≤ 20:
Comments
…………………………….
Conclusion
…………………………….