首先tftb的Choi-Williams的tfrcw()函数是这样的:
function [tfr,t,f] = tfrcw(x,t,N,g,h,sigma,trace);
%TFRCW Choi-Williams time-frequency distribution.
% [TFR,T,F]=TFRCW(X,T,N,G,H,SIGMA,TRACE) computes the Choi-Williams
% distribution of a discrete-time signal X, or the
% cross Choi-Williams representation between two signals.
%
% X : signal if auto-CW, or [X1,X2] if cross-CW.
% T : time instant(s) (default : 1:length(X)).
% N : number of frequency bins (default : length(X)).
% G : time smoothing window, G(0) being forced to 1.
% (default : Hamming(N/10)).
% H : frequency smoothing window, H(0) being forced to 1.
% (default : Hamming(N/4)).
% SIGMA : kernel width (default : 1)
% TRACE : if nonzero, the progression of the algorithm is shown
% (default : 0).
% TFR : time-frequency representation. When called without
% output arguments, TFRCW runs TFRQVIEW.
% F : vector of normalized frequencies.
%
% Example:
% sig=fmlin(128,0.05,0.3)+fmlin(128,0.15,0.4);
% g=tftb_window(9,'Kaiser'); h=tftb_window(27,'Kaiser');
% t=1:128; tfrcw(sig,t,128,g,h,3.6,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).
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
if (nargin == 0),
error('At least 1 parameter required');
end;
[xrow,xcol] = size(x);
if (xcol==0)|(xcol>2),
error('X must have one or two columns');
end
if (nargin <= 2),
N=xrow;
elseif (N<0),
error('N must be greater than zero');
elseif (2^nextpow2(N)~=N),
fprintf('For a faster computation, N should be a power of two\n');
end;
hlength=floor(N/4); hlength=hlength+1-rem(hlength,2);
glength=floor(N/10);glength=glength+1-rem(glength,2);
if (nargin == 1),
t=1:xrow; g = tftb_window(glength); h = tftb_window(hlength); sigma = 1.0; trace = 0;
elseif (nargin == 2)|(nargin == 3),
g = tftb_window(glength); h = tftb_window(hlength); sigma = 1.0; trace = 0;
elseif (nargin == 4),
h = tftb_window(hlength); sigma = 1.0; trace = 0;
elseif (nargin == 5),
sigma = 1.0; trace = 0;
elseif (nargin == 6),
trace = 0;
end;
[trow,tcol] = size(t);
if (trow~=1),
error('T must only have one row');
end;
[grow,gcol]=size(g); Lg=(grow-1)/2;
if (gcol~=1)|(rem(grow,2)==0),
error('G must be a smoothing window with odd length');
end;
[hrow,hcol]=size(h); Lh=(hrow-1)/2; h=h/h(Lh+1);
if (hcol~=1)|(rem(hrow,2)==0),
error('H must be a smoothing window with odd length');
end;
if (sigma<=0.0),
error('SIGMA must be strictly positive');
end;
normfac = 16.0*pi/sigma; spreadfac = 16.0/sigma;
taumax = min([round(N/2),Lh]); tau = 1:taumax; points = -Lg:Lg;
CWKer = exp(-kron( points.' .^2, 1.0 ./ (spreadfac*tau.^2)));
CWKer = diag(g) * CWKer;
tfr= zeros (N,tcol) ;
if trace, disp('Choi-Williams distribution'); end;
for icol=1:tcol,
ti= t(icol); taumax=min([ti+Lg-1,xrow-ti+Lg,round(N/2)-1,Lh]);
if trace, disprog(icol,tcol,10); end;
tfr(1,icol)= x(ti,1) .* conj(x(ti,xcol));
for tau=1:taumax,
points= -min([Lg,xrow-ti-tau]):min([Lg,ti-tau-1]);
g2 = CWKer(Lg+1+points,tau); g2=g2/sum(g2);
R=sum(g2 .* x(ti+tau-points,1) .* conj(x(ti-tau-points,xcol)));
tfr( 1+tau,icol)=h(Lh+tau+1)*R;
R=sum(g2 .* x(ti-tau-points,1) .* conj(x(ti+tau-points,xcol)));
tfr(N+1-tau,icol)=h(Lh-tau+1)*R;
end;
tau=round(N/2);
if (ti<=xrow-tau)&(ti>=tau+1)&(tau<=Lh),
points= -min([Lg,xrow-ti-tau]):min([Lg,ti-tau-1]);
g2 = CWKer(Lg+1+points,tau); g2=g2/sum(g2);
tfr(tau+1,icol) = 0.5 * ...
(h(Lh+tau+1)*sum(g2 .* x(ti+tau-points,1) .* conj(x(ti-tau-points,xcol)))+...
h(Lh-tau+1)*sum(g2 .* x(ti-tau-points,1) .* conj(x(ti+tau-points,xcol))));
end;
end;
clear CWKer;
if trace, fprintf('\n'); end;
tfr= fft(tfr);
if (xcol==1), tfr=real(tfr); end ;
if (nargout==0),
tfrqview(tfr,x,t,'tfrcw',g,h,sigma);
elseif (nargout==3),
f=(0.5*(0:N-1)/N)';
end;
想请问,按函数介绍,输出的f是归一化频率吧?而且的确我改动N,无论N是多少,f总是在[0,0.5]范围内,但我在查找归一化频率的资料时有说归一化频率取在[0,1]的,也有[-0.5,0.5]的。想问,如果像这样设定在[0,0.5]的归一频率,是不是纵轴对应的频率就是数值*原始数据的采样频率?
还有,得出的分布总是N×t的大小,而且是上下对称的,是为什么呢(此张N=500)?
我的输入信号sig为96×1的single型数据,sig是实信号,sig经过100Hz低通滤波且低频特征明显;
原始采样频率为250Hz;
我想要得到信号的cwd分布,并且切割下1-32Hz的部分,而且想要频率轴每Hz对应一个点,即输出为32×96,频率分辨率为1,下面这样可以吗?
t=1:96;
g=window(@kaiser,9);
N=250;
%我困惑的地方就是这里,N按函数解释,是频率箱个数?想得到频率分辨率为1的话,N=原始采样频率,对吗?
[tfr,t,f] = tfrcw(x,t,N,g);
imagesc(t,f,abs(tfr(1:32,:)))
%截取图像中的1-32Hz部分可以直接这么对矩阵切割然后画图吗?
set(gca,'YDir','Normal')
又看到,常在对实信号做二次时频分析前,进行希尔伯特变换,这是为了什么呢?虽然我不知道为什么但我尝试了一下:
t=1:96;
g=window(@kaiser,9);
N=250;
%上图
[tfr1,t,f]=tfrcw((x,t,N,g);
imagesc(t,f,abs(tfr1))
set(gca,'YDir','Normal')
%下图
x2=hilbert(x);
[tfr2,t,f]=tfrcw((x2,t,N,g);
imagesc(t,f,abs(tfr2))
set(gca,'YDir','Normal')
经过hilbert变换的,的确图不对称了,但是这是什么意义呢?频率轴又怎么对应实际频率呢?
非常感谢大家!
我觉得:1.纵轴对应的频率就是数值0.5原始数据的采样频率,采样定理。
2.FFT变换完的数据就是对称的,一般频谱是取其结果的前1/2,结果中的对称应该也是这个原因吧。
3.没细研究过,感觉差不多。
%X:自动CW时的信号,或交叉CW时的[X1,X2]。
%T:时间瞬间(s)(默认值:1:长度(X))。
%N:频率箱数(默认值:长度(X))。
%G:时间平滑窗口,G(0)被强制为1。
%(默认值:Hamming(N/10))。
%H:频率平滑窗口,H(0)强制为1。
%(默认值:Hamming(N/4))。
%SIGMA:内核宽度(默认值:1)
%跟踪:如果非零,则显示算法的进程
%(默认值:0)。
%TFR:时频表示。调用时没有
%输出参数时,TFRCW运行TFRQVIEW。
%F:归一化频率向量。