matlab实现dft

上传人:第*** 文档编号:34210796 上传时间:2018-02-21 格式:DOCX 页数:12 大小:331.56KB
返回 下载 相关 举报
matlab实现dft_第1页
第1页 / 共12页
matlab实现dft_第2页
第2页 / 共12页
matlab实现dft_第3页
第3页 / 共12页
matlab实现dft_第4页
第4页 / 共12页
matlab实现dft_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《matlab实现dft》由会员分享,可在线阅读,更多相关《matlab实现dft(12页珍藏版)》请在金锄头文库上搜索。

1、DFT 基于 Matlab 的实现一、实验目的1掌握DFT函数的用法。2. 利用DFT进行信号检测及谱分析。3了解信号截取长度对谱分析的影响。二、实验内容1利用DFT计算信号功率谱。实验程序:t=0:0.001:0.6;x=sin(2*pi*50*t)+sin(2*pi*120*t)+randn(1,length(t);Y=dft(x,512);P=Y.*conj(Y)/512;f=1000*(0:255)/512;plot(f,P(1:256)2. 进行信号检测。分析信号频谱所对应频率轴的数字频率和频率之间的关系。模拟信号 ,以 进行取样,求N点)8cos(5)4sin(*2)(tttxnt

2、01.1nDFT的幅值谱。实验程序:subplot(2,2,1)N=45;n=0:N-1;t=0.01*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8*pi*t);y=dft(x,N);plot(q,abs(y);title(DFT N=45)subplot(2,2,2)N=50;n=0:N-1;t=0.01*n; q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8*pi*t);y=dft(x,N);plot(q,abs(y);title(DFT N=50)subplot(2,2,3)N=55;n=0:N-1;t=0.01*n;q=n*2*pi/N;

3、x=2*sin(4*pi*t)+5*cos(8*pi*t);y=dft(x,N);plot(q,abs(y);title(DFT N=55)subplot(2,2,4)N=60;n=0:N-1;t=0.01*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8*pi*t);y=dft(x,N);plot(q,abs(y);title(DFT N=60)3. 对 2,进一步增加截取长度和 DFT 点数,如 N 加大到 256,观察信号频谱的变化,分析产生这一变化的原因。在截取长度不变的条件下改变采样频率,观察信号频谱的变化,分析产生这一变化的原因。N加大到256时的程序:N=

4、256;n=0:N-1;t=0.01*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8*pi*t);y=dft(x,N);plot(q,abs(y);title(DFT N=256)分析原因:在 T=0.01s 的情况下,第一个序列的周期是 100,第二个序列的周期是 50,所以当取样点数小于 100 时,频率分辨率不够,不能够区分出两个信号。当采样点数足够多(256)时,频率分辨率增加,能够区分出两个频率的信号。将采样间隔变为 T=0.1s 时,N 仍为 45 的程序:N=45;n=0:N-1;t=0.1*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*

5、cos(8*pi*t);y=dft(x,N);plot(q,abs(y);title(DFT N=45)分析原因:在 T=0. 1s 的情况下,第一个序列的周期是 10,第二个序列的周期是 5,所以当取样点数为 45 时,能够区分出两个信号。参数同上,N 取 64,并在信号中加入噪声 w(t)。figure(2)subplot(2,1,1)N=64;n=0:N-1;t=0.01*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8*pi*t); y=dft(x,N);plot(q,abs(y);title(DFT N=64)subplot(2,1,2)N=64;n=0:N-

6、1;t=0.01*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8*pi*t)+0.8*randn(1,N); y=dft(x,N);plot(q,abs(y);title(DFT N=64(with noise)由图可以看出这种噪音不影响信号检测。4. 对 3,加大噪声到 2*randn(1,N)和 8*randn(1,N),画出并比较不同噪声下时域波形和频谱。subplot(2,1,1)N=64;n=0:N-1;t=0.01*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8*pi*t)+2*randn(1,N); y=dft(x,N);plo

7、t(q,abs(y);title(DFT N=64(with noise2)subplot(2,1,2)N=64;n=0:N-1;t=0.01*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8*pi*t)+8*randn(1,N); y=dft(x,N);plot(q,abs(y);title(DFT N=64(with noise8)subplot(3,2,1)N=64;n=0:N-1;t=0.01*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8*pi*t)+0.8*randn(1,N); plot(x);title(噪声为0.8*w的信号)

8、y=dft(x,N);subplot(3,2,2)plot(q,abs(y);title(噪声为0.8*w时的频谱)subplot(3,2,3)N=64;n=0:N-1;t=0.01*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8*pi*t)+2*randn(1,N); plot(x);title(噪声为2*w时的信号)y=dft(x,N);subplot(3,2,4)plot(q,abs(y);title(噪声为2*w时的频谱)subplot(3,2,5)N=64;n=0:N-1;t=0.01*n;q=n*2*pi/N;x=2*sin(4*pi*t)+5*cos(8

9、*pi*t)+8*randn(1,N); plot(x);title(噪声为8*w时的信号)y=dft(x,N);subplot(3,2,6)plot(q,abs(y);title(噪声为8*w时的频谱)实验分析:当噪声较小时,不影响信号的检测,但当噪声较大时,就看不出原信号的频率成分了,可以继续加大噪声,可看到其频谱杂乱无章了。5. 用一个N点DFT计算两个长度为N的实序列N点离散傅里叶变换,并将结果和直接使用两个N点DFT得到的结果进行比较。x=1 2 3 4 5 6; y=6 5 4 3 2 1; a,b=dft_2(x,y) a = Columns 1 through 3 21.000

10、0 -3.0000 + 5.1962i -3.0000 + 1.7321i Columns 4 through 6 -3.0000 -3.0000 - 1.7321i -3.0000 - 5.1962i b = Columns 1 through 3 21.0000 3.0000 - 5.1962i 3.0000 - 1.7321i Columns 4 through 6 3.0000 3.0000 + 1.7321i 3.0000 + 5.1962i 函数文件如下:function y1,y2=dft_2(a,b) N=length(a); x=zeros(1,N); x=a+j*b; X=

11、dft(x,N); X0=conj(fliplr(X); X0=X0(N) X0(1:N-1); y1=(X+X0)./2; y2=(X-X0)./2./j; 直接运行计算 :dft(x) ans = Columns 1 through 3 21.0000 -3.0000 + 5.1962i -3.0000 + 1.7321i Columns 4 through 6 -3.0000 -3.0000 - 1.7321i -3.0000 - 5.1962i dft(y) ans = Columns 1 through 3 21.0000 3.0000 - 5.1962i 3.0000 - 1.73

12、21i Columns 4 through 6 3.0000 3.0000 + 1.7321i 3.0000 + 5.1962i 6比较DFT和DFT的运算时间。(计时函数 tic, toc)N分别取256,512,1024,2048,4096, 程序如下: N=256;N=4096; x=randn(1,N); tic y=dft(x,N); toc tic z=dft(x); toc N=256:Elapsed time is 0.172000 seconds. Elapsed time is 0.015000 seconds.N=512:Elapsed time is 0.687000

13、seconds. Elapsed time is 0.000000 seconds. N=1024:Elapsed time is 3.031000 seconds.Elapsed time is 0.047000 seconds. N=2048:Elapsed time is 13.375000 seconds. Elapsed time is 0.063000 seconds. N=4096:Elapsed time is 59.250000 seconds. Elapsed time is 0.125000 seconds.7对给定语音信号进行谱分析,写出采样频率,画出语音信号的波形及频

14、谱,并分析语音信号的频率分布特点。(1)画时域波形并对整个语音序列做DFT x,fs=wavread(C:ai1.wav); subplot(2,1,1) N=length(x); n=0:N-1; plot(n,x); xlabel(n); ylabel(x); title(时域波形);subplot(2,1,2); N=length(x); n=0:N-1; t=0.01*n; q=n*2*pi/N; y=dft(x,N);plot(q,abs(y); xlabel(n);ylabel(ai1); title(DFT); (2)并分别求出k=300,3500所对应的信号频率(Hz) x,f

15、s=wavread(C:ai1.wav)N=length(x);n=0:N-1; t=n*(1/fs);q=n*2*pi/N;n1=300;q1=n1*2*pi/N; f1=q1*fs/(2*pi);n2=3500;q2=n2*2*pi/N;f2=q2*fs/(2*pi);fs =16000(3)从语音中截取一段语音(256点)做DFT,得出频谱,画出时域波形及频谱。分别求出k=5,60时所对应的信号频率(Hz) 程序如下: x,fs=wavread(C:ai1.wav); subplot(2,1,1); N=256;n=0:N-1;x=x(1:256); plot(n,x);xlabel(n); ylabel(x); title(256点时域波形); subplot(2,1,2); N=256;n=0:N-1; t=0.01*n;q=n*2*pi/N; x=x(1:256);y=dft(x,N); plot(q,abs(y); xlabel(n); ylabel(ai1);title(DFT-256); (4)分别求出k=5,60时所对应的信号频率(Hz)的程序。 x,fs=wavread(C:ai1.wav); subplot(2,1,1) N=256;n=0:N-1;x=x(1:256); t=0.01

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号