文档视界 最新最全的文档下载
当前位置:文档视界 › 数字信号处理实验报告MATLAB

数字信号处理实验报告MATLAB

数字信号处理实验报告MATLAB
数字信号处理实验报告MATLAB

数字信号处理实验报告

姓名:

班级:09电信一班学号:

2)]

得下图二,

图二

图一

3.将如下文件另存为:sigadd.m文件

function [y,n] = sigadd(x1,n1,x2,n2)

% 实现y(n) = x1(n)+x2(n)

% -----------------------------

% [y,n] = sigadd(x1,n1,x2,n2)

% y = 在包含n1 和n2 的n点上求序列和,

% x1 = 在n1上的第一序列

% x2 = 在n2上的第二序列(n2可与n1不等)

n = min(min(n1),min(n2)):max(max(n1),max(n2)); % y(n)的长度

y1 = zeros(1,length(n)); y2 = y1; % 初始化

y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % 具有y的长度的x1

y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % 具有y的长度的x2

y = y1+y2;

在命令窗口输入:x1=[1,0.5,0.3,0.4];n1=-1:2;x2=[0.2,0.3,0.4,0.5,0.8,1];n2=-2:3; [y,n] = sigadd(x1,n1,x2,n2)

得:y =

n=-1:10;

x=sin(0.4*pi*n);

y=fliplr(x);

n1=-fliplr(n);

subplot(2,1,1),stem(n,x) subplot(2,1,2),stem(n1,y

在命令窗口键入:

n=-1:10; x=sin(0.4*pi*n);

n (samples)

实验结果:1.(1)在命令窗口输入:

tic; [am,pha]=dft1(x)

N=length(x);

w=exp(-j*2*pi/N);

for k=1:N

sum=0;

for n=1:N

sum=sum+x(n)*w^((k-1)*(n-1));

end

am(k)=abs(sum);

pha(k)=angle(sum);

end

;toc

得到如下结果:

am =

Columns 1 through 11

120.0000 41.0066 20.9050 14.3996 11.3137 9.6215 8.6591 8.1567 8.0000 8.1567 8.6591

Columns 12 through 16

9.6215 11.3137 14.3996 20.9050 41.0066

pha =

Columns 1 through 11

0 1.7671 1.9635 2.1598 2.3562 2.5525 2.7489 2.9452 3.1416 -2.9452 -2.7489

Columns 12 through 16

-2.5525 -2.3562 -2.1598 -1.9635 -1.7671

Elapsed time is 0.047000 seconds.

(2)在命令窗口输入:

tic;[am,pha]=dft2(x)

N=length(x);

n=[0:N-1];

k=[0:N-1];

w=exp(-j*2*pi/N);

nk=n’*k;

wnk=w.^(nk); Xk=x*wnk; am= abs(Xk); pha=angle(Xk); toc

得到下图:figure(1)

00.10.20.30.40.50.60.70.80.91

signal x(n), 0 <= n <= 99(2)在命令窗口键入:

n3=[0:1:99];y3=[x(1:1:10) zeros(1,90)]; %添90个零。得到100个数据

subplot(2,1,1);stem(n3,y3);title('signal x(n), 0 <= n <= 9 + 90 zeros');xlabel('n') axis([0,100,-2.5,2.5])

Y3=fft(y3);magY3=abs(Y3(1:1:51)); k3=0:1:50;w3=2*pi/100*k3;

subplot(2,1,2);stem(w3/pi,magY3);title('100点DFT');xlabel('w/pi') axis([0,1,0,10])

得到下图figure(2) (3)在命令窗口键入: n=[0:1:99];

x=cos(0.48*pi*n)+cos(0.52*pi*n);

subplot(2,1,1);stem(n,x);title('signal x(n), 0 <= n <= 99');xlabel('n') axis([0,100,-2.5,2.5])

X=fft(x);magX=abs(X(1:1:51)); k=0:1:50;w=2*pi/100*k;

subplot(2,1,2);stem(w/pi,magX);title('100点DFT );xlabel('w/pi') axis([0,1,0,60]) 得到下图figure(3)

wp=200/1000*2*pi;

n=1:65;

hd=sin(wp*(n-32))./(pi*(n-32)); hd(32)=wp/pi;

24

-200-150

-100-500

50矩形窗

024-150

-100

-50

巴特里特窗

024

-300

-200-100

100汉宁窗

050

100

0.5

11.5

2

50

100

00.2

0.40.60.8

10

50

100

00.20.40.60.8

1w1=boxcar(65); subplot(2,3,1) h1=hd.*rot90(w1); [mag1,r1]=freqz(h1); plot(r1,20*log(abs(mag1))); title('矩形窗') w2=triang(65); subplot(2,3,2)

h2=hd.*rot90(w2); [mag2,r2]=freqz(h2);

plot(r2,20*log(abs(mag2)));

title('巴特里特窗')

w3=hanning(65); subplot(2,3,3)

h3=hd.*rot90(w3);

[mag3,r3]=freqz(h3); plot(r3,20*log(abs(mag3))); title('汉宁窗')

subplot(2,3,4); plot(n,w1); subplot(2,3,5);

plot(n,w2);

subplot(2,3,6);

plot(n,w3);

得到右图结果:

结果分析:结果如上

总结:matlab 可以实现利用窗函数设计滤波器。

相关文档