资源描述
数字信号处理实验
实验三、信号检测与分析
学院:信息工程学院
班级:电子101班
姓名:***
学号:******
一、实验目的
1.掌握FFT函数的用法。
2. 利用FFT进行信号检测及谱分析。
3.了解信号截取长度对谱分析的影响。
二、实验内容
1.利用FFT计算信号功率谱。
实验程序:
t=0:0.001:0.6;
x=sin(2*pi*50*t)+sin(2*pi*120*t)+randn(1,length(t));
Y=fft(x,512);
P=Y.*conj(Y)/512;
f=1000*(0:255)/512;
plot(f,P(1:256))
2. 进行信号检测。分析信号频谱所对应频率轴的数字频率和频率之间的关系。模拟信号,以 进行取样,求N点DFT的幅值谱。
实验程序:
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=fft(x,N);
plot(q,abs(y));title('FFT 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=fft(x,N);
plot(q,abs(y));title('FFT N=50')
subplot(2,2,3)
N=55;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=fft(x,N);
plot(q,abs(y));title('FFT 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=fft(x,N);
plot(q,abs(y));title('FFT N=60')
3. 对2,进一步增加截取长度和FFT点数,如N加大到256,观察信号频谱的变化,分析产生这一变化的原因。在截取长度不变的条件下改变采样频率,观察信号频谱的变化,分析产生这一变化的原因。
N加大到256时的程序:
N=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=fft(x,N);
plot(q,abs(y));title('FFT 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*cos(8*pi*t);
y=fft(x,N);
plot(q,abs(y));title('FFT 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=fft(x,N);
plot(q,abs(y));title('FFT N=64')
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)+0.8*randn(1,N); y=fft(x,N);
plot(q,abs(y));title('FFT 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=fft(x,N);
plot(q,abs(y));title('FFT 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=fft(x,N);
plot(q,abs(y));title('FFT 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的信号')
y=fft(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=fft(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*pi*t)+8*randn(1,N);
plot(x);title('噪声为8*w时的信号')
y=fft(x,N);
subplot(3,2,6)
plot(q,abs(y));title('噪声为8*w时的频谱')
实验分析:当噪声较小时,不影响信号的检测,但当噪声较大时,就看不出原信号的频率成分了,可以继续加大噪声,可看到其频谱杂乱无章了。
5. 用一个N点FFT计算两个长度为N的实序列N点离散傅里叶变换,并将结果和直接使用两个N点FFT得到的结果进行比较。
x=[1 2 3 4 5 6];
y=[6 5 4 3 2 1];
[a,b]=fft_2(x,y)
a =
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
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]=fft_2(a,b)
N=length(a);
x=zeros(1,N);
x=a+j*b;
X=fft(x,N);
X0=conj(fliplr(X));
X0=[X0(N) X0(1:N-1)];
y1=(X+X0)./2;
y2=(X-X0)./2./j;
直接运行计算 :
fft(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
fft(y)
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
6.比较DFT和FFT的运算时间。(计时函数 tic, toc)
N分别取256,512,1024,2048,4096,…
程序如下:
N=256;
N=4096;
x=randn(1,N);
tic
y=dft(x,N);
toc
tic
z=fft(x);
toc
N=256:Elapsed time is 0.172000 seconds.
Elapsed time is 0.015000 seconds.
N=512:Elapsed time is 0.687000 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.对给定语音信号进行谱分析,写出采样频率,画出语音信号的波形及频谱,并分析语音信号的频率分布特点。
(1)画时域波形并对整个语音序列做FFT
[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=fft(x,N);
plot(q,abs(y));
xlabel('n');
ylabel('ai1');
title('FFT');
(2)并分别求出k=300,3500所对应的信号频率(Hz)
[x,fs]=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点)做FFT,得出频谱,画出时域波形及频谱。分别求出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=fft(x,N);
plot(q,abs(y));
xlabel('n');
ylabel('ai1');
title('FFT-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*n;
q=n*2*pi/N;
x=x(1:256);
y=fft(x,N);
n1=5;
q1=n1*2*pi/N;
f1=q1*fs/(2*pi);
n2=60;
q2=n2*2*pi/N;
f2=q2*fs/(2*pi);
展开阅读全文