实验二离散时间系统的时域分析
实验室名称:实验时间:
姓名:学号:专业:指导教师:
四、实验原理
1.离散时间系统中信号运算方法和基本性质;
2.离散时间系统的MATLAB表示和基本运算;
3. MATLAB处理离散时间系统的方法。
五、实验步骤
1.根据实验题目要求进行分析;
2. 运用所学知识用MATLAB编程实现题目要求;
3. 对结果进行分析总结。
六、实验记录(数据、图表、波形、程序等)
Q2.1 程序代码:
%产生输入信号
n = 0:100;
s1 = cos(2*pi*0.05*n); %一个低频正弦
s2 = cos(2*pi*0.47*n); %一个高频正弦
x = s1+s2;
%滑动平均滤波器的实现
M = input('Desired length of the filter = ');
num = ones(1,M);
y = filter(num,1,x)/M;
clf;
%显示输入和输出信号
subplot(2,2,1);
plot(n, s1);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal #1');
subplot(2,2,2);
plot(n, s2);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal #2');
subplot(2,2,3);
plot(n, x);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Input Signal');
subplot(2,2,4);
plot(n, y);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Signal'); axis;
显示结果:
Q2.2 代码(将输出信号的代码做出修改,其余代码与Q2.1相同):n=0:100;
s1=cos(2*pi*0.05*n);
s2=cos(2*pi*0.47*n);
x=s1+s2;
M=input(' Desired length of the filter = ');
num=(-1).^[0:M-1];
y=filter(num,1,x)/M;
clf;
%显示输入和输出信号
subplot(2,2,1);
plot(n, s1);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal #1');
subplot(2,2,2);
plot(n, s2);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal #2');
subplot(2,2,3);
plot(n, x);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Input Signal');
subplot(2,2,4);
plot(n, y);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Signal');
axis;
显示结果:
Q2.4 程序代码:
%构造长度为101、最低频率为0、最高频率为0.5的扫频正弦信号n = 0:100;
a = pi/2/100;
b = 0;
arg = a*n.*n + b*n;
x = cos(arg);
M = input('Desired length of the filter = ');
num = ones(1,M);
y = filter(num,1,x)/M;
clf;
subplot(2,1,1);
plot(n,x);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('扫频正弦信号');
subplot(2,1,2);
plot(n, y);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude'); title('滤波后的输出信号');
显示结果:
Q2.7 程序代码:
% 生成输入序列
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('振幅');
序列u[n]显示结果:
Q2.23 程序代码:
%级联实现
clf;
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和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;
显示结果:
Q2.23 程序代码:
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);。