tfrwv.m

来自「时频分析工具箱」· M 代码 · 共 118 行

M
118
字号
function [tfr,t,f] = tfrwv(x,t,N,trace);%TFRWV	Wigner-Ville time-frequency distribution.%	[TFR,T,F]=TFRWV(X,T,N,TRACE) computes the Wigner-Ville distribution%	of a discrete-time signal X, %	or the cross Wigner-Ville representation between two signals. % %	X     : signal if auto-WV, or [X1,X2] if cross-WV.                      %	输入信号为列向量%	T     : time instant(s)          (default : 1:length(X)).%	N     : number of frequency bins (default : length(X)).%	TRACE : if nonzero, the progression of the algorithm is shown%	                                 (default : 0).%	TFR   : time-frequency representation. When called without %	        output arguments, TFRWV runs TFRQVIEW.%	F     : vector of normalized frequencies.%%	Example :%	 sig=fmlin(128,0.1,0.4); tfrwv(sig);% %	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 if (nargin == 0), error('At least one parameter required');end;[xrow,xcol] = size(x);if (nargin == 1), t=1:xrow; N=xrow ; trace=0;elseif (nargin == 2), N=xrow ; trace=0;elseif (nargin == 3), 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; tfr= zeros (N,tcol);  if trace, disp('Wigner-Ville distribution'); end;for icol=1:tcol, ti= t(icol); taumax=min([ti-1,xrow-ti,round(N/2)-1]); tau=-taumax:taumax; indices= rem(N+tau,N)+1; tfr(indices,icol) = x(ti+tau,1) .* conj(x(ti-tau,xcol)); tau=round(N/2);  if (ti<=xrow-tau)&(ti>=tau+1),  tfr(tau+1,icol) = 0.5 * (x(ti+tau,1) * conj(x(ti-tau,xcol))  + ...                           x(ti-tau,1) * conj(x(ti+tau,xcol))) ; end; if trace, disprog(icol,tcol,10); end;end; % tfr构成说明: t=1,2,3,...,254,255,256 % (1)icol=1,第1列, ti=1, taumax=0,tau=0,indices=1% tfr(1,1)=x(1,1)*x(1,1)=5.2786e5% (2)icol=2,第2列, ti=2, taumax=1,tau=-1,0,1;indices=256,1,2% tfr(256,2)=x(1,1)*x(3,1)=6.7026e5% tfr(1,2)=x(2,1)*x(2,1)=7.7183e5% tfr(2,2)=x(3,1)*x(1,1)=6.7026e5% (3)icol=3,第3列, ti=3, taumax=2,tau=-2,-1,0,1,2;indices=255,256,1,2,3% tfr(255,3)=x(1,1)*x(5,1)=7.6326e5% tfr(256,3)=x(2,1)*x(4,1)=9.37e5% tfr(1,3)=x(3,1)*x(3,1)=8.5108e5% tfr(2,3)=x(4,1)*x(2,1)=9.37e5% tfr(3,3)=x(5,1)*x(1,1)=7.6326e5% (4)icol=4,第4列, ti=4, taumax=3,tau=-3,-2,-1,0,1,2,3;indices=254,255,256,1,2,3,4% tfr(254,4)=x(1,1)*x(7,1)=1.0168e6% tfr(255,4)=x(2,1)*x(6,1)=9.941e5% tfr(256,4)=x(3,1)*x(5,1)=9.6917e5% tfr(1,4)=x(4,1)*x(4,1)=1.1375e6% tfr(2,4)=x(5,1)*x(3,1)=9.6917e5% tfr(3,4)=x(6,1)*x(2,1)=9.941e5% tfr(4,4)=x(7,1)*x(1,1)=1.0168e6% (5)icol=5,第5列, ti=5, taumax=4,tau=-4,-3,-2,-1,0,1,2,3,4;indices=253,254,255,256,1,2,3,4,5% tfr(253,5)=x(1,1)*x(9,1)=1.0924e6% tfr(254,5)=x(2,1)*x(8,1)=1.2928e6% tfr(255,5)=x(3,1)*x(7,1)=1.2911e6% tfr(256,5)=x(4,1)*x(6,1)=1.2068e6% tfr(1,5)=x(5,1)*x(5,1)=1.1036e6% tfr(2,5)=x(6,1)*x(4,1)=1.2068e6% tfr(3,5)=x(7,1)*x(3,1)=1.2911e6% tfr(4,5)=x(8,1)*x(2,1)=1.2928e6% tfr(5,5)=x(9,1)*x(1,1)=1.0924e6% 第2到128行与256到130行,上下以第129行为轴对应列元素相等,第1行为输入矢量各元素平方项(自身与其共轭相乘),% 第129行始终为0;横轴方向,即由左到右列向为时间,1到256点(将时间离散点化,此处32ms);行索引indices与tau有关系,% 第1行,tau=0;第2行,tau=1;第3行,tau=2;...;第128行,tau=127。% 下面用fft对1到256行的tau计算傅氏变换% If 输入 is a matrix, fft returns the Fourier transform of each column of the matrix.tfr= fft(tfr);                                  % ***  tfr (Nxtcol) 矩阵,行指频点,列指时间  ***% tfr第2到128行与256到130行,上下以第129行为轴对应列元素相等,第1行与其他行不同,第129行与其他行不同;% 横轴方向,即由左到右列向为时间,1到256点(将时间离散点化,此处32ms);% 可取上半部分第1行,第2行到128行,第129行共129行的129点,与频率范围(0到4000Hz)对应,省掉下半部分256到130行的重复内容。if (xcol==1), tfr=real(tfr); end ;if (nargout==0), tfrqview(tfr,x,t,'tfrwv');elseif (nargout==3), f=(0.5*(0:N-1)/N)';end;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?