声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2473|回复: 0

[FFT] 短时傅里叶变换时频谱图画法【求助】

[复制链接]
发表于 2011-2-25 16:56 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 hitdely 于 2011-2-25 17:00 编辑

下面的程序是网上照的 我想通过短时傅里叶变换得到时频谱图 应该怎么办 请各位高手指点 万分感谢
clear all;
close all;
fs=3200;%采样频率
Ts=1/fs;%采样时间间隔
TT=0.4;%终止时间
t=0:Ts:TT;%采样时刻                    
N=fs*TT;%采样点
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 产生信号 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=zeros(size(t));
%  x1=sin(2*pi*50*t);x2=sin(2*pi*100*t)+sin(2*pi*50*t);%采样频率fs=3200;Ts=1/fs;t=0:Ts:0.4;  
%  x=[x1(1:400),x2(401:800),x1(801:end)];
x1=sin(2*pi*50*t);x2=sin(2*pi*200*t);
x=[x1(1:600),x2(601:end)];
% x=sin(2*pi*50*t)+sin(2*pi*100*t)+sin(2*pi*240*t)+sin(2*pi*400*t);
%Generate two sine signal with different frequencies.
% x(50:150)=cos(pi*(t(50:150)-50)/10);   
% x(250:350)=cos(pi*(t(250:350)-250)/20);
% x=wavread('D:\MATLAB7\123\XP_KaiShi.wav');
figure;
subplot(221);
plot(x);
title('信号波形图'); %图名
xlabel('时间'); %x轴
ylabel('振幅'); %y轴
% axis([ 0 800 -0.11 0.1]);
grid;
%%%%%%%%%%%%%%%%%%%%%%%%%%% 短时傅里叶变换 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Nw=20;          %窗函数长 window length
L=Nw/2;         %窗函数每次移动的样点数
Ts=round((N-Nw)/L)+1;     %计算把数据x共分成多少段
nfft=128;        %FFT的长度
TF=zeros(Ts,nfft);  %将存放三维谱图,先清零
for i=1:Ts
    xw=x((i-1)*L+1:i*L+L);   %取一段数据
    temp=fft(xw,nfft);       %FFT变换
    temp=fftshift(temp);     %频谱以0频为中心
    TF(i,:)=temp;            %把谱图存放在TF中
end
subplot(222);
mesh(abs(TF));  %三维绘图
title('STFT');
xlabel('时间');
ylabel('频率');
%%%%%%%%%%%%%%%%%%%%%%%%%% 画等高图 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(223);
contour(abs(TF));
% plot(abs(TF));
title('等高图');
xlabel('时间');
ylabel('频率');
axis equal ;   %纵、横坐标轴采用等长刻度 set the axes aspect ratio
%axis([0 55 0 0.71]);
grid;

untitled.jpg

本帖被以下淘专辑推荐:

回复
分享到:

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-17 11:07 , Processed in 0.053650 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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