Sei sulla pagina 1di 10

EE-311 Lab Manual, EE Department, Wah Engineering College

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

Fig. 2.1: Plot command output graph


EE-311 Lab Manual, EE Department, Wah Engineering College

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

Output graph is shown below in Fig. 2.2.

Fig. 2.2: Line style


Plot command can also be used for multiple graphs like
x = linspace(0,2*pi,50);
>> y = sin(x);
>> z = cos(x);
>>plot(x,y,'-.',x,z,':')
Its output graph is shown below in Fig. 2.3.

Fig. 2.3: Multiple graph output


Line Colour
The general syntax is Plot(x,y,’linestylelinecolor’,….).
For example
>> plot(x,y,'-.r',x,z,':g')
Prints the first dashed dot line as red and second line as green. In the following graph shown
in Fig. 2.4, the line color is green for plus ‘+’ and black for diamond‘d’.
EE-311 Lab Manual, EE Department, Wah Engineering College

Fig. 2.4: Graph showing line colour


Line Markers
The general syntax is:
Plot(x,y,’linestylelinecolorlinemarker,….)
>> plot(x,y,'-gd',x,z,'--r.')
Its output is shown below in Fig. 2.5.

Fig. 2.5: Use of line marker


Legends
LEGEND(string1,string2,string3, ...) puts a legend on the current plot
using the specified strings as labels.
Add a legend to the graph identifying each data set using the legend function. Specify legend
descriptions in the order that you plot the lines.
x=0:0.1:2*pi;
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.

Fig. 2.6: Use of legends in graph


Data Exploration
Display Data Values Interactively:
Data cursors enable you to read data directly from a graph by displaying the values of points
you select on plotted lines, surfaces, images, and so on. You can place multiple data tips in a
plot and move them interactively. If you save the figure, the data tips in it are saved, along
with any other annotations present.
Enabling Data Cursor Mode:
Once you have enabled data cursor mode, clicking the mouse on a line or other graph object
displays data values of the point clicked. Clicking elsewhere does not create or update data
tips as shown in Fig. 2.7.

Fig. 2.7: Graph showing data cursor


Using multiple data tips
EE-311 Lab Manual, EE Department, Wah Engineering College

 Use the following procedure to create multiple data tips.


 Enable data cursor mode from the figure toolbar. The cursor changes to a cross.
 Click on the graph to insert a data tip.
 Right-click to display the context menu. Select Create New Data tip.
 Click on the graph to place the second data tip. e way to annotate a number of points
on a graph.
Input Command
Input command gives the user the prompt in the text string and then waits for input from the
keyboard.
The input can be any MATLAB expression, which is evaluated, using the variables in the
current workspace, and the result returned in any variable e.g.
D = input('No of days')
Signal:
Signal is basically a pattern of variation of some form e.g. Electrical signals:
Voltages and currents in a circuit
Electrical representation of a signal is:

A = amplitude, peak deviation of function from zero.


F = frequency, number of oscillations (cycles) that occur each second of time.
ɷ= 2πf , the angular frequency, is the rate of change of the function argument in units of
rad/sec.
Two types of signals are Continious signals and Discrete signals.
Continuous Signal
Signals that vary continuously over specified range. They are represented by small
parenthesis in SNS. i.e x(t), y(t) etc.Represented by Amplitude, frequency and phase. In
MATLAB, plot command is used. Continous signal is shown in Fig. 2.8.

Fig. 2.8: Continuous signal


Discrete Signal
EE-311 Lab Manual, EE Department, Wah Engineering College

It represents discrete or discontinuous quantities. They are represented by large square


brackets in SNS. i.e. x[t], y[t] etc. They are represented by Amplitude and location of
samples. In MATLAB, stem command is used. Discrete signal is shown in Fig. 2.8.

Fig. 2.8: Discrete signal


Unit Step Signal
It is also called as Heaviside Step function. It is a discontinuous function whose value is zero
for negative argument and one for positive argument as shown below in Fig. 2.9.

Fig. 2.9a: Discrete domain Fig. 2.9b: Continuous domain


Matlab Code
N=input('Number of Samples = ');
n=-N:1:N
x=[zeros(1,N) 1 ones(1,N)]
stem(n,x)
xlabel('Time');
ylabel('Amplitude');
title('Unit Step');
Its output graph is shown in Fig. 2.10.
EE-311 Lab Manual, EE Department, Wah Engineering College

Fig. 2.10: Unit step signal graph


Unit Impulse Signal
A function δ[n] that has the value zero everywhere except at x = 0 where its value is infinitely
large in such a way that its total integral is 1. In signal processing it is referred to as the unit
impulse function and is shown below:

Fig. 2.11: Unit Impulse Signal


Matlab Code:
N=input('Number of Samples = ');
n=-N:1:N
x=[zeros(1,N) 1 zeros(1,N)]
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title(‘Unit Impulse');
Its output graph is shown below:
EE-311 Lab Manual, EE Department, Wah Engineering College

Fig. 2.11: Unit impulse graph


Exponential Signal
Exponential signals are of the form x(t)=Ceat
 If a>0, x(t) is increasing/growing function, if a<0, x(t) is decreasing/decaying
function. If t=0 then x(t)=C
Example: Plot the signal x(t)=3e0.4t and y(t)=2e-0.9t in the time interval -2≤ t ≤ 5.
Matlab Code:
t=-2:0.01:5;
x=3*exp(0.4*t);
y=2*exp(-0.9*t);
plot(t,x)
hold on
plot(t,y)
Its output is shown below in Fig. 2.12.

Fig. 2.12: Exponential function graph


EE-311 Lab Manual, EE Department, Wah Engineering College

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
…………………………….

Potrebbero piacerti anche