Beruflich Dokumente
Kultur Dokumente
MATLAB (MATrix LABoratory) is a Matrix Vector Oriented Programming language with significant
graphics capabilities
control c aborts running script file (often indicated as ^c, but ^ is short for control key, not carrot)
Other Notations % (percent sign) comment, anything to right is not read by matlab
% (percent sign) at top of m files is written to screen in response to help qwerty
; (semicolon) end row and suppress printing
: (colon) vector generation
… (ellipsis) continue line
‘ (single quote) transpose
( ) (left and right parenthesis) subscript enclosure
[ ] (left and right square bracket] matrix enclosure
, (comma) separator
examples:
a=3.4 a=[3.4] scalar
b=3.4+j*2.6 b=[3.4+j*2.6] scalar
dd=1:10 1 x 10 vector
ee=[1:5]’ 5 x 1 vector
PLOT(X,Y,'c+:') plots a cyan dotted line with a plus at each data point;
PLOT(X,Y,'bd') plots blue diamond at each data point but does not draw a line.
subplot(2,1,1)
plot(0:100,cos(2*pi*(1:100)/50))
hold on
plot(0:100,sin(2*pi*(1:100)/50),’- -‘,linewidth’,2)
hold off
grid on
axis([0 100 -1.2 1.2])
title(‘cosine(2*\pi*(1:100)/50)’)
xlabel(‘counting index’)
ylabel(‘amplitude’
subplot(2,1,2)
plot(0:100,sin(2*pi*(1:100)/50))
hold on
plot(0:5:100,sin(2*pi*(1:5:100)/50),’o’)
hold off
grid on
axis([0 100 -1.2 1.2])
Common Math Functions
complex operators
conj(aa) conjugates argument aa
real(aa) real part argument aa
imag(aa) imaginary part argument aa
abs(aa) absolute value of argument aa
angle(aa) atan2(imag(aa),real(aa))
polynomial operations
polyval(aa,x) evaluates polynomial with coefficients aa at argument values x
conv(aa,bb) convolves two polynomial sequence (product of two polynomials)
roots(aa) factors polynomial aa and lists roots
interesting operators
fliplr(aa) reverses order of row elements
flipud(aa) reverses order of column elements
fftshift(aa) swaps first half of array with second half
signal processing
fft(xx)
freqz(bb,aa)
zplane(bb,aa)
[bb,aa]= butter(nn,f1)
[bb,aa]= tcheby1(nn,r1,f1)
[bb,aa]= tcheby2(nn,r2,f1)
[bb,aa]= ellip(nn,r1,r2,f1)
filter(aa,bb,x)
sinc(t1:dt:t2)
hanning(nn)
kaiser(nn,beta)
programming
figure(1)
subplot(2,1,1)
stem(0:42,hh,'linewidth',2)
grid on
axis([-5 45 -0.1 0.5])
title('Impulse Response')
xlabel('Normalized Time: (t/T)')
ylabel('Amplitude')
subplot(2,1,2)
plot((-0.5:1/1024:0.5-1/1024),fftshift(20*log10(abs(fft(hh,1024)))),'linewidth',2);
grid on
axis([-0.5 0.5 -70 5])
title('Frequency Response')
xlabel('Normalized Frequency: (f/f_S)')
ylabel('Amplitude')