设计计算机程序,产生序列并计算序列的DTFT,绘制其幅频特性和相频特性曲线;根据系统的单位脉冲响应和差分方程,计算系统的频率响应,绘制系统频率响应的幅频特性和相频特性曲线;根据系统的单位脉冲响应和差分方程,计算系统的系统函数、零极点分布;改变系统的零极点分布,观察系统频率响应的变化。
图太多啦,就不贴出来了,自己跑吧。
%1.设置差分方程y(n)-0.8y(n-1) = x(n)
a = 0.8;
%初值y(-1) =0
ys = 0;
N = 30;
xn1 = [1,zeros(1,N-1)];
n =[1:N];
%输入序列xn2
xn2 =0.8.^n;
B = 1;A= [1, -0.8];
xi =filtic(B,A,ys);
%2.求解系统的单位脉冲相应和输入序列的单位脉冲相应
yn1 =filter(B,A,xn1);
yn2 =filter(B,A,xn2);
n1 =0:length(yn1)-1;
n2 =0:length(yn2)-1;
subplot(3,2,1);stem(n1,yn1,'.');
title('系统单位脉冲响应');xlabel('n');ylabel('h(n)');
subplot(3,2,2);stem(n2,yn2,'.');
title('输入序列响应(函数库法)');xlabel('n');ylabel('s(n)');
%3.dtft
w = -2*pi:0.01:2*pi;
X = dtft(xn2, n, w);
subplot(3,2,3); plot(n, xn2);title('signal = 0.8^n');
subplot(3,2,4); plot(w, X); title('DTFT');
%4.幅频相频特性
X1 = abs(X)
X2 = angle(X)
subplot(3,2,5); plot(w,X1); title('幅频特性');
subplot(3,2,6); plot(w,X2); title('相频特性');
%%%%%%%%%%%%%%%%%%%%%%%%根据系统
%H(Z)=Z/(Z-0.8)
num = [1];
den = [1,-0.8];
%响应分布
g = freqz(num,den,w);
figure;
g1 = abs(g)
g2 = angle(g)
subplot(3,1,1); plot(w,g1); title('幅频特性');grid on;
subplot(3,1,2); plot(w,g2); title('相频特性');grid on;
%零点极点分布
subplot(3,1,3);zplane(num,den);
%%%%%%%%%%%%%%%%改变零点极点的分布带来的变化
w = -2*pi:0.01:2*pi;
%H(Z)=(Z-1)/(Z-0.8) 零点在单位圆上,谷值为0
num = [1,-1];
den = [1,-0.8];
%响应分布
g = freqz(num,den,w);
figure;
g1 = abs(g)
g2 = angle(g)
subplot(3,1,1); plot(w,g1); title('幅频特性');grid on;
subplot(3,1,2); plot(w,g2); title('相频特性');grid on;
%零点极点分布
subplot(3,1,3);zplane(num,den);
%H(Z)=(Z-0.7)/(Z-0.8) 1.零点越靠近单位圆,谷值越深
num = [1,-0.7];
den = [1,-0.8];
%响应分布
g = freqz(num,den,w);
figure;
g1 = abs(g)
g2 = angle(g)
subplot(3,1,1); plot(w,g1); title('幅频特性');grid on;
subplot(3,1,2); plot(w,g2); title('相频特性');grid on;
%零点极点分布
subplot(3,1,3);zplane(num,den);
%H(Z)=(Z-0.2)/(Z-0.8) 1.零点越靠近单位圆,谷值越深
num = [1,-0.2];
den = [1,-0.8];
%响应分布
g = freqz(num,den,w');
figure;
g1 = abs(g)
g2 = angle(g)
subplot(3,1,1); plot(w,g1); title('幅频特性');grid on;
subplot(3,1,2); plot(w,g2); title('相频特性');grid on;
%零点极点分布
subplot(3,1,3);zplane(num,den);
%H(Z)=Z/(Z-0.3) 极点越靠近单位圆,峰值越尖锐
num = [1];
den = [1,-0.3];
%响应分布
g = freqz(num,den,w);
figure;
g1 = abs(g)
g2 = angle(g)
subplot(3,1,1); plot(w,g1); title('幅频特性');grid on;
subplot(3,1,2); plot(w,g2); title('相频特性');grid on;
%H(Z)=Z/(Z-0.9) 极点越靠近单位圆,峰值越尖锐
num = [1];
den = [1,-0.9];
%响应分布
g = freqz(num,den,w);
figure;
g1 = abs(g)
g2 = angle(g)
subplot(3,1,1); plot(w,g1); title('幅频特性');grid on;
subplot(3,1,2); plot(w,g2); title('相频特性');grid on;
%H(Z)=Z/Z-1 极点在单位圆上
num = [1];
den = [1,-1];
%响应分布
g = freqz(num,den,w);
figure;
g1 = abs(g)
g2 = angle(g)
subplot(3,1,1); plot(w,g1); title('幅频特性');grid on;
subplot(3,1,2); plot(w,g2); title('相频特性');grid on;
DTFT.m
function [ X ] = dtft(x,n,w)
% [X] = dtft(x,n,w)
% X =在w频率计算的DTFT值
% x = n上的有限持续时间序列
% n =样本位置向量
% w =频率位置矢量
temp = w' * n;
temp = - 1i * temp;
e = exp(temp);
X = e * x' ;
End
Ztrans.m
clear all;close all;clc;
syms k
xn3 = 0.8^k;
Fz = ztrans(xn3)