📄 tfrstft.m
字号:
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 discrete-time signal X. % % X : signal.% T : time instant(s) (default : 1:length(X)). 时间刻度:1:256 % N : number of frequency bins (default : length(X)). 频率点数:256,N为2的几次幂 % H : frequency smoothing window, H being normalized so as to% be of unit energy. (default : Hamming(N/4)). % TRACE : if nonzero, the progression of the algorithm is shown% (default : 0).% TFR : time-frequency decomposition (complex values). The% frequency axis is graduated from -0.5 to 0.5.% F : vector of normalized frequencies.%% Example :% sig=[fmconst(128,0.2);fmconst(128,0.4)]; tfr=tfrstft(sig);% subplot(211); imagesc(abs(tfr));% subplot(212); imagesc(angle(tfr));% % See also all the time-frequency representations listed in% the file CONTENTS (TFR*)% F. Auger, May-August 1994, July 1995.% Copyright (c) 1996 by CNRS (France).%% ------------------- CONFIDENTIAL PROGRAM -------------------- % This program can not be used without the authorization of its% author(s). For any comment or bug report, please send e-mail to % f.auger@ieee.org [xrow,xcol] = size(x);if (nargin < 1), error('At least 1 parameter is required');elseif (nargin <= 2), N=xrow; % For a faster computation, N should be a power of twoend;hlength=floor(N/4);hlength=hlength+1-rem(hlength,2); % modidy window length so that hlength is odd. if (nargin == 1), t=1:xrow; h = window(hlength); trace=0; % 时间点设为输入信号长度elseif (nargin == 2) | (nargin == 3), h = window(hlength); trace = 0;elseif (nargin == 4), trace = 0;end;if (N<0), error('N must be greater than zero');end;[trow,tcol] = size(t);if (xcol~=1), error('X must have one column');elseif (trow~=1), error('T must only have one row'); elseif (2^nextpow2(N)~=N), fprintf('For a faster computation, N should be a power of two\n');end; [hrow,hcol]=size(h); Lh=(hrow-1)/2; % get the number of the half window,窗h以列形式保存 if (hcol~=1)|(rem(hrow,2)==0), error('H must be a smoothing window with odd length');end;h=h/norm(h); % window energy normalizationtfr= zeros (N,tcol) ; % initialize output time frequency distribution matrix, N:frequency bin axis, tcol:time axisif trace, disp('Short-time Fourier transform'); end; % N:频率垂直轴,tcol:时间横轴for icol=1:tcol, ti= t(icol); tau=-min([round(N/2)-1,Lh,ti-1]):min([round(N/2)-1,Lh,xrow-ti]); indices= rem(N+tau,N)+1; if trace, disprog(icol,tcol,10); end; tfr(indices,icol)=x(ti+tau,1).*conj(h(Lh+1+tau));end;% x(ti+tau,1).*conj(h(Lh+1+tau)) 完成加窗。输入信号:xrow,256点(时间);xrol,1。初始,ti=1,tau=0,1,2...31,32。共取33信号点。% 窗取Lh=32,h(Lh+1+tau)为右半侧窗,且取共轭。进行x(ti+tau,1)和conj(h(Lh+1+tau))的33点对应相乘。放入tfr占据(1,..,33)x1位置。% ti向右移一点ti=2,tau=-1,0,...,32。indices:256,1,2,...,33。tfr(indices,icol)占据(256,1,2,...,33)x2的位置。% ti向右移一点ti=3,tau=-2,-1,...,32。indices:255,256,1,...,33。tfr(indices,icol)占据(255,256,1,2,...,33)x3的位置。% ti向右移一点ti=4,tau=-3,-2,-1,...,32。indices:254,255,256,1,...,33。tfr(indices,icol)占据(254,255,256,1,2,...,33)x3的位置。% ti向右移一点ti=5,tau=-4,-3,-2,-1,...,32。indices:253,254,255,256,1,...,33。tfr(indices,icol)占据(253,254,255,256,1,2,...,33)x3的位置。% ......% ti向右移ti=32,indices:225,...,256,1,...,33。tfr(indices,icol)占据(225,...,256,1,2,...,33)x32的位置。% ......% ti向右移一点ti=128,tau=-32,-31,...,31,32。indices:225,...,256,1,...,33。tfr(indices,icol)占据(225,...,256,1,...,33)x128的位置。% ......% ti向右移ti=225,indices:225,...,256,1,...,32。tfr(indices,icol)占据(225,...,256,1,...,32)x225的位置。% ti向右移ti=256,indices:225,...,256,1。tfr(indices,icol)占据(225,...,256,1)x256的位置。tfr=fft(tfr); % TFRSTFT Short time Fourier transform,只是fft,并不是功率谱if trace, fprintf('\n'); end; % *** tfr (Nxtcol矩阵,行和列相等,行指频点,列指时间 ***if (nargout==0), tfrqview(abs(tfr).^2,x,t,'tfrstft',h);elseif (nargout==3), f=fftshift(0.5*(-N:N-1)/N)';end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -