?? tfrsp.m
字號:
function [tfr,t,f] = tfrsp(x,t,N,h,trace);%TFRSP Spectrogram time-frequency distribution.% [TFR,T,F]=TFRSP(X,T,N,H,TRACE) computes the Spectrogram % distribution of a discrete-time signal X. % % X : signal.% T : time instant(s) (default : 1:length(X)).% N : number of frequency bins (default : length(X)).% H : analysis 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 representation. When called without % output arguments, TFRSP runs TFRQVIEW.% F : vector of normalized frequencies.%% Example :% sig=fmlin(128,0.1,0.4);% h=window(17,'Kaiser'); tfrsp(sig,1:128,64,h,1);% % 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.rog if (nargin == 0), error('At least 1 parameter required');end;[xrow,xcol] = size(x);if (nargin < 1), error('At least 1 parameter is required');elseif (nargin <= 2), N=xrow;end;hlength=floor(N/4);hlength=hlength+1-rem(hlength,2);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==0) | (xcol>2), error('X must have one or two columns');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;if (hcol~=1)|(rem(hrow,2)==0), error('H must be a smoothing window with odd length');end;tfr= zeros (N,tcol) ; if trace, disp('Spectrogram'); end;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).*conj(h(Lh+1+tau))/norm(h(Lh+1+tau));end;%------icol=1,ti=1,tau=0,1,2,3,4,5,6,indices=1,2,3,4,5,6,7----------speech1000 % tfr(1,1)=x(1).*h(7)/1.8107=-2.1359, tfr(2,1)=x(2).*h(8)/1.8107=-2.4651,tfr(3,1)=x(3).*h(9)/1.8107=-2.2424,% tfr(4,1)=x(4).*h(10)/1.8107=-2.0141,tfr(5,1)=x(5).*h(11)/1.8107=-1.3516,tfr(6,1)=x(6).*h(12)/1.8107=-0.84225,% tfr(7,1)=x(7).*h(13)/1.8107=-0.51658%------icol=2,ti=2,tau=-1,0,1,2,3,4,5,6,indices=256,1,2,3,4,5,6,7% tfr(256,2)=x(1).*h(6)/2.0468=-1.8034,tfr(1,2)=x(2).*h(7)/2.0468=-2.2848,tfr(2,2)=x(3).*h(8)/2.0468=-2.2899,% tfr(3,2)=x(4).*h(9)/2.0468=-2.2933,tfr(4,2)=x(5).*h(10)/2.0468=-1.7550,tfr(5,2)=x(6).*h(11)/2.0468=-1.2879,% tfr(6,2)=x(7).*h(12)/2.0468=-0.9216,tfr(7,2)=x(8).*h(13)/2.0468=-0.4805% 分析窗h先由正半側(cè)由第1個樣值x(1),x(2),x(3),x(4),x(5),x(6),x(7),向最后1個樣值x(256)滑行;最后與樣值x(250),x(251),% x(253),x(254),x(255),x(256),對應(yīng)相乘的窗h(1),h(2),h(3),h(4),h(5),h(6),h(7).tfr=abs(fft(tfr)).^2; % *** tfr (Nxtcol) 矩陣,行指頻點(diǎn),列指時間 ***% tfr第1列:% (1) 133.81% (2) 133.58% (3) 132.88% (4) 131.71% (5) 130.1% ... 第1,129行單獨(dú)成行;第2行到第128行(127行)與第256行到第130行(127行)以第129行為軸上下對應(yīng) % (127)0.83925% (128)0.85153% (129)0.85567% (130)0.85153% (131)0.83925% ... 只取第1行到129行可作為,0到4000Hz頻率范圍% (253)130.1% (254)131.71% (255)132.88% (256)133.58if trace, fprintf('\n'); end;if (nargout==0), tfrqview(tfr,x,t,'tfrsp',h);elseif (nargout==3), f=fftshift((-N/2:N/2-1)/N)';end;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -