实验一
- 格式:doc
- 大小:353.50 KB
- 文档页数:9
实 验 报 告
课程名称 数字信号处理
实验项目 实验1 离散傅里叶变换的性质及应用
系 别 信息与通信工程
班级/学号
姓 名 _____
实验日期 ____ ____
成 绩
____________________ _ __
指导教师
一、实验目的
1.了解DFT的性质及其应用
2.熟悉MATLAB编程特点
二、实验仪器及材料
计算机,MATLAB软件
三、实验内容及要求
1.用三种不同的DFT程序计算8()()xnRn的256点离散傅里叶变换()Xk,并比较三种程序计算机运行时间。
(1)编制用for loop语句的M函数文件dft1.m,用循环变量逐点计算()Xk;
(2)编写用MATLAB矩阵运算的M函数文件dft2.m,完成下列矩阵运算:
00000121012(1)(1)(1) (0)(0) (1)(1)
(1)(1) NNNNNNNNNNNNNNNNNXxWWWWXxWWWWxNXNWWWW
(3)调用fft库函数,直接计算()Xk;
(4)分别调用上述三种不同方式编写的DFT程序计算序列()xn的离散傅里叶变换()Xk,并画出相应的幅频和相频特性,再比较各个程序的计算机运行时间。
2.利用DFT实现两序列的卷积运算,并研究DFT点数与混叠的关系。
(1)已知两序列:
3;030;)5/3()(nnnhn ,用MATLAB生成随机输入信号x(n),n的取值为0~2;
(2)用直接法(即用线性卷积的定义计算,见下式)计算线性卷积y(n)=x(n)*h(n)的结果,并以图形方式表示结果;
20),()()(10MNnmnhmxnyNm
其中:序列)1Nn0(),n(x和序列)1Mn0(),n(h
(3)用MATLAB编制利用DFT计算线性卷积y(n)=x(n)*h(n)的程序;分别令圆周卷积的点数为L=5,6,8,10,以图形方式表示结果。
(4)对比直接法和圆周卷积法所得的结果。
四、实验代码与截图
1.DSP1_1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%exp 1 part 1
% Compute DFT using 3 methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
clc;
close all;
N=256;
xn=ones(1,8);
%%
%compute DFT, just using the equation
tic;
[Am1,ph1]=dft1(xn,N);
fprintf('Time dft1:\n');
toc;
%%
% Using the Wn matrix to compute the DFT.
tic;
[Am2,ph2]=dft2(xn,N);
fprintf('Time dft2:\n');
toc;
%%
% Using the built-in fft to compute the DFT.
tic;
[Am3,ph3]=dft3(xn,N);
fprintf('Time dft3:\n');
toc;
%%
k=1:length(Am1);
subplot(3,2,1),plot(k,Am1,'.');
line([k(1),k(end)],[0,0]);ylabel('Am1');
title('黄迪制作');
subplot(3,2,2),plot(k,ph1,'.');
line([k(1),k(end)],[0,0]);ylabel('ph1');
subplot(3,2,3),plot(k,Am2,'.');
line([k(1),k(end)],[0,0]);ylabel('Am2');
subplot(3,2,4),plot(k,ph2,'.');
line([k(1),k(end)],[0,0]);ylabel('ph2');
subplot(3,2,5),plot(k,Am3,'.');
line([k(1),k(end)],[0,0]);ylabel('Am3');
subplot(3,2,6),plot(k,ph3,'.'); line([k(1),k(end)],[0,0]);ylabel('ph3');
%-- 2013-5-12 16:04 --%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-- 2013-11-4 16:04 --%
2.DFT1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%dft1.m
%compute DFT, just using the equation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[Am,pha] = dft1(x,N)
%Paramrters:
% x-- The oringinal sequence
% N-- The numeber of results of DFT.
w = exp(-j*2*pi/N);
for k=1:N
sum = 0;
for n = 1:N
if n<=length(x)
sum = sum+x(n)*w^((k-1)*(n-1));
end
end
Am(k) = abs(sum);
pha(k) = angle(sum);
end
3.DFT2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%dft2.m
% Using the Wn matrix to compute the DFT.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[Am,pha] = dft2(x,N)
%Paramrters:
% x-- The oringinal sequence
% N-- The numeber of results of DFT.
nx=length(x);
x=[x,zeros(1,N-nx)];
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);
4.DFT3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%exp 1 part 1
% Using the built-in fft to compute the DFT.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[Am,pha] = dft3(x,N)
%Paramrters:
% x-- The oringinal sequence
% N-- The numeber of results of DFT.
Xk = fft(x,N);
Am = abs(Xk); pha = angle(Xk);
5.DSP1_2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%exp 1 part 2
%Convolute two sequences using 2 methods.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
clc;
n=0:3;
xn=rand(1,3);
hn=(3/5).^n;
%%
%Directly compute the linear convolution of two sequences.
yn1=mConv(xn,hn)
ny1=1:length(yn1);
subplot(5,1,1),stem(ny1,yn1,'.');
line([ny1(1),ny1(end)],[0,0]);ylabel('linear convolution');
%%Compute the convolution of two sequences
% by first transforming to frequency field, and multiplying them,
% finally transforming inversely to time field.