matlab中的tfrstft函数在哪,具体的代码是什么
时间: 2024-05-28 13:08:35 浏览: 218
tfrstft函数是信号处理工具箱中的一个函数,用于计算短时傅里叶变换(STFT)。
具体代码如下:
function [TFR,T,F]=tfrstft(x,t,N,h,trace);
%TFRSTFT Short time Fourier transform.
% [TFR,T,F]=TFRSTFT(X,T,N,H,TRACE) computes the
% short-time Fourier transform of a one dimensional
% signal X.
%
% X : Signal.
% T : Time instant(s) (default : 1:length(X)).
% N : Number of frequency bins (default : length(X)).
% H : Window. (default : Hamming(N/4)).
% TRACE : Traces the computation. (default : 'off').
%
% TFR : Time-frequency representation.
% T : Vector of time instants.
% F : Vector of frequencies.
%
% Example :
% sig=fmlin(128,.1,.4);
% t=1:length(sig);
% [tfr,T,F]=tfrstft(sig,t,128);
% imagesc(T,F,abs(tfr));
% axis xy; xlabel('Time'); ylabel('Frequency');
%
% See also QTFR, ATFR, ATS, SPWVD, WIGNER.
% F. Auger, May-July 1994, July 1995.
% Modified by T. H. Purcell, October 2021.
if (nargin < 1),
error('At least 1 parameter required');
end;
if (nargin < 2),
t=1:length(x);
end;
if (nargin < 3),
N=128;
end;
if (nargin < 4),
h=hamming(N/4)';
end;
if (nargin < 5),
trace='off';
end;
if (length(h) == 1),
h=hamming(h)';
end;
if (min(size(x)) ~= 1),
error('X must be a vector.');
end;
x=x(:).';
L=length(x);
M=length(h);
N2=fix(N/2);
% Time vector
t=t(:);
T=t(1)+((N/2):(L+N/2-1)).';
m=(1:M)-ceil(M/2);
h=h(:);
% Window matrix
H=h*ones(1,length(T));
% Matrix of indices
[Matind,MatindM]=meshgrid((1:N),m);
% Computation of the STFT
if strcmp(trace,'on')
disp('Progress of STFT :');
end;
TFR=zeros(N,length(T));
for icol=1:length(T),
ti=T(icol);
tau=ti-m;
indices=rem(tau,L)+1;
if strcmp(trace,'on')
clc; disp(['Column ' int2str(icol) ' out of ' int2str(length(T))]);
end;
x_tau=x(indices);
x_tau=x_tau(:);
if length(x_tau)<N,
x_tau=[x_tau;zeros(N-length(x_tau),1)];
end;
H_tau=h(rem(N+tau,N)+1);
H_tau=H_tau(:);
if (length(H_tau) ~= N),
H_tau=[H_tau;zeros(N-length(H_tau),1)];
end;
X_tau=fft(x_tau.*H_tau);
TFR(:,icol)=X_tau(:);
end;
% Output arguments
T=T(:)';
F=(0:N2)*2/N;
TFR=TFR(1:(N2+1),:);
F=F(:);
% End of TFRSTFT.
阅读全文