Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Reference Books:
MATLAB -- high-performance numeric computation and
visualization software
Contemporary Communication Systems Using MATLAB
Internet Web Resources:
http://www.mathworks.com/products/
http://www.math.utah.edu/lab/ms/matlab/matlab.html
http://www-h.eng.cam.ac.uk/help/tpl/programs/matlab.html
Dr. C. N.
Georghiades
Introduction To Matlab
Interpreted language
Efficient in manipulating vectors and matrices
Slow in handling loops
Case sensitive
type
dir
cd
Inverse:
inv(m)
Inverse:
inv(m)
Eigenvalue/vector
Eigenvalue/vector decomposition:
decomposition:
[[v,v,ee]]==eig(m)
eig(m)
Diagonal:
diag(m)
Diagonal:
diag(m)
Determinant:
det(m)
Determinant:
det(m)
* vs .*
/ vs
./
IfIfthe
thevector/matrixs
vector/matrixsdimensionality
dimensionalityisistoo
toolarge
large(say
(say100000),
100000),
cut
cutititinto
intosegments
segmentsto
toavoid
avoidmemory
memoryoverflow
overflowand
andwriting
writingto
todisk
disk
which
whichslows
slowsprocessing.
processing.
Dr. C. N.
Georghiades
norm
Functions can
operate
on vectors
spectrum
Other
Othercommands:
commands:(check
(checkhelp)
help)
figure
figure axis
axis stem
stem bar
bar legend
legend hold
hold
Dr. C. N.
Georghiades
One plot:
>> x= [0:0.05:2*pi];
>> figure(1);
>> subplot(1,2,1); plot(x,sin(x));
>> title(sin);grid on;axis([0 2*pi -1 1]);
>> subplot(1,2,2); plot(x,cos(x));
>> titel(cos);grid on;axis([0 2*pi -1 1]);
>> x= [0:0.05:2*pi];
>> figure(2);
>> plot(x,sin(x),--,x,cos(x),:);
>> legend(sin, cos);
>> grid on;
>> axis([0 2*pi -1 1]);
Dr. C. N.
Georghiades
B= 1 3 2
2 2 1
3 1 3
B= 1 3 2
0 -4 -3
0 0 3
Tips:
* Avoid loops.
Use reasonable vector operation instead if possible.
* Make operations inside loops as few as possible.
Dr. C. N.
Georghiades
break command:
terminates
execution of
while or for
loop.
. loops,
In nested
break exits
from the
innermost
loop only.
Matlab: If Statement
>> % check for determinant
>> % before do inverse
>> if det(A) ~= 0,
B = inv(A);
end;
Dr. C. N.
Georghiades
if end;
if else end;
if elseif elseif else end;
allow nested if statements.
10
..
Matlab
Matlabdata
datafile
file((mat-file
mat-file):):
>>
>>save
saveresult.mat
result.matdB,
dB,Pb
Pb
.
.
>>
>>load
loadresult.mat
result.mat
>>
>>whos
whos
..
%%save
savevariables
variablesdB
dBand
andPb
Pbininresult.mat
result.mat
%%load
loadfile
file
%%check
checkwhat
whatvariables
variablesare
areloaded
loaded
Note:
Dr. C. N.
Georghiades
11
Save as
N=max(size(A));
gaussElim.m
for j = 2:N,
for k = k:N,
m = A(k,j-1)/A(j-1,j-1);
A(k,:) = A(k,:)-A(j-1,:)*m;
b(k) = b(k)-m*b(j-1);
end;
end;
x=zeros(N,1);
x(N)=b(N)/A(N,N);
for k=N-1:-1:1,
x(k)=(b(k)A(k,k+1:N)*x(k+1:N)/A(k,k);
end;
Dr. C. N.
Georghiades
>>A = [1 2 3 6; 4 3 2 3;
9 9 1 -2; 4 2 2 1];
>>B = [1 2 1 4];
>>C = gaussElim(A,B);
A=1 2 3 6 B=1 C= 0.6809
433 3
2
-0.8936
9 9 1 -2
1
1.8085
422 1
4
-0.5532
When you want to repeat a
sequence of commands with
different variables as input
Too many subroutines may slow
down performance
12
13
Dr. C. N.
Georghiades
% Gaussian noise
v= 1/sqrt(2*10^(dB/10);
AWGN=randn(1,fs)*v;
% add noise
y0=x0+AWGN;
y1=x1+AWGN;
% pass through matched filter
z0=filter(y0,1,H);
z1=filter(y1,1,H);
% reconstruct original signal
x0_hat=sign(z0(fs))*s;
x1_hat=sign(z1(fs))*s;
14
0.2
0.15
0.15
x0
0.1
-0.05
x1
-0.05
x0_hat
0.1
-0.1
0.05
-0.15
-0.15
-0.2
-2
-1.5
-1
-0.5
0.5
1.5
-2
-0.2
-1.5
-1
-0.5
0.5
1.5
-2
-1.5
-1
-0.5
AWGN
0.5
1.5
-2
0.8
1.2
0.4
0.6
0.2
y0
y1
0.4
-1.5
-1
-0.5
0.5
1.5
Reconstruct signal
0.8
0.6
x1_hat
-0.1
0.05
0.8
0
0.4
0.6
0.2
-0.2
0.2
z0
0.4
0
0
0.2
-0.2
-0.4
-0.2
z1
-0.6
0
-0.4
-0.4
-0.8
-0.2
-0.6
-0.6
-0.8
-2
-1.5
-1
-0.5
0.5
1.5
-0.8
-2
-0.4
-2
-1.5
-1
-0.5
0.5
1.5
-1.5
-1
-0.5
0.5
1.5
-1
-2
-1.5
-1
-0.5
0.5
1.5
0.2
0. 15
0.1
Matched Filter
0. 05
-2
Dr. C. N.
Georghiades
-1.5
-1
-0.5
0.5
1.5
15