Lab 1 - Introduction To MATLAB
Lab 1 - Introduction To MATLAB
Lab 1 - Introduction To MATLAB
1.
NAME OF GROUP
MEMBER(S) & 2.
MATRIX NUMBER(S)
3.
COURSE BEEZ
DATE
TOTAL MARKS
1.0 OBJECTIVES
2.0 EQUIPMENT
1. MATLAB® software.
What is MATLAB®
MATLAB® is a high-level programming language that has been used extensively to solve
complex engineering problems. MATLAB® works with three types of windows which are
Command window, the Figure window and the Editor window. The Figure window only
pops up whenever you plot something. The Editor window is used for writing and editing
MATLAB® programs (called M-files) and can be invoked in Windows from the pull-down
menu after selecting File | New | M-file. The Command window is the main window in
which you communicate with the MATLAB® interpreter. The MATLAB® interpreter displays
a command “>>” which indicating that it is ready to accept commands from you.
The MATLAB® is usually use for technical computing integrates computation, visualization,
and programming in an easy-to-use environment where problems and solutions are
expressed in familiar mathematical notation. Typical uses include:
1. From the Task 1-4 below, run all tasks using MATLAB®.
>> intro
at the MATLAB prompt. This short introduction will demonstrate some basic MATLAB
commands.
>> help
>> help plot
>> help ops
>> help arith
4. Evaluate the expression a3 +√bd −4c , where a=1.2, b=2.3, c=4.5 and d=4.
Then in the Command window, type:
a=1.2;
b=2.3;
c=4.5;
d=4;
a^3+sqrt(b*d)-4*c
(Note: Put the semicolon after each variable assignment. If you omit the semicolon,
then MATLAB echoes back on the screen the variable value.)
Task 2: Plotting Graph
1. The function plot is used to generate line plots. The function stem is used to generate
“picket-fence” type of plots.
2. Type:
x=1:20;
plot(x) % see Figure 1
stem(x) % see Figure 2
Figure 1: Plot obtained using the plot function Figure 2: Plot obtained using the stem function
3. Type the program below and plot the graph obtained at Experiment Result. (Graph 1)
x=1:40;
subplot (2,1,1), plot(x)
subplot (2,1,2), stem(x) % see Graph 1
Task 3: Convolution
a = [3 2 4 3];
b = [4 4 5 6];
conv(a,b)
3. Type the program below and plot the graph obtained at Experiment Result. (Graph 2)
x =[0 1 1 1 1 1 1 1 1 1 1 1 1 1];
h = [1 0.5 0.25 0.125 0.0625];
y = conv(x,h);
nz = 10;
ly = length(y) + nz;
xz = [x, zeros(1,ly-length(x))];
hz = [h, zeros(1,ly-length(h))];
yz = [y, zeros(1,nz)];
nn = 0:ly-1;
subplot(3,1,1),stem(nn,xz,'filled'),axis([0 25 0 2]),
ylabel('x(nT)'), grid on
subplot(3,1,2),stem(nn,hz,'filled'),axis([0 25 0 2]),
ylabel('h(nT)'), grid on
subplot(3,1,3),stem(nn,yz,'filled'),axis([0 25 0 3]),
xlabel('Sample Index - n')
ylabel('y(nT)'), grid on % see Graph 2
(Note: Variables (array) x represents the input, y is the output, and h is the system.)
Task 4: Generate Sinusoidal Signal
1. A sinusoidal signal can be either sine or cosine time signal and it can be
expressed by:
Where = 2*pi*f
Therefore:
X(n) = A sin (2*pi*f*n + ), - < n <
2. Type the program below and plot the graph obtained at Experiment Result. (Graph 3).
n=0:40;
f=0.1;
P=0;
A=1;
arg=2*pi*f*n+P;
x=A*cos(arg);
clf; %clear and graph
subplot (2,1,1), plot (n,x), axis([0 40 -2 2]),
xlabel('Time index n'), ylabel ('Amplitude'),
title('Continuous Sinusoidal Signal'), grid on
subplot (2,1,2), stem (n,x), axis([0 40 -2 2]),
xlabel('Time index n'), ylabel ('Amplitude'),
title('Discrete Sinusoidal Signal'), grid on % see Graph 3