Вы находитесь на странице: 1из 48

,

MATLAB 6.5.0.

, ;
,
; MATLAB,
- ;
MATLAB m-;
MATLAB MATLAB
.
,
.

, MATLAB. MATLAB
.

, .
,
.
HELP MATLAB,
, MATLAB,
.
. ,
MATLAB
.

1
: .
: ,
.
:
,
, , ,
.
() ,
.
,
. , , ,
MATLAB
,
.
MATLAB
.
MATLAB, m-,
.
(F5), (Ctrl+S).
MATLAB

:

ones

pi

rand

randn

zeros


cos

exp

imag

real


axis

grid

legend

plot

stairs

stem

title

xlabel

ylabel


clf

subplot

1_1
.
% P1_1
%
clf;
% -10 20
n=-10:20;
%
u=[zeros(1,10) 1 zeros(1,20)];
%
stem(n,u);
xlabel(' n'); ylabel('');
title(' ');
axis([-10 20 0 1.2]);

1_2

.
MATLAB: .^ exp.
- .
% P1_2
%
clf;
5

c=-(1/12)+(pi/6)*i;
K=2;
n=0:40;
x=K*exp(c*n);
subplot(2,1,1);
stem(n,real(x));
xlabel(' n'); ylabel('');
title(' ');
subplot(2,1,2);
stem(n,imag(x));
xlabel(' n'); ylabel('');
title(' ');

1_3

.
% P1_3
%
clf;
n=0:35; a=1.2; K=0.2;
x=K*a.^n;
stem(n,x);
xlabel(' n'); ylabel('');

1_4
, ,
.
MATLAB sin cos.
% P1_4
%
clf;
n=0:40;
f=0.1;
phase=0;
A=1.5;
arg=2*pi*f*n - phase;
x=A*cos(arg);
stem(n,x); %
axis([0 40 -2 2]);
grid;
title('');
xlabel(' n'); ylabel('');
axis;

1_5

. s[n] ,
d[n] x[n] = s[n] + d[n].
x[n] , y[n],
s[n]. : y[n] =
(x[n-1] + x[n] = x[n+1]), .
% P1_5
%
clf;
R=51;
d=0.8*(rand(R,1)-0.5); %
m=0:R-1;
s=2*m.*(0.9.^m); %
x=s+d'; %
subplot(2,1,1);
plot(m,d','r-',m,s,'g--',m,x,'b-.');
xlabel(' n'); ylabel('');
legend('d[n] ','s[n] ','x[n] ');
x1=[0 0 x]; x2=[0 x 0]; x3=[x 0 0];
y=(x1+x2+x3)/3;
subplot(2,1,2);
plot(m,y(2:R+1),'r-',m,s,'g--');
legend('y[n] ','s[n] ');
xlabel(' n'); ylabel('');

1_6
,


. :
- .

A cos( 0 n), ,

x[n],

, y[n], :
y[n] = A x[n] cos( 0 n)
% P1_6
%
clf;
n=0:150;
m=0.8; fH=0.1; fL=0.01;
xH=sin(2*pi*fH*n);
9

xL=sin(2*pi*fL*n);
y=(1+m*xL).*xH;
stem(n,y); grid;
xlabel('Time n'); ylabel('Amplitude');

1_7
.
, ,
. ,
: an2 +bn, 1_7 .
% P1_7
%
n=0:100;
a=pi/2/500;
b=0;
arg=a*n.*n+b*n;
x=sin(arg);
clf;
stem(n,x);
axis([0, 100, -1.5, 1.5]);
title(' ');
xlabel(' n'); ylabel('');
grid; axis;

10

2
:

.
:

.
, .

, .

11

x[n]=x1[n]+x2[n]
y[n]=y1[n]+y2[n], y1[n] y2[n]
x1[n] x2[n] .
x[n]=x1[nn0] y[n]=y1[n-n0], n0
y1[n] x1[n].
(Linear Time-Invariant LTI)
.
y1[n] y2[n] u1[n]
u2[n] , u1[n]= u2[n], n<N , y1[n]= y2[n],
n<N.
MATLAB

disp

<


break

end

for

if

input


ones

pi

zeros


abs

cos


conv


axis

plot

stem

title

xlabel

ylabel


clf

subplot


num2str


filter

impz

12

2_1
-,
.
% P2_1
% FIR M
%
clf;
n=0:100;
s1=cos(2*pi*0.05*n); % -
s2=cos(2*pi*0.47*n); % -
x=s1+s2;
% FIR
M=input(' = ');
num=ones(1,M);
y=filter(num,1,x)/M;
%
subplot(2,2,1);
plot(n,s1);
axis([0, 100, -2, 2]);
xlabel(' n'); ylabel('');
title(' #1');
subplot(2,2,2);
plot(n,s2);
axis([0, 100, -2, 2]);
xlabel(' n'); ylabel('');
title(' #2');
subplot(2,2,3);
plot(n,x);
axis([0, 100, -2, 2]);
xlabel(' n'); ylabel('');
title(' ');
subplot(2,2,4);
plot(n,y);
axis([0, 100, -2, 2]);
xlabel(' n'); ylabel('');
title(' ');
axis;

13

2_2

x[n], .
% P2_2
%
clf;
n=0:200;
x=cos(2*pi*0.05*n);
%
x1 = [x 0 0]; % x1[n] = x[n+1]
x2 = [0 x 0]; % x2[n] = x[n]
x3 = [0 0 x]; % x3[n] = x[n-1]
y=x2.*x2 + x1.*x3;
y=y(2:202);
%
subplot(2,1,1);
plot(n,x);
xlabel(' n'); ylabel('');
title(' ');
subplot(2,1,2);
plot(n,y);
xlabel(' n'); ylabel('');
title(' ');

14

2_3
, :
y[n]-0.4y[n-1]+0.75y[n-2]=2.2403x[n]+2.4908x[n-1]+2.2403x[n-2].
x1[n], x2[n] x[n]=a*x1[n]+b*x2[n].
y1[n], y2[n] y[n],
.
% P2_3
%
clf;
n=0:40;
a=2; b=-3;
x1=cos(2*pi*0.1*n);
x2=cos(2*pi*0.4*n);
x=a*x1+b*x2;
num=[2.2403 2.4908 2.2403];
den=[1 -0.4 0.75];
ic=[0 0]; %
y1=filter(num,den,x1,ic); % y1[n]
y2=filter(num,den,x2,ic); % y2[n]
y=filter(num,den,x,ic); % y[n]
yt=a*y1+b*y2;
d=y-yt; % d[n]
%
subplot(3,1,1);
stem(n,y);
ylabel('');
title(' , : a \cdot x_{1}[n]
+ b \cdot x_{2}[n]');
15

subplot(3,1,2);
stem(n,yt);
ylabel('');
title(' : a \cdot y_{1}[n] + b \cdot y_{2}[n]');
subplot(3,1,3);
stem(n,d);
xlabel(' n'); ylabel('');
title(' ');

2_4
: y[n]-0.4y[n-1]+0.75y[n2]=2.2403x[n]+2.4908x[n-1]+2.2403x[n-2].
x[n] x[n-D].
y1[n] y2[n+D].
% P2_4
%
clf;
n=0:40; D=10; a=3.0; b=-2;
x=a*cos(2*pi*0.1*n)+b*cos(2*pi*0.4*n);
16

xd=[zeros(1,D) x];
num=[2.2403 2.4908 2.2403];
den=[1 -0.4 0.75];
ic=[0 0]; %
% y[n]
y=filter(num,den,x,ic);
% yd[n]
yd=filter(num,den,xd,ic);
% d[n]
d=y-yd(1+D:41+D);
%
subplot(3,1,1);
stem(n,y);
ylabel('');
title(' y[n]'); grid;
subplot(3,1,2);
stem(n,yd(1:41));
ylabel('');
title([', x[n ',num2str(D),']']); grid;
subplot(3,1,3);
stem(n,d);
xlabel(' n'); ylabel('');
title(' '); grid;

17

2_5

:
y[n]-0.4y[n-1]+0.75y[n-2]=2.2403x[n]+2.4908x[n-1]+2.2403x[n-2].
% P2_5
% y
clf;
N=40;
num=[2.2403 2.4908 2.2403];
den=[1 -0.4 0.75];
y=impz(num,den,N);
%
stem(y);
xlabel(' n'); ylabel('');
title(' '); grid;

2_6
: y[n]+1.6y[n-1]+2.28y[n2]+1.325y[n-3]+0.68y[n-4]

0.06x[n]-0.19x[n-1]+0.27x[n-2]-0.26x[n-3]+0.12x[n-4]

:
1: y1[n]+0.9y1[n-1]+0.8y1[n-2]=0.3x[n]-0.3x[n-1]+0.4x[n-2];
2: y2[n]+0.7y2[n-1]+0.85y2[n-2]=0.2y1[n]-0.5y1[n-1]+0.3y1[n-2];
% P2_6
%
clf;
18

x=[1 zeros(1,40)]; %
n=0:40;
%
den=[1 1.6 2.28 1.325 0.68];
num=[0.06 -0.19 0.27 -0.26 0.12];
%
y=filter(num,den,x);
%
num1=[0.3 -0.2 0.4]; den1=[1 0.9 0.8];
num2=[0.2 -0.5 0.3]; den2=[1 0.7 0.85];
% y1[n]
y1=filter(num1,den1,x);
% y2[n]
y2=filter(num2,den2,y1);
% y[n] y2[n]
d=y-y2;
%
subplot(3,1,1);
stem(n,y);
ylabel('');
title(' '); grid;
subplot(3,1,2);
stem(n,y2);
ylabel('');
title(' '); grid;
subplot(3,1,3);
stem(n,d);
xlabel(' n'); ylabel('');
title(' '); grid;

19

2_7
MATLAB conv.
.
% P2_7
clf;
h=[3 2 1 -2 1 0 -4 0 3]; %
x=[1 -2 3 -4 3 2 1]; %
y=conv(h,x);
n=0:14;
subplot(2,1,1);
stem(n,y);
xlabel(' n'); ylabel('');
title(' , '); grid;
x1=[x zeros(1,8)];
y1=filter(h,1,x1);
subplot(2,1,2);
stem(n,y1);
xlabel(' n'); ylabel('');
title(' , '); grid;

20

2_8
.
% P2_8
% ,
%
clf;
num=[1 -0.8]; den=[1 1.5 0.9];
N=200;
h=impz(num,den,N+1);
parsum=0;
for k=1:N+1;
parsum=parsum+abs(h(k));
if abs(h(k))<10^(-6), break, end
end
%
n=0:N;
stem(n,h);
xlabel(' n'); ylabel('');
disp('='); disp(abs(h(k))); % abs(h(k))

21

2_9
: y[n] = 0.5x[n]+0.27x[n-1]+0.77x[n-2]
y[n] = 0.45x[n] +0.5x[n-1]+0.45x[n-2]+0.53y[n-1]-0.46y[n-2].
% P2_9
%
clf;
n=0:299;
x1=cos(2*pi*10*n/256);
x2=cos(2*pi*100*n/256);
x=x1+x2;
%
num1=[0.5 0.27 0.77];
y1=filter(num1,1,x); % #1
den2=[1 -0.53 0.46];
num2=[0.45 0.5 0.45];
y2=filter(num2,den2,x); % #2
%
subplot(2,1,1);
plot(n,y1); axis([0 300 -2 2]);
ylabel('');
title(' #1'); grid;
subplot(2,1,2);
plot(n,y2); axis([0 300 -2 2]);
xlabel(' n'); ylabel('');
title(' #2'); grid;

22

3
: :
(DTFT) Z-.
: .
:
(DTFT) (Discrete-Time Fourier
Transform) X(ej) x[n] .
MATLAB , X(ej)
. ,
DTFT, e-j
:
(1)

23

.
f (t ) , ,

F ( ) = e 2iwt f (t )dt

(2). F ( )

f (t ) = e 2iwt F ( )d

(3).

f (t ) F ( w) .

f (t a) e 2 iw aF ( w) .

f (t ) F ( w), g (t ) G ( w), af (t ) + bg (t ) aF ( w) + bG ( w)

h(t ) = f (t ) * g (t ) , :
h(t ) =

f (t x) g ( x)dx . h(t ) F (w)G(w) .

f (t ) g (t ) F ( w) * G ( w) .
, , f (t ) - . ,

f ( x) 2wiF ( w) .

F ( w) = F ( w)

(3).
MATLAB

disp

<

>

.*

.^

~=


break

end

error

for

function

if

input

pause


fliplr

pi

zeros


abs

angle

conj

exp

imag

real

rem

24


conv


axis

grid

plot

stem

title

xlabel

ylabel


clf

subplot


num2str


fft

ifft

max

min


freqz

impz

residuez

tf2zp

zp2cos

zp2tf

zplane

3_1
DTFT,
.
% P3_1
% DTFT
clf;
% DTFT
w=-4*pi:8*pi/511:4*pi;
num=[2 1]; den=[1 -0.6];
h=freqz(num,den,w);
% DTFT
subplot(2,1,1);
plot(w/pi,real(h)); grid
title(' H(e^{j\omega})');
xlabel('\omega /\pi');
ylabel('');
subplot(2,1,2);
plot(w/pi,imag(h)); grid
title(' H(e^{j\omega})');
xlabel('\omega /\pi');
ylabel('');
pause
subplot(2,1,1);
plot(w/pi,abs(h)); grid
title(' |H(e^{j\omega})|');
xlabel('\omega /\pi');
ylabel('');
subplot(2,1,2);
plot(w/pi,angle(h)); grid
title(' arg[H(e^{j\omega})]');
xlabel('\omega /\pi');
ylabel(', ');
:

25

3_2

DTFT.
% P3_2
% DTFT
clf;
w=-pi:2*pi/255:pi; wo=0.4*pi; D=10;
num=[1 2 3 4 5 6 7 8 9];
h1=freqz(num,1,w);
h2=freqz([zeros(1,D) num],1,w);
subplot(2,2,1);
plot(w/pi,abs(h1)); grid
title(' ');
26

subplot(2,2,2);
plot(w/pi,abs(h2)); grid
title(' ');
subplot(2,2,3);
plot(w/pi,angle(h1)); grid
title(' ');
subplot(2,2,4);
plot(w/pi,angle(h2)); grid
title(' ');
:

3_3
DTFT.
% P3_3
% DTFT
clf;
w=-pi:2*pi/255:pi; wo=0.4*pi;
num1=[1 3 5 7 9 11 13 15 17];
L=length(num1);
h1=freqz(num1,1,w);
n=0:L-1;
num2=exp(wo*i*n).*num1;
h2=freqz(num2,1,w);
subplot(2,2,1);
plot(w/pi,abs(h1)); grid
title(' ');
subplot(2,2,2);
plot(w/pi,abs(h2)); grid
title(' ');
27

subplot(2,2,3);
plot(w/pi,angle(h1)); grid
title(' ');
subplot(2,2,4);
plot(w/pi,angle(h2)); grid
title(' ');
:

3_4
DTFT.
% P3_4
% DTFT
clf;
w=-pi:2*pi/255:pi;
x1=[1 3 5 7 9 11 13 15 17];
x2=[1 -2 3 -2 1];
y=conv(x1,x2);
h1=freqz(x1,1,w);
h2=freqz(x2,1,w);
hp=h1.*h2;
h3=freqz(y,1,w);
subplot(2,2,1);
plot(w/pi,abs(hp)); grid;
title(' ');
subplot(2,2,2);
plot(w/pi,abs(h3)); grid;
title(' ');
subplot(2,2,3);
plot(w/pi,angle(hp)); grid;
title(' ');
subplot(2,2,4);
plot(w/pi,angle(h3)); grid;
title(' ');
:
28

3_5
DTFT.
% P3_5
% DTFT
clf;
w=-pi:2*pi/255:pi;
x1=[1 3 5 7 9 11 13 15 17];
x2=[1 -1 1 -1 1 -1 1 -1 1];
y=x1.*x2;
h1=freqz(x1,1,w);
h2=freqz(x2,1,w);
h3=freqz(y,1,w);
subplot(3,1,1);
plot(w/pi,abs(h1)); grid
title(' ');
subplot(3,1,2);
plot(w/pi,abs(h2)); grid
title(' ');
subplot(3,1,3);
plot(w/pi,abs(h3)); grid
title(' ');
:

29

3_6
() DTFT.
% P3_6
% DTFT
clf;
w=-pi:2*pi/255:pi;
num=[1 2 3 4];
L=length(num)-1;
h1=freqz(num,1,w);
h2=freqz(fliplr(num),1,w);
h3=exp(w*L*i).*h2;
subplot(2,2,1);
plot(w/pi,abs(h1)); grid
title(' ');
subplot(2,2,2);
plot(w/pi,abs(h3)); grid
title(' c ');
subplot(2,2,3);
plot(w/pi,angle(h1)); grid
title(' ');
subplot(2,2,4);
plot(w/pi,angle(h3)); grid
title(' c ');
30

3_7

. MATLAB circshift.
% P3_7
%
clf;
M=6;
a=[0 1 2 3 4 5 6 7 8 9];
b=circshift(a, [0 M]);
L=length(a)-1;
n=0:L;
subplot(2,1,1);
stem(n,a); axis([0,L,min(a),max(a)]);
title(' ');
subplot(2,1,2);
stem(n,b); axis([0,L,min(a),max(a)]);
title(', ');
:

31

3_8
DTFT.
% P3_8
% DTFT
clf;
x=[0 2 4 6 8 10 12 14 16];
N=length(x)-1; n=0:N;
y=circshift(x, [0 5]);
XF=fft(x);
YF=fft(y);
subplot(2,2,1);
stem(n,abs(XF)); grid
title('DFT ');
subplot(2,2,2);
stem(n,abs(YF)); grid
title('DFT ');
subplot(2,2,3);
stem(n,angle(XF)); grid
title(' DFT ');
subplot(2,2,4);
stem(n,angle(YF)); grid
title(' DFT ');
:

32

3_9
DFT

DFT .
% P3_9
% DFT-
%
x=[1 2 4 2 6 32 6 4 2 zeros(1,247)];
x1=[x(1) x(256:-1:2)];
xe=0.5*(x+x1);
XF=fft(x);
XEF=fft(xe);
clf;
k=0:255;
subplot(2,2,1);
plot(k/128,real(XF)); grid;
ylabel('');
title('Re(DFT\{x[n]\})');
subplot(2,2,2);
plot(k/128,imag(XF)); grid;
ylabel('');
title('Im(DFT\{x[n]\})');
subplot(2,2,3);
plot(k/128,real(XEF)); grid;
xlabel(' n'); ylabel('');
title('Re(DFT\{x_{e}[n]\})');
subplot(2,2,4);
plot(k/128,imag(XEF)); grid;
xlabel(' n'); ylabel('');
33

title('Im(DFT\{x_{e}[n]\})');
:

4
: .
:
.
:


. ,
.

.

34

. DTFT z-
,
.
, ,

.
MATLAB

disp


function

pause


fliplr

pi


abs

angle

imag

log10

real

stem

title


axis

grid

plot

xlabel

ylabel

impz

poly2rc


clf

subplot


filter

filtfilt

freqz

grpdelay

sinc

zplane

4_1
.
MATLAB sinc.
% P4_1
%
clf;
fc=0.25;
n=[-6.5:1:6.5];
y=2*fc*sinc(2*fc*n);
k=n+6.5;
stem(k,y); title('N=13'); axis([0 13 -0.2 0.6]);
xlabel(' n'); ylabel(''); grid

35

4_2
,
% P4_2
%
clf;
M=2;
num=ones(1,M)/M;
w=0:pi/255:pi;
h=freqz(num,1,w);
g=20*log10(abs(h));
plot(w/pi,g); grid
axis([0 1 -50 0.5]);
xlabel('\omega /\pi'); ylabel('');
title(['M = ',num2str(M)]);

36

4_3

, :
1: ;
2: ;
3: ;
4: .
% P4_3
% FIR
clf;
b=[1 -8.5 30.5 -63]
num1=[b 81 fliplr(b)];
num2=[b 81 81 fliplr(b)];
num3=[b 0 -fliplr(b)];
37

num4=[b 81 -81 -fliplr(b)];


n1=0:length(num1)-1;
n2=0:length(num2)-1;
subplot(2,2,1); stem(n1,num1);
xlabel(' n'); ylabel('');
title(' 1 FIR ');
subplot(2,2,2); stem(n2,num2);
xlabel(' n'); ylabel('');
title(' 2 FIR ');
subplot(2,2,3); stem(n1,num3);
xlabel(' n'); ylabel('');
title(' 3 FIR ');
subplot(2,2,4); stem(n2,num4);
xlabel(' n'); ylabel('');
title(' 4 FIR ');
pause
subplot(2,2,1); zplane(num1,1);
title(' 1 FIR ');
subplot(2,2,2); zplane(num2,1);
title(' 2 FIR ');
subplot(2,2,3); zplane(num3,1);
title(' 3 FIR ');
subplot(2,2,4); zplane(num4,1);
title(' 4 FIR ');
disp(' FIR 1');
disp(roots(num1));
disp(' FIR 2');
disp(roots(num2));
disp(' FIR 3');
disp(roots(num3));
disp(' FIR 4');
disp(roots(num4));

grid
grid
grid
grid

38

b = 1.0000 -8.5000 30.5000 -63.0000


Nuli FIR filitra tipa 1
2.9744
2.0888
0.9790 + 1.4110i
0.9790 - 1.4110i
0.3319 + 0.4784i
0.3319 - 0.4784i
0.4787
0.3362

Nuli FIR filitra tipa 2


3.7585 + 1.5147i
3.7585 - 1.5147i
0.6733 + 2.6623i
0.6733 - 2.6623i
-1.0000
0.0893 + 0.3530i
0.0893 - 0.3530i
0.2289 + 0.0922i
0.2289 - 0.0922i

Nuli FIR filitra tipa 3


4.7627
1.6279 + 3.0565i
1.6279 - 3.0565i
-1.0000
1.0000
0.1357 + 0.2549i
0.1357 - 0.2549i
0.2100

Nuli FIR filitra tipa 4


3.4139
1.6541 + 1.5813i
1.6541 - 1.5813i
-0.0733 + 0.9973i
-0.0733 - 0.9973i
1.0000
0.3159 + 0.3020i
0.3159 - 0.3020i
0.2929

4_4
IIR
. .
IIR
.
% P4_4
%
39

clf;
den=input(' : ');
ki=poly2rc(den);
disp(' : ');
disp(ki);
:
Vvedite koefficienty znamenatelia: 10
Parametry testa na ustoiichivosti:

5
:

:
.
:

.
, ,
,
,
, , .
: - ,

cos(2 w0 t ) [ ( w w0 ) + ( w + w0 )] / 2 .


x(t ) , S .

y[n] = x(nS ) .

Y ( w) =

y[n]e

n =

2 wiSn

(4).

Y (w) .
S = 1 , 1.

40

. ,
. u (t ) =

(t nS ) .

n =

Y ( w) = u (t ) x(t )e 2 wit dt (5),

, - . ,

.

S =1.

U (w) =

u (t ) e

2 wit

dt .

U N ( w) =

(t n)e 2iwt dt =

n = N

2 iwn

n= N

. ,

1,
. : U N ( w) =
.

(w)U N (w)dw =

e 2 iNw e 2 i ( N +1) w
. e iw
2 iw
1 e

U N ( w) =

sin( 2 ( N + 1 / 2) w)
.
sin(w)

( w) sin(2 ( N + 1 / 2) w)
dw
iw
c

(0) .

N
n

(t Sn) (w S ) / S

S :

(6)

.
.
(5) (6) ,
, :
n
Y ( w) = U ( w) * X ( w) , x(t ) X ( w) , Y ( w) = X ( w ) / S
S

(7)

. , Y (w) 1 / S ,
(4).

41

MATLAB

length

size

==

&

ones

linspace

pi


abs

cos

exp


axis

plot

stem

title

xlabel

ylabel


clf

grid

plot

stem

subplot


butter
ellipord

buttord
freqz

cheb1ord

cheb2ord

cheby1

cheby2

ellip

sinc

5_1

, .
% P5_1
%
clf;
t=0:0.0005:1;
f=13;
xa=cos(2*pi*f*t);
subplot(2,1,1);
plot(t,xa); grid;
xlabel(', '); ylabel('');
title(' x_{a}(t)');
axis([0 1 -1.2 1.2]);
subplot(2,1,2);
T=0.1;
n=0:T:1;
xs=cos(2*pi*f*n);
k=0:length(n)-1;
stem(k,xs); grid;
xlabel(' n'); ylabel('');
title(' x[n]');
axis([0 (length(n)-1) -1.2 1.2]);

42

5_2
.
,

. .
% P5_2
% ""
clf;
T=0.1; f=13;
n=(0:T:1)';
xs=cos(2*pi*f*n);
t=linspace(-0.5,1.5,500)';
ya=sinc((1/T)*t(:,ones(size(n))) - (1/T)*n(:,ones(size(t)))')*xs;
plot(n,xs,'o',t,ya); grid;
xlabel(', '); ylabel('');
title(' y_{a}(t)');
axis([0 1 -1.2 1.2]);

43

5_3

, , .
% P5_3
% ""
clf;
t=0:0.005:10;
xa=2*t.*exp(-t);
subplot(2,2,1);
plot(t,xa); grid;
xlabel(', '); ylabel('');
title(' x_{a}(t)');
subplot(2,2,2);
wa=0:10/511:10;
ha=freqs(2,[1 2 1],wa);
plot(wa/(2*pi),abs(ha)); grid;
xlabel(', '); ylabel('');
title('|X_{a}(j/Omega)|');
axis([0 5/pi 0 2]);
subplot(2,2,3);
T=1;
n=0:T:10;xs=2*n.*exp(-n);
k=0:length(n)-1;
stem(k,xs); grid;
xlabel(' n'); ylabel('');
title(' x[n]');
subplot(2,2,4);
wd=0:pi/255:pi;
hd=freqz(xs,1,wd);
plot(wd/(T*pi),T*abs(hd)); grid;
xlabel(', '); ylabel('');
title('|X(e^{j/omega})|');
axis([0 1/T 0 2]);
44

5_4

.
% P5_4
%
clf;
Fp=3500; Fs=4500;
Wp=2*pi*Fp; Ws=2*pi*Fs;
[N,Wn]=buttord(Wp,Ws,0.5,30,'s');
[b,a]=butter(N,Wn,'s');
wa=0:(3*Ws)/511:3*Ws;
h=freqs(b,a,wa);
plot(wa/(2*pi),20*log10(abs(h))); grid;
xlabel(', '); ylabel('');
title(' ');
axis([0 3*Fs -60 5]);

45

6
:
:

.
:

( ).
, , ,
.
IIR (Infinite Impulse Response
) :
(8)

.
.
46

. ,
t t .

T.

: [0] = 1, [t ] = 0, t 0 .
T {} = {h[n]} , k [t ] = [t k ] .
{x[n]}

{x[n]} = x[k ] k .
k

T {x[n]} = x[k ]T { k }, T { } = {h[n k ]} . ,


k
k
{ y[n]} = T {x[n]} , y[n] = x[k ]h[n k ]
k

(9)

{h[n]} ,

, .

MATLAB

disp

length


ones

pi


latc2tf

poly2rc

residue

residuez

tf2latc

zp2sos

6_1

MATALAB

zp2sos

H(z) .
% P6_1
%
num=input(' : ');
den=input(' : ');
[z,p,k]=tf2zp(num,den);
sos=zp2sos(z,p,k)
47


Enter numinator koefficients:[10, 20, 30]
Enter denuminator koefficients:[12, 34, 45]
sos = 0.8333

1.6667

2.5000

1.0000

2.8333

3.7500

6_2
IIR
. - ,
z-1. MATLAB residuez.
z MATLAB residue.
% P6_2
% IIR
num=input(' : ');
den=input(' : ');
[r1,p1,k1]=residuez(num,den);
[r2,p2,k2]=residue(num,den);
disp(' 1')
disp(': '); disp(r1);
disp(': '); disp(p1);
disp(': '); disp(k1);
disp(' 2')
disp(': '); disp(r2);
disp(': '); disp(p2);
disp(': '); disp(k2);

Enter numinator koefficients:[10, 20, 30]
Enter denuminator koefficients:[12, 34, 45]
Parallel Form 1
Rest:
0.0833 + 0.1736i
0.0833 - 0.1736i
Poles:
-1.4167 + 1.3202i
-1.4167 - 1.3202i
Const:
0.6667
Parallel Form 2
Rest:
48

-0.3472 - 0.1359i
-0.3472 + 0.1359i
Poles:
-1.4167 + 1.3202i
-1.4167 - 1.3202i
Const:
0.8333

6_3
Gray-Markel. GrayMarkel H(z) N- ,
AN(z),
, H(z).
% P6_3
% Gray-Markel
% k -
% alpha -
format long
%
num=input(' : ');
den=input(' : ');
N=length(den)-1; % ()
k=ones(1,N);
a1=den/den(1);
alpha=num(N+1:-1:1)/den(1);
for ii=N:-1:1,
alpha(N+2-ii:N+1)=alpha(N+2-ii:N+1)-alpha(N-ii+1)*a1(2:ii+1);
k(ii)=a1(ii+1);
a1(1:ii+1)=(a1(1:ii+1)-k(ii)*a1(ii+1:-1:1))/(1-k(ii)*k(ii));
end
disp(' : '); disp(k)
disp(' : '); disp(alpha)
subplot(1,2,1); title(' ');
bar(k);
subplot(1,2,2); title(' ');
bar(alpha);

:
Enter numinator koefficients:[10, 20, 30]
Enter denuminator koefficients:[12, 34, 45]
Grid Parametrs:
0.59649122807018 3.75000000000000
Mults of direct connection:
2.0

-5.41666666666667 -5.31067251461988

49

50