运用快速傅里叶变换(FFT)进行信号时频转换
  *对输入(待测)信号的处理过程
*matlab实现程序如下:
Fs = 5000;                  % 采样频率>=2*输入信号最高频率
T = 1/Fs;                    % 采样周期
N = 1000;                    % 采样点数
t=(0:N-1)*T;                % 时间轴向量
%产生原始信号
x1=2*sin(2*pi*1000*t);
x2=0.5*sin(2*pi*2000*t);
x3=sin(2*pi*50*t);
x4=0.5*sin(2*pi*200*t);
%4个原始信号进行叠加,合成输入信号
y0=x1+x2+x3+x4;
wh=(rectwin(N))';    %矩形窗向量
y=wh.*y0;                %时域加窗
%绘制干扰后的信号频谱图
subplot(2,1,1);
plot(Fs*t(1:400),y0(1:400));      %画出输入信号时域图
title('Signal');
xlabel('time(milliseconds)');
%单纯在原始信号上区分噪音信号和正常信号基本上不可行,要想从受干扰的信号中区分
%正常信号和噪音运行快速傅里叶变换,其运算点数应根据采样点数来确定。一般有下面
%关系成立:2^[log(N)/log(2)](取整)
NFFT = 2^nextpow2(N); % Next power of 2 from length of y
Y = fft(y,NFFT)/N;          %幅度调整(与输入信号幅度对应11
f = Fs/2*linspace(0,1,NFFT/2+1);
% 画出输入信号幅度频谱图
subplot(2,1,2);
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
*运行结果:
*hamming窗截取:
Fs = 5000;                  % 采样频率>=2*输入信号最高频率
T = 1/Fs;                    % 采样周期
N = 1000;                    % 采样点数
t=(0:N-1)*T;                % 时间轴向量
%产生原始信号
x1=2*sin(2*pi*1000*t);
x2=0.5*sin(2*pi*2000*t);
x3=sin(2*pi*50*t);
x4=0.5*sin(2*pi*200*t);
%4个原始信号进行叠加,合成输入信号
y0=x1+x2+x3+x4;
wh=(hamming(N))';    %hamming窗向量
y=wh.*y0;                %时域加窗
%绘制干扰后的信号频谱图
subplot(2,1,1);
plot(Fs*t(1:400),y0(1:400));      %画出输入信号时域图
title('Signal');
xlabel('time(milliseconds)');
%单纯在原始信号上区分噪音信号和正常信号基本上不可行,要想从受干扰的信号中区分
%正常信号和噪音运行快速傅里叶变换,其运算点数应根据采样点数来确定。一般有下面
%关系成立:2^[log(N)/log(2)](取整)
NFFT = 2^nextpow2(N); % Next power of 2 from length of y
Y = fft(y,NFFT)/N;          %幅度调整(与输入信号幅度对应11
f = Fs/2*linspace(0,1,NFFT/2+1);
% 画出输入信号幅度频谱图
subplot(2,1,2);
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
*输入伴有噪声:
Fs = 5000;                  % 采样频率>=2*输入信号最高频率
T = 1/Fs;                    % 采样周期
短时傅里叶变换matlab程序
N = 1000;                    % 采样点数
t=(0:N-1)*T;                % 时间轴向量
%产生原始信号
x1=2*sin(2*pi*1000*t);
x2=0.5*sin(2*pi*2000*t);
x3=sin(2*pi*50*t);
x4=0.5*sin(2*pi*200*t);
%4个原始信号进行叠加,并加入随机噪声,合成输入信号
y0=x1+x2+x3+x4+2*randn(size(t));
wh=(rectwin(N))';    %矩形窗向量
y=wh.*y0;                %时域加窗
%绘制干扰后的信号频谱图
subplot(2,1,1);
plot(Fs*t(1:400),y0(1:400));      %画出输入信号时域图
title('Signal');
xlabel('time(milliseconds)');
%单纯在原始信号上区分噪音信号和正常信号基本上不可行,要想从受干扰的信号中区分
%正常信号和噪音运行快速傅里叶变换,其运算点数应根据采样点数来确定。一般有下面
%关系成立:2^[log(N)/log(2)](取整)
NFFT = 2^nextpow2(N); % Next power of 2 from length of y
Y = fft(y,NFFT)/N;          %幅度调整(与输入信号幅度对应11
f = Fs/2*linspace(0,1,NFFT/2+1);
% 画出输入信号幅度频谱图
subplot(2,1,2);
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')