1.1
b=[1 6 4];
a=[1 7 10];
w=0:0.1:2*pi*3;
h=freqz(b,a,w);
n=abs(h);
k=angle(h);
subplot(2,1,1);
plot(n);
title('magnitude')
subplot(2,1,2);
plot(k);
title('angle')
1.2
b=ones(1,64);
a=[1];
w=0:0.01:pi;
freqz(b,a,w)
1.3
b=[zeros(1,12) ones(1,64)];
a=[1];
w=0:0.01:pi;
freqz(b,a,w)
2.1
clf;
X=[0 1 2 3 4 5 6 7 8];
N=length(X);
n=0:N-1;
Y=yzyw(X,5);
Xk=fft(X);
Yk=fft(Y);
subplot(2,2,1);
stem(n,abs(Xk));
grid
title('原序列DFT的幅度')
subplot(2,2,2);
stem(n,abs(Yk));
grid
title('圆周移位后序列DFT的幅度');
subplot(2,2,3);
stem(n,angle(Xk));
grid
title('原序列DFT的相位')
subplot(2,2,4);
stem(n,angle(Yk));
grid
title('圆周移位后序列DFT的相位');
2.2
function[xec,xoc]=gedc(x);
N=length(x);
n=0:N-1;
xec=(x+x(mod(-n,N)+1))/2;
xoc=(x-x(mod(-n,N)+1))/2;
N=16;
n=0:15;
x1=cos(pi/4*n);
x2=sin(pi/8*n);
x3=x1+j*x2;
x1k=fft(x1);
x2k=fft(j*x2);
x3k=fft(x3);
[y3kep,y3keo]=gedc(x3k);
subplot(3,2,1)
stem(n,x1k);grid
title('x1的DFT序列');
subplot(3,2,2)
stem(n,x2k);grid
title('x2的DFT序列');
subplot(3,2,3)
stem(n,y3kep);grid
title('x3的DFT圆周共轭对称分量');
subplot(3,2,4)
stem(n,y3keo);grid
title('x3的DFT圆周反共轭对称分量');
subplot(3,2,5)
stem(n,x1k-y3kep);grid
title('x1k-y3kep');
subplot(3,2,6)
stem(n,x2k-y3keo);
title('x2k-y3keo');
2.3
N=16;
n=0:15;
x1=cos(pi/4*n);
x2=sin(pi/8*n);
x3=x1+x2;
x1k=fft(x1);
x2k=fft(-j*x2);
x3k=fft(x3);
subplot(3,2,1)
stem(n,x1k);grid
title('x1的DFT序列');
subplot(3,2,2)
stem(n,x2k);grid
title('x2的DFT序列');
subplot(3,2,3)
stem(n,real(x3k));grid
title('x3的DFT实部');
subplot(3,2,4)
stem(n,imag(x3k));grid
title('x3的DFT虚部');
subplot(3,2,5)
stem(n,x1k-real(x3k));grid
title('x1k-real(x3k)');
subplot(3,2,6)
stem(n,x2k-imag(x3k));
title('x2k-imag(x3k)');
3.1
b=[1 -0.25];
a=[1 -1.86 0.8643 1.5];
[r,p,h]=residuez(b,a);
r =
0.4375 - 0.3228i
0.4375 + 0.3228i
0.1251
>> p
p =
1.2412 + 0.9322i
1.2412 - 0.9322i
-0.6225
>> h
h =
[]
3.2
b=[1 -0.25];
a=[1 -1.86 0.8643 1.5];
[g,t]=impz(b,a);
stem(t,g);
4.1
L=31
n=0:14;
x=0.5.^n;
h=ones(1,15);
x1=[x,zeros(1,L-length(x))];
h1=[h,zeros(1,L-length(h))];
%fft
tic
x1k=fft(x1);
h1k=fft(h1);
y1k=x1k.*h1k;
y=ifft(y1k);
subplot(3,1,1);
stem(y);
axis([0 30 0 2]);
toc
%conv
tic
z=conv(x,h);
subplot(3,1,2);
stem(z);
toc
subplot(3,1,3);
z=[z 0 0]
stem(y-z);
TIME:
L =
31
Elapsed time is 0.008692 seconds.
Elapsed time is 0.007559 seconds.
>>
4.2
L=128
L =
128
Elapsed time is 0.024602 seconds.
Elapsed time is 0.007636 seconds.
clc;
clear;
L=128
n=0:14;
x=0.5.^n;
h=ones(1,15);
x1=[x,zeros(1,L-length(x))];
h1=[h,zeros(1,L-length(h))];
%fft
tic
x1k=fft(x1);
h1k=fft(h1);
y1k=x1k.*h1k;
y=ifft(y1k);
subplot(3,1,1);
stem(y);
axis([0 30 0 2]);
toc
%conv
tic
z=conv(x,h);
subplot(3,1,2);
stem(z);
toc
subplot(3,1,3);
z=[z zeros(1,99)]
stem(y-z);
本文来源:https://www.2haoxitong.net/k/doc/48d2d326c281e53a5802ffba.html
文档为doc格式