《数字信号处理》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 Sequenceclf;% Generate a vector from -10 to 20n = -10:20;% Generate the unit sample sequenceu = [zeros(1,10) 1 zeros(1,20)];% Plot the unit sample sequencestem(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 sequenceclf;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 sequencen = 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 sequenceclf;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 Averagingclf;R = 51;d = 0.8*(rand(R,1) - 0.5); % Generate random noisem = 0:R-1;s = 2*m.*(0.9.^m); % Generate uncorrupted signalx = s + d'; % Generate noise corrupted signalsubplot(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 sequencesclf;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 outputssubplot(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_7clf;h = [3 2 1 -2 1 0 -4 0 3]; % impulse response x = [1 -2 3 -4 3 2 1]; % input sequencey = conv(h,x);n = 0:14;subplot(2,1,1);stem(n,y);xlabel('Time index n'); ylabel('Amplitude'); title('Output Obtained by Convolution'); grid; x1 = [x zeros(1,8)];y1 = filter(h,1,x1);subplot(2,1,2);stem(n,y1);xlabel('Time index n'); ylabel('Amplitude'); title('Output Generated by Filtering'); grid;8、编写输入信号经滤波形成的系统输出信号。
% Program P2_9% Generate the input sequenceclf;n = 0:299;x1 = cos(2*pi*10*n/256);x2 = cos(2*pi*100*n/256);x = x1+x2;% Compute the output sequencesnum1 = [0.5 0.27 0.77];y1 = filter(num1,1,x); % Output of System #1 den2 = [1 -0.53 0.46];num2 = [0.45 0.5 0.45];y2 = filter(num2,den2,x); % Output of System #2 % Plot the output sequencessubplot(2,1,1);plot(n,y1);axis([0 300 -2 2]);ylabel('Amplitude');title('Output of System #1'); grid;subplot(2,1,2);plot(n,y2);axis([0 300 -2 2]);xlabel('Time index n'); ylabel('Amplitude'); title('Output of System #2'); grid;9、四、本实验用到的matlab命令Stem plot sin abs cos conv clf subplot filter impz实验二:时域连续时间信号和频域抽样理论的验证与观察一、实验目的:1、理解并掌握信号时域采样和频率抽样理论涉及的过程和效果;2、通过编程加深理解奈奎斯特采样定理,理解不满足采样条件的对时域和频域采样造成的混叠现象。
二、实验内容:1、时域的采样过程、采样定理和混叠效果;2、频域中的采样效果;3、学习buttworth模拟低通滤波器的设计命令;三、实验例程1、连续时间信号的理想抽样及其混叠效果clf;T = 0.4;f = 25;n = (0:T:1)';xs = cos(2*pi*f*n);t = linspace(-0.5,1.5,500)';ya = sinc((1/T)*t(:,ones(size(n))) - (1/T)*n(:,ones(size(t)))')*xs;plot(n,xs,'o',t,ya);grid;xlabel('Time, msec');ylabel('Amplitude');title('Reconstructed continuous-time signal y_{a}(t)');axis([0 1 -1.2 1.2])2、.频率抽样及其混叠效果clf;t = 0:0.002:50;xa = 2*t.*exp(-t);subplot(4,2,1)plot(t,xa);gridxlabel('Time, msec');ylabel('Amplitude');title('Continuous-time signal x_{a}(t)');subplot(4,2,2)wa = 0:10/511:10;ha = freqs(2,[1 2 1],wa);plot(wa/(2*pi),abs(ha));grid;xlabel('Frequency, kHz');ylabel('Amplitude');title('|X_{a}(j\Omega)|');axis([0 5/pi 0 2]);subplot(4,2,3)T = 1;n = 0:T:10;xs = 2*n.*exp(-n);k = 0:length(n)-1;stem(k,xs);grid;xlabel('Time index n');ylabel('Amplitude');title('Discrete-time signal x[n]');subplot(4,2,4)wd = 0:pi/255:pi;hd = freqz(xs,1,wd);plot(wd/(T*pi), T*abs(hd));grid;xlabel('Frequency, kHz');ylabel('Amplitude');title('|X(e^{j\omega})|');axis([0 1/T 0 2])3、buttworth模拟低通滤波器的设计命令并画出该滤波器图形。