matlab实验指导解读
- 格式:doc
- 大小:177.73 KB
- 文档页数:19
《数字信号处理》MATLAB实验指导
实验一:离散时间信号和离散时间系统
一、 实验目的:
1、 以MA TLAB 为工具学习离散时间信号的图形表示;
2、 以课本提供的例程,练习、理解典型离散信号及其基本运算;
3、 通过MATLAB 仿真简单的离散时间系统,研究其时域特性;
4、 加深对离散系统的差分方程、冲激响应和卷积分析方法的理解。
二、 实验内容:
1、 典型序列的产生与显示;
2、 序列的简单运算;
3、 复合和复杂信号的产生与显示;
4、 离散时间系统的仿真:线性和非线性系统、时变和非时变系统的仿真;
5、 线性时不变离散时间系统:系统冲激响应、卷积运算、系统的级联、系统的稳定性;
三、实验例程:
1、 参照课本例程产生下列序列,并用plot 、stem 好人subplot 命令绘出其图形: ①单位取样序列()n δ;②单位阶跃序列()n μ;③矩形序列RN(n),④斜变序列()n n μ。 所需输入的数据是产生序列的长度L 和抽样频率F T 。
% Program P1_1
% Generation of a Unit Sample Sequence
clf;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit sample sequence
u = [zeros(1,10) 1 zeros(1,20)];
% Plot the unit sample sequence
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 20 0 1.2]);
2、 编写MATLAB 实指数序列程序,
% Program P1_3
% Generation of a real exponential sequence
clf;
n = 0:35; a = 1.2; K = 0.2;
x = K*a.^n;
stem(n,x);
xlabel('Time index n');ylabel('Amplitude');
3、编写产生swept frequency sinusoidal 序列的程序。
% Program P1_7
% Generation of a swept frequency sinusoidal sequence
n = 0:100;
a = pi/2/100;
b = 0;
arg = a*n.*n + b*n;
x = cos(arg);
clf;
stem(n, x);
axis([0,100,-1.5,1.5]);
title('Swept-Frequency Sinusoidal Signal');
xlabel('Time index n');
ylabel('Amplitude');
grid; axis;
>>
4、产生正弦振幅调制序列
% Generation of amplitude modulated sequence
clf;
n = 0:100;
m = 0.4;fH = 0.1; fL = 0.01;
xH = sin(2*pi*fH*n);
xL = sin(2*pi*fL*n);
y = (1+m*xL).*xH;
stem(n,y);grid;
xlabel('Time index n');ylabel('Amplitude');
5、用滑动平均滤波器平滑带噪信号,讨论滤波器长度对平滑效果、输出平滑后信号与
输入带噪信号之间延时的影响。
% Program P1_5
% Signal Smoothing by Averaging
clf;
R = 51;
d = 0.8*(rand(R,1) - 0.5); % Generat
e random noise
m = 0:R-1;
s = 2*m.*(0.9.^m); % Generate uncorrupted signal
x = s + d'; % Generate noise corrupted signal
subplot(2,1,1);
plot(m,d','r-',m,s,'g--',m,x,'b-.');
xlabel('Time index n');ylabel('Amplitude');
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('Time index n');ylabel('Amplitude');
6、编写输入序列、计算输出序列、差分输出并画出输出序列。
% Program P2_4
% Generate the input sequences
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);
xd = [zeros(1,D) x];
num = [2.2403 2.4908 2.2403];
den = [1 -0.4 0.75];
ic = [0 0]; % Set initial conditions
% Compute the output y[n]
y = filter(num,den,x,ic);
% Compute the output yd[n]
yd = filter(num,den,xd,ic);
% Compute the difference output d[n]
d = y - yd(1+D:41+D);
% Plot the outputs
subplot(3,1,1)
stem(n,y);
ylabel('Amplitude');
title('Output y[n]'); grid;
subplot(3,1,2)
stem(n,yd(1:41));
ylabel('Amplitude');
title(['Output due to Delayed Input x[n ?', num2str(D),']']); grid; subplot(3,1,3)
stem(n,d);
xlabel('Time index n'); ylabel('Amplitude');
title('Difference Signal'); grid;
7、编写输入序列和系统单位脉冲响应的卷积程序并画出图形。
% Program P2_7
clf;