声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1635|回复: 3

[HHT] 请教一下gabriel.rilling的toimage函数

[复制链接]
发表于 2009-9-16 12:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我知道这个函数是用来求希尔伯特时频谱的输出矩阵的,但是对立面的某些语句不是很明白,就是定义完变量之后的那几行,我用红色标注了,望各位能指点一下,谢谢。
%TOIMAGE  transforms a spectrum made of 1D functions in an 2D image
%
% [im,tt,ff] = TOIMAGE(A,f,t,splx,sply) transforms a spectrum made
% of 1D functions (e.g., output of "hhspectrum") in an 2D image
%
% inputs :   - A    : amplitudes of modes (1 mode per row of A)
%            - f    : instantaneous frequencies
%            - t    : time instants
%            - splx : number of columns of the output im (time resolution).
%                     If different from length(t), works only for uniform
%                     sampling.
%            - sply : number of rows of the output im (frequency resolution).
% outputs :  - im   : 2D image of the spectrum
%            - tt   : time instants in the image
%            - ff   : centers of the frequency bins
%
% Examples : [im,tt,ff] = toimage(A,f);[im,tt] = toimage(A,f,t);[im,tt,ff] = toimage(A,f,sply);
%            [im,tt,ff] = toimage(A,f,splx,sply);[im,tt,ff] = toimage(A,f,t,splx,sply);
%
%
% See also
%  emd, hhspectrum, disp_hhs
%
% G. Rilling, last modification 3.2007
% gabriel.rilling@ens-lyon.fr
function [im,tt,ff] = toimage(A,f,varargin)

DEFSPL = 400;
error(nargchk(2,5,nargin));
switch nargin
  case 2
    t = 1:size(A,2);
    sply = DEFSPL;
    splx = length(t);
  case 3
    if isscalar(varargin{1})
      t = 1:size(A,2);
      splx = length(t);
      sply = varargin{1};
    else
      t = varargin{1};
      splx = length(t);
      sply = DEFSPL;
    end
  case 4
    if isscalar(varargin{1})
      t = 1:size(A,2);
      sply = varargin{1};
      splx = varargin{2};
    else
      t = varargin{1};
      sply = varargin{2};
      splx = length(t);
    end
  case 5
    t = varargin{1};
    splx = varargin{2};
    sply = varargin{3};
end
if isvector(A)
  A = A(:)';
  f = f(:)';
end

if issparse(A) || ~isreal(A) || length(size(A)) > 2
  error('A argument must be a real matrix')
end
if issparse(f) || ~isreal(f) || length(size(f)) > 2
  error('f argument must be a real matrix')
end
if any(size(f)~=size(A))
  error('A and f matrices must have the same size')
end
if issparse(t) || ~isreal(t) || ~isvector(t) || length(t)~=size(A,2)
  error('t argument must be a vector and its length must be the number of columns in A and f inputs')
end
if ~isscalar(splx) || ~isreal(splx) || splx ~= floor(splx) || splx <= 0
  error('splx argument must be a positive integer')
end
if ~isscalar(sply) || ~isreal(sply) || sply ~= floor(sply) || sply <= 0
  error('splx argument must be a positive integer')
end
if any(diff(diff(t))) && splx ~= length(t)
  warning('toimage:nonuniformtimeinsants','When splx differs from length(t), the function only works for equally spaced time instants. You may consider reformating your data (using e.g. interpolation) before using toimage.')
end
f = min(f,0.5);
f = max(f,0);

indf = round(2*f*(sply-1)+1);
indt = repmat(round(linspace(1,length(t),splx)),size(A,1),1);
im = accumarray([indf(:),indt(:)],A(:),[sply,splx]);

indt = indt(1,:);
tt = t(indt);
ff = (0:sply-1)*0.5/sply+1/(4*sply);

end

本帖被以下淘专辑推荐:

回复
分享到:

使用道具 举报

发表于 2009-9-16 21:33 | 显示全部楼层

回复 楼主 asemao 的帖子

你在论坛里搜toimage相关的帖子,有些提示信息。我原来也读过这个程序,现在只知道,f = min(f,0.5);
f = max(f,0);这两句是保证归一化后的频率在[0,0.5]之间,最重要的是看懂accumarray函数。
 楼主| 发表于 2009-9-16 22:26 | 显示全部楼层
本帖最后由 wdhd 于 2016-9-19 13:00 编辑
原帖由 xiaoxiong702 于 2009-9-16 21:33 发表
你在论坛里搜toimage相关的帖子,有些提示信息。我原来也读过这个程序,现在只知道,f = min(f,0.5);
f = max(f,0);这两句是保证归一化后的频率在[0,0.5]之间,最重要的是看懂accumarray函数。

这个我也明白,就是后面那几行现在还理解不了
发表于 2009-9-17 10:17 | 显示全部楼层

回复 板凳 asemao 的帖子

那就期待高手吧。
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-4 00:33 , Processed in 0.263530 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表