西电电院数字信号处理上机实验记录

一、离散时间信号与系统的时域和频域分析

1-1

clear;clc;
n = (-6:6);
%初始信号表达
x = 0.*(n<-4 & n>4) + (2*n).*(n <= 4 & n>=0) + (2*n + 4).*(n<=-1 & n>=-4);
%x1移位序列表达
n1 = n + 2;
x1 = 2.*x;
%x2加移位序列表达
n2 = n - 3;
n2 = -fliplr(n2);
x2 = 3.*fliplr(x);
%绘图
subplot(1,3,1);stem(n,x,'.');xlabel('n');ylabel('x(n)');grid on;
subplot(1,3,2);stem(n1,x1,'.');xlabel('n');ylabel('x1(n)');grid on;
subplot(1,3,3);stem(n2,x2,'.');xlabel('n');ylabel('x2(n)');grid on;

1-2

clear;clc;
%输入序列与冲激响应
nx = (0:9);
R10 = ((nx-0)>=0)-((nx-10)>=0);
x = sin(0.3*pi*nx)./nx.*R10;
nh = (0:3);
h = ((nh-0)>=0)-((nh-4)>=0);
%卷积计算零状态响应
y = conv(x,h);
ny1 = nx(1) + nh(1);
ny2 = nx(end) + nh(end);
ny = (ny1:ny2);
%绘图
stem(ny,y,'.');xlabel('n');ylabel('y(n)');grid on;

1-3

clear;clc;
%模拟信号
t = (-5:0.01:5);xa = exp(-1.*abs(t));
% 模拟信号频谱
w = (-5:0.01:5);Fw = 2./(1 + w.^2);
% 采样信号
fs1 = 5000;dt1 = 1/fs1;
t1 = -0.01:dt1:0.01;
x1 = exp(-1000.*abs(t1));
fs2 = 5000;dt2 = 1/fs2;
t2 = 0:dt2:0.01;
x2 = exp(-1000.*abs(t1));
%对采样信号做fft
y1 = abs(fft(x1,1e5));y1 = [y1 y1];
y2 = abs(fft(x2,1e5));y2 = [y2 y2];
wn = linspace(-5,5,2e5);
%绘图
subplot(2,2,1);plot(t,xa);title('时域波形');
xlabel('t');ylabel('xa');grid on;
subplot(2,2,2);plot(w,Fw);title('幅频特性');
xlabel('w');ylabel('Fw');grid on;
subplot(2,2,3);stem(wn,y1,'.');title('fs = 5000Hz');
xlabel('w');ylabel('Yw');grid on;
subplot(2,2,4);stem(wn,y2,'.');title('fs = 1000Hz');
xlabel('w');ylabel('Yw');grid on;

1-4

clear;clc;
%z变换的系数
b = [0,1];a = [1,-1,-1];
%零极点
rp = roots(a);rz = roots(b);
subplot(2,2,1);
zplane(b,a);axis([-2,2,-1.5,1.5]);
%冲激函数
subplot(2,2,2);impz(b,a,10);grid on;
%幅度相角部分
[H,w] = freqz(b,a,1024,'whole');
magX = abs(H);angX = angle(H);
subplot(2,2,3);plot(w/pi,magX);
xlabel('$w/\pi$','Interpreter','latex');ylabel('Hx');grid on;
subplot(2,2,4);plot(w/pi,angX);grid on;
xlabel('$w/\pi$','Interpreter','latex');
ylabel('$\theta_x$','Interpreter','latex');grid on;

1-5

clear;clc;
%表示函数
w = (0:0.01:3);
Hw = (1+cos(w)+3*cos(2*w)).*cos(w/2).*exp(-5i*w/2);%频率响应
x1 = sin(pi*n/2);x2 = 5*cos(pi*n);
x = x1 + x2;
%% 求系统函数
[b,a] = invfreqz(Hw,w,3,4);
display(b);display(a);
%% 滤波器的幅度响应和相位响应曲线
magX = abs(Hw);subplot(2,1,1);
plot(w/pi,magX);title('幅度响应');%幅度响应
xlabel('$w/\pi$','Interpreter','latex');
ylabel('$H_{w}$','Interpreter','latex');
angX = angle(Hw);subplot(2,1,2);
plot(w/pi,angX);title('相位响应');%相位响应
xlabel('$w/\pi$','Interpreter','latex');
ylabel('$\theta$','Interpreter','latex');
%% 滤波器对正弦信号的影响
xlabel('n');ylabel('xn');
y = filter(b,a,x);%稳态相应
y1 = filter(b,a,x1);y2 = filter(b,a,x2);
X = fft(x,2022);Y = fft(y,2022);
X1 = fft(x1,2022);Y1 = fft(y1,2022);
X2 = fft(x2,2022);Y2 = fft(y2,2022);
w = linspace(-pi,pi,2022);
%% xn与稳态响应比较
subplot(121);
plot(n,x);xlabel('n');ylabel('xn');
title('原信号');grid on;
subplot(122);
plot(n,y);xlabel('n');ylabel('yn');
title('稳态响应');
%% 正弦信号1幅度与相位响应的影响
subplot(221);
plot(w/pi,fftshift(abs(X1)),'Color','r');
xlabel('$w/\pi$','Interpreter','latex');
ylabel('$H_{X1}$','Interpreter','latex');
grid on;title('原幅度响应')
subplot(222);
plot(w/pi,fftshift(abs(Y1)));
xlabel
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值