声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1130|回复: 0

[共享资源] 用FFT分析信号

[复制链接]
发表于 2007-4-28 21:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
这两天搞毕业设计,编的用Matlab中的fft分析含噪声的信号,其中有直接FFT,时域同步平均后FFT,频域同步平均后FFT。初次使用FFT的可以参考。

%%This procedure is to investigate the FFT of sine signal, sine signal with
%%noise.  The sine signal with noise is treated by direct FFT,
%%FFT after piece-wise averaging in time domain, and FFT after
%%piece-wise averaging  frequency domain
%%
clear all
pack


w=10;
t=0:(2*pi/w/500):(300*2*pi/w);
x=sin(w*t);

n=length(t);

ss=888;
randn('seed',ss);
z=randn(1,n);
z1=z-mean(z);
z2=z1/max(abs(z1));
z2=z2*500;

figure(1)
plot(t,x)  % The sine signal without noise


fre=(1/(2*pi/w/500))*(1:n)/n;

nn=fix(n/2);
y1=fft(x);  % The FFT of sine signal without noise
y1=(abs(y1)).^2/n;
y2=y1(2:(nn+1));
fre1=2*pi*fre(1:nn);

figure(2)
plot(fre1,y2)

x=x+z2;

y1=fft(x);  % The FFT of sine signal with noise
y1=(abs(y1)).^2/n;
y2=y1(2:(nn+1));

figure(3)
plot(fre1,y2)         %The sine signal with noise

%% Averaging in time domain

M=10000;
xx=zeros(1,M);
m1=1;m2=M;

nnnn=fix(300*500/M);

for nnn=1:nnnn
    xxx=x(m1:m2);
    xx=xx+xxx;
    m1=m1+M;
    m2=m2+M;
end

fre=(1/(2*pi/w/500))*(1:M)/M;

nn=fix(M/2);
xx=xx/nnnn;
y1=fft(xx);
y1=(abs(y1)).^2/M;
y2=y1(2:(nn+1));
fre1=2*pi*fre(1:nn);

figure(4)
plot(fre1,y2)



% Next is averaging in frequency domain
% In fact, the averaging in time domain is identical with that in frequency
% domain

MM=10000;
xx=zeros(1,MM);
m1=1;m2=MM;

nnnn=fix(300*500/MM);

for nnn=1:nnnn
    xxx=x(m1:m2);
    xxx=fft(xxx);
    %xxx=sqrt((abs(xxx)).^2);
    xx=xx+xxx;
    m1=m1+MM;
    m2=m2+MM;
end

y1=xx/nnnn;
y1=(abs(y1)).^2/MM;


fre=(1/(2*pi/w/500))*(1:MM)/MM;

nn=fix(MM/2);
y2=y1(2:(nn+1));
fre1=2*pi*fre(1:nn);

figure(5)
plot(fre1,y2)
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-12 22:44 , Processed in 0.051418 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表