DSP-B实验指导书 下载本文

%

if ((n0 < n1) | (n0 > n2) | (n1 > n2))

error('arguments must satisfy n1 <= n0 <= n2') end

n = [n1:n2];

%x = [zeros(1,(n0-n1)), ones(1,(n2-n0+1))]; x = [(n-n0) >= 0];

2)单位冲激函数(the impulse sequence)

function [x,n] = impseq(n0,n1,n2)

% Generates x(n) = delta(n-n0); n1 <= n,n0 <= n2 % ---------------------------------------------- % [x,n] = impseq(n0,n1,n2) %

if ((n0 < n1) | (n0 > n2) | (n1 > n2))

error('arguments must satisfy n1 <= n0 <= n2') end

n = [n1:n2];

%x = [zeros(1,(n0-n1)), 1, zeros(1,(n2-n0))]; x = [(n-n0) == 0];

2. 基本运算函数 1)加法函数

function [y,n] = sigadd(x1,n1,x2,n2) % implements y(n) = x1(n)+x2(n) % ----------------------------- % [y,n] = sigadd(x1,n1,x2,n2)

% y = sum sequence over n, which includes n1 and n2 % x1 = first sequence over n1

% x2 = second sequence over n2 (n2 can be different from n1) %

n = min(min(n1),min(n2)):max(max(n1),max(n2)); % duration of y(n) y1 = zeros(1,length(n)); y2 = y1; % initialization

y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y y = y1+y2; % sequence addition

2)反折函数

- 5 -

以纵坐标轴为中心,左右对折,调用matlab自带函数fliplr。 function [y,n]=sigfold(x,n) % implements y(n) = x(-n) % ----------------------------- % [y,n] = sigfold(x,n)

y=fliplr(x); n=-fliplr(n); 3)乘法函数

function [y,n] = sigmult(x1,n1,x2,n2) % implements y(n) = x1(n)*x2(n) % ----------------------------- % [y,n] = sigmult(x1,n1,x2,n2)

% y = produce sequence over n, which includes n1 and n2 % x1 = first sequence over n1

% x2 = second sequence over n2 (n2 can be different from n1) %

n = min(min(n1),min(n2)):max(max(n1),max(n2)); % duration of y(n) y1 = zeros(1,length(n)); y2 = y1; % initialization

y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y y = y1.*y2; % sequence multiplication 4)移位函数

function [y,n]=sigshift(x,m,n0) % implements y(n) = x(n-n0) % ----------------------------- % [y,n] = sigshift(x,m,n0) n=m+n0; y=x;

五、编程注意事项

1)变量和文件名的命名规则:以英文字母开头,由字母、数字和下划线组成,并且不要与

MATLAB内置函数名称相同。

2)数组运算是点运算(对应位置的数据之间的加减乘除),注意小黑点;

- 6 -

实验三 序列的频域表示与分析

一、实验目的

1. 2.

考察抽样间隔对信号频谱的影响; 掌握用FFT做谱分析的方法。

二、实验内容与要求 (在预习报告中写出对信号进行傅立叶分析的程序,并思考下面的问题) 1. 参考程序Lab3_1.m 是对正弦信号的抽样,先改变抽样间隔(哪个参数?),取若不同的值作观察图形变化,你能得出什么样的结论? 2. 用FFT对模拟信号进行傅里叶分析 以频率fs 对以下信号抽样N点

xa(t) = cos (a t) + cos (b t) + cos (c t)

相应的参数是

a = 2*pi*6500, b = 2*pi *7000, c = 2*pi*9000 fs = 32000,N = 16

对这N点序列作N点DFT,观察其幅频特性,如果

X = fft (x)

w是频率坐标向量,你可以考虑用stem (w, abs(X)), plot (w, abs(X)), plot (w, abs(X), '*')来显示,然后确定用哪种显示方式。注意安排信号的时域、频域的显示。 1)对N=16点的序列作16点DFT(FFT),观察其幅频特性;

2)对N=16点的序列作M=256点DFT(FFT),这意味着在x后补了M-N个0,再观察幅频特性; 3)对N=256点的序列作256点DFT(FFT),观察其幅频特性;

4)改变fs ,令其分别为 24000,19000,18000,17000,16000,你看到了什么,做怎样的解释? 1)在实验报告中回答:离散信号如何通过对连续信号抽样来获得,并按照以上要求写出对xa(t)抽样后的结果(即xn的表达式);

2)在实验报告中回答:如何对信号进行频谱分析,fft函数的用法? 3)在实验报告中回答:对原时域信号补零后,其幅频特性有何变化? 4)在实验报告中回答:高密度谱和高分辨率谱之间有何区别?

5)在实验报告中回答:改变时域信号的采样率fs对信号的幅频特性会产生什么影响?为什么?在实际中选取fs的依据是什么?

三、参考程序

% Program Lab3_1

- 7 -

% Illustration of the Sampling Process in the Time-Domain clf;

t = 0:0.0005:1; f = 13;

xa = cos(2*pi*f*t); subplot(2,1,1) plot(t,xa);grid

xlabel('Time, msec');ylabel('Amplitude'); title('Continuous-time signal x_{a}(t)'); axis([0 1 -1.2 1.2]) subplot(2,1,2);

% in the lab project, should run for 4 different sampling periods T = 1./26;%抽样间隔 n = 0:T:1;

xs = cos(2*pi*f*n); k = 0:length(n)-1; stem(k,xs);grid;

xlabel('Time index n');ylabel('Amplitude'); title('Discrete-time signal x[n]'); axis([0 (length(n)-1) -1.2 1.2])

% Program Lab3_2

% determine the spectrum of discrete-time signal x[n]=cos(2*pi*500t), the sampling frequency denotes by fs

fs=1500; M=256; T=1/fs; n=0:T:(M-1)*T;

xa=cos(2*pi*500*n); % discrete-time signal k=0:(M-1);

Xa1=abs(fft(xa,M)); &magnitude spectrum plot(k*fs/(M-1),Xa1);

- 8 -