Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

DEPARTMENT OF COMPUTER ENGINEERING

School of Engineering and Architecture


Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Name:
S e c ti o n :
Date Assigned:
D a t e S u b m i tt e d :
EXPERIMENT 1
G e tti n g S t a r t e d w i t h M a t l a b / O c t a v e

Matlab and GNU Octave are mathematics-oriented software with built-in plotting and
visualization tools. GNU Octave, which you will be using for this course, is a free software that runs on
GNU/Linux, macOS, BSD, and Windows. Its syntax is largely compatible with Matlab. GNU Octave will
simply be referred to as Octave in this laboratory manual.
Octave can be downloaded from https://www.gnu.org/software/octave. Below is the step-by-
step installation procedure indicated by the orange arrow symbol.

Experiment 1 INTRO Page 1


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Select the appropriate system type applicable to your PC, for example 64-bit operating system.

Experiment 1 INTRO Page 2


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Wait until the file is saved and then proceed with the installation.

Experiment 1 INTRO Page 3


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Open the file from the downloads folder.

Experiment 1 INTRO Page 4


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Experiment 1 INTRO Page 5


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Experiment 1 INTRO Page 6


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Experiment 1 INTRO Page 7


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Wait until the installation procedure is completed.

Experiment 1 INTRO Page 8


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Experiment 1 INTRO Page 9


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Experiment 1 INTRO Page 10


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Clear command window, View or change Remove command window


command history and current directory outside of desktop (undock)
workspace at the Edit menu

• Enter Octave functions at


View or evaluate
the command-line prompt
previously run functions Workspace window provides
• Error messages can be seen
from the command information about the
on the command window
history window variables that are used

GNU Octave comes with a large set of general-purpose functions that is available without any
packages installed. The list can be seen from https://octave.sourceforge.io/octave/index.html .

Octave Forge is a central location for development of packages for GNU Octave which is similar
to Matlab's toolboxes. To list the available package, use the pkg command from the Octave prompt by
typing:
>> pkg list
To load a package, choose the package name from the list and type
>> pkg load package_name

Experiment 1 INTRO Page 11


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL

Practice Exercises:

I. PLOT
The plot command is used to create two-dimensional plot.
Syntax: plot(x,y)
Where x and y are vectors with the same number of elements.
Do this:
wt = 0:0.5:10;
y1 = 2*cos(wt); % y1 is computing the cosine of all the values in wt and
%multiplied each by 2. Since cosine is used, the maximum
%amplitudes of y1 are ±2.
figure 1,plot(y1); %the values on the x-axis are the matrix indices 1,2,3,…,length(y1)
figure 2, plot(wt,y1); %the values on the x-axis are the values of wt.

II. TITLE and LABEL


Syntax : title(string) , xlabel(string) , ylabel(string)
Do this:
clear;
clf;
wt = 0:0.5:10;
y1 = 2*cos(wt);
plot(wt,y1);
%title('Plot of y1'); %single line. You may use double or single quote
title("plot of y1 \n y1=2cos(wt) \n wt=0:0.5:10"); %multiple lines. Use double quote
xlabel("Time \n millisecond"); %multiple lines. Use double quote
ylabel("Amplitude"); %single line. You may use double or single quote

III. MULTIPLE GRAPHS IN ONE PLOT


Do this:
clear;
clf;
wt = 0:0.5:10;
y1 = 2*cos(wt);

Experiment 1 INTRO Page 12


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL


y2 = cos(wt);
y3 = 0.5*cos(wt);
plot(wt,y1,'--',wt,y2,'-',wt,y3,':')%The default for plot command is connected solid line
% You can see other options by invoking help
legend('y1=2cos(wt)','y2=cos(wt)','y3=0.5cos(wt)');

IV. LEGEND
syntax: legend (STR1, STR2, ...)
This is demonstrated on the code above. The str1, str2, must be in the order as how you
plotted the waveforms. Referring to the plot command above, the order is y1,y2,y3.

V. SUBPLOT
syntax: subplot(m,n,p)
m-number or rows, n-number of columns, p-position. Only the p value chages.
The figure below (2x3) has 2 rows, 3 columns, and the position numbers are as
shown. The position number is from left to right starting from top .

Do this (result is 3x1 subplot):


clear;
clf;
wt = 0:0.5:10;
y1 = 2*cos(wt);
y2 = cos(wt);
y3 = 0.5*cos(wt);
subplot(3,1,1),plot(wt,y1),title('Graph of y1');
subplot(3,1,2),plot(wt,y2);title('Graph of y2');
subplot(3,1,3),plot(wt,y3);title('Graph of y3');

VI. INPUT and DISPLAY


syntax: variable=input(string)
disp(string)
Do this:
clear;

Experiment 1 INTRO Page 13


DEPARTMENT OF COMPUTER ENGINEERING
School of Engineering and Architecture
Holy Angel University – Angeles City

LABORATORY MANUAL FOR SIGNALPROL


disp('This will compute y=2cos(wt) where wt is a vector');
wt=input('Input the values of wt as [0:increment:last value]: ');
y = 2*cos(wt);
somevalues=num2str(y(1:5)); %somevalues contain the first five values of y
disp('The first five values are:');
disp(somevalues);

The activities above serve as a practice on how to use the basic commands in Matlab, which can
also be done in Octave. When you are in Octave, you may be encountering an error like the one shown
below

Simply load the particular package that you need, in this case, the signal package. You may do it on the
command window or within the editor.

>>pkg load signal

Experiment 1 INTRO Page 14

You might also like