Académique Documents
Professionnel Documents
Culture Documents
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRIX LABORATORY [ MATLAB ]
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRIX LABORATORY [ MATLAB ]
MALAB is Used
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
GETTING STARTED WITH MATRIX LABORATORY [2016]
A Minimum MATLAB Session
Quit MATLAB
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
GETTING STARTED WITH MATRIX LABORATORY [2016]
Command Window
– to execute commands in the MATLAB environment
Figure Window
– to display graphical output from MATLAB code
Workspace Window
– to view variable definitions and variable memory allocations
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
GETTING STARTED WITH MATRIX LABORATORY [2016]
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
SOME FUNDAMENTAL MATLAB COMMANDS
command Purpose / Functionality
help displays the help for the functionality
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
USING MATLAB AS A CALCULATOR & QUITING
In order to evaluate any expression type at
prompt command >>
For example, let’s suppose you want to calculate the
expression, 1 + 2×3.
>> 1+2*3 >> 2.3+4.2 >> 2*pi
ans = 7 ans = 6.5000 ans = 6.2832
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
MATLAB NUMERICAL EXPRESSIONS & OPERATORS
By default MATLAB returns numerical expressions as
decimals with 5 digits.
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
MATLAB OPERATORS & SPECIAL CHARACTERS
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
PREDEFINED MATHEMATICAL FUNCTIONS IN MATLAB
MATLAB offers many predefined mathematical functions for
technical computing.
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
MATHEMATICAL FUNCTIONS IN MATLAB
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
MATHEMATICAL FUNCTIONS IN MATLAB EXAMPLES
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRICES & VECTORS IN MATLAB
Matrices are the basic elements of the MATLAB environment.
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRICES & VECTORS IN MATLAB
>>A(2) %% indexing
>>A(6:9) %% Colon operator
>> A(:) %%produces a column vector,
>> size(A)
1 2 3 4 5 6 7 8 9
1x9 vector
A(2) A(6:9)
16
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRICES & VECTORS IN MATLAB
To create a column vector B simply type in:
B = [3; 5; 0; 0; 1; 4; 9; -1; 1]
3 1
5 B(3)
B(1:4) 2
0 3
0 4
B = 1 5 9x1 vector
4 6
9 7
-1 8
19
B(6)
17
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRICES & VECTORS IN MATLAB
Practice 1: Investigate the effect of the
following commands:
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRICES & VECTORS IN MATLAB
Practice 2: Investigate the effect of the
following commands:
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRICES & VECTORS IN MATLAB
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRICES & VECTORS IN MATLAB
Matrix Indexing
>> A(2,1)
ans = 4
>> A(3,3)
ans = 9
>>A(3,3) = 0
A = 1 2 3
4 5 6
7 8 0
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRICES & VECTORS IN MATLAB
COLON OPERATOR
The colon operator will prove very useful and
understanding how it works is the key to efficient and
convenient usage of MATLAB.
For example, suppose we want to enter a vector x
consisting of points (0,0.1,0.2,0.3,··· ,5).
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRICES & VECTORS IN MATLAB
A = 1 2 3 Deleting Row/ Column
4 5 6
7 8 0 >> A(:,2)=[]
ans = 1 3
>> A(2,:) 4 6
ans = 4 5 6 7 0
is the second row elements of A row or a column of a matrix can
be deleted by setting it to a null
A.
vector, [ ].
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO MATRIX GENERATORS IN MATLAB
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO BASIC PLOTTING IN MATLAB
MATLAB has an excellent set of graphic tools.
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO BASIC PLOTTING IN MATLAB
>> x = [1 2 3 4 5 6];
>> y = [3 -1 2 4 5 1];
>> plot(x,y)
>> plot(y,x)
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO BASIC PLOTTING IN MATLAB
>> x = [1 2 3 4 5 6];
>> y = [3 -1 2 4 5 1];
>> plot(x,y)
>> plot(y,x)
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO BASIC PLOTTING IN MATLAB
Plot the function sin(x) on the interval [0,2π]
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
ADDING TITLES, AXIS LABELS, AND ANNOTATIONS
>> x = 0:pi/100:2*pi;
>> y = sin(x);
>> plot(x,y)
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
INTRODUCTION TO BASIC PLOTTING IN MATLAB
Multiple (x,y) pairs arguments create multiple graphs with a
single call to plot.
For example, these statements plot three related functions
of x: y1 = 2cos(x), y2 = cos(x), and y3 = 0.5∗cos(x), in the
interval 0≤x≤2π
>> x = 0:pi/100:2*pi;
>> y1 = 2*cos(x);
>> y2 = cos(x);
>> y3 = 0.5*cos(x);
>> plot(x,y1,'--',x,y2,'-',x,y3,':')
>> xlabel('0 \leq x \leq 2\pi')
>> ylabel('Cosine functions')
>> legend('2*cos(x)','cos(x)','0.5*cos(x)')
>> title('Typical example of multiple plots')
>> axis([0 2*pi -3 3])
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
PLOTTING IN MATLAB
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018
BASIC OPERATIONS ON SIGNALS ( LAB 2 )
Objective:
Following are the main objectives of this lab.
1. To perform basic operations of signals
Time Scaling
Time Reversal
Time Shift
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | MARCH 12, 2018
BASIC OPERATIONS ON SIGNALS ( LAB 2 )
f=1;
w=2*pi*f;
t=-5:0.01:5;
x = sawtooth(w*t);
b = 2; % Scaling Factor
x1 = sawtooth(w*b*t);
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | MARCH 12, 2018
BASIC OPERATIONS ON SIGNALS ( LAB 2 )
t=-3:0.01:3;
x = exp(t);
xrev= exp(-t);
plot(t, x, 'red', t, xrev, 'blue');
axis([-3 3 0 5]);
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | MARCH 12, 2018
BASIC OPERATIONS ON SIGNALS ( LAB 2 )
Plot function x(t)=e-3t, its time delayed x(t-1)
and its time advanced version x(t+1).
t=-3:0.01:3;
t1 = 1;
a=3;
x = exp(-a*t); % original
x1 = exp(-a*(t-t1)); %delayed
t1=-1;
x2 = exp(-a*(t-t1)); %advanced
plot(t, x, 'red', t, x1, 'green', t, x2, 'blue');
axis([-3 3 0 5]);
grid on
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | MARCH 12, 2018
FOURIER SERIES REPRESENTATION OF SIGNALS ( LAB 2 )
Generating various complex waveforms to verify
Fourier theorem.
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | MARCH 12, 2018
FOURIER SERIES REPRESENTATION OF SIGNALS ( LAB 2 )
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | MARCH 12, 2018
FOURIER SERIES REPRESENTATION OF SIGNALS ( LAB 2 )
f=1; % frequency of the signal
w=2*pi*f; % angular frequency
t=0:0.01:2; % total time of the signal
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | MARCH 12, 2018
FOURIER SERIES REPRESENTATION OF SIGNALS ( LAB 2 )
The above can also be implemented using the for loop to make the things
efficient.
y=0;
f=1;
w=2*pi*f;
t=0:0.01:2;
for n=1:10
y= y + (1/n)*sin(n*w*t);
end
plot(t,y)
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | MARCH 12, 2018
FOURIER SERIES REPRESENTATION OF SIGNALS ( LAB 2 )
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | MARCH 12, 2018
FOURIER SERIES REPRESENTATION OF SIGNALS ( LAB 2 )
% Fourier_ Square wave
f=1;
w=2*pi*f;
t=0:0.01:2;
% Using 7 terms to plot the Fourier series of a
Square wave
a=1*sin(w*t);
b=(1/3)*sin(3*w*t);
c=(1/5)*sin(5*w*t);
d=(1/7)*sin(7*w*t);
e=(1/9)*sin(9*w*t);
f=(1/11)*sin(11*w*t);
g=(1/13)*sin(13*w*t);
y = a+b+c+d+e+f+g;
plot(t,y)
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | MARCH 12, 2018
INTRODUCTION TO MATRIX LABORATORY [ MATLAB ]
The Language of Technical & Physical Computing
arif.hussain@iba-suk.edu.pk
SIGNALS & SYSTEMS [Spring 2018] | MATLAB WORKSHOP | JANUARY 29, 2018