📄 tfrqview.m
字号:
function tfrqview(tfr,sig,t,method,p1,p2,p3,p4,p5);%TFRQVIEW Quick visualization of time-frequency representations.% TFRQVIEW(TFR,SIG,T,METHOD,P1,P2,P3,P4,P5) allows a quick % visualization of a time-frequency representation.%% TFR : time-frequency representation (MxN).% SIG : signal in time. If unavailable, put sig=[] as input% parameter. (default : []).% T : time instants (default : 1:N).% METHOD : name of chosen representation (default : 'TYPE1').% See the TFR* files for authorized names.% TYPE1 : the representation TFR goes in normalized% frequency from -0.5 to 0.5 ; % TYPE2 : the representation TFR goes in normalized% frequency from 0 to 0.5. % P1...P5 : optional parameters of the representation : run the % file TFRPARAM(METHOD) to know the meaning of P1..P5 % for your method. %% When you use the 'save' option in the main menu, you save all your% variables as well as two strings, TfrQView and TfrView, in a mat % file. If you load this file and do eval(TfrQView), you will restart% the display session under tfrqview ; if you do eval(TfrView), you% will obtain the exact layout of the screen you had when clicking on % the 'save' button. % % Example : % sig=fmsin(128); tfr=tfrwv(sig);% tfrqview(tfr,sig,1:128,'tfrwv');%% See also TFRVIEW, TFRSAVE, TFRPARAM.% F. Auger, September 1994, July 1995 % O. Lemoine, Oct 1995, May-July 1996.% F. Auger, May 1998.% 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 comp=computer; % so as to know the running computer% Tests on the input argumentsif nargin<1, error('At least one parameter required'); % at least the tfrend[tfrrow,tfrcol]=size(tfr); % *** tfr (tfrrow X tfrcol) 矩阵,行指频点,列指时间 ***if nargin==1, sig=[]; t=1:tfrcol; method='type1'; % empty signalelseif nargin==2, t=1:tfrcol; method='type1';elseif nargin==3, method='type1';end[trow,tcol] = size(t);if (trow~=1), error('T must only have one row'); % t must be a row vectorend;if (tfrcol~=tcol), error('T must have as much elements as tfr has columns');end;[Nsig,Ncol]=size(sig);if Ncol>2, error('SIG must have one or two columns');end% Computation of Nf2, the number of interresting points in frequencymethod=upper(method);if istfr2(method), Nf2=tfrrow; % 设定tfr的行数为输出频点。正频率点。elseif istfr1(method), Nf2=tfrrow/2; % elseif istfr3_adaptive(method), % Nf2=tfrrow; else error('Unknown representation. Use type1 or type2');end;% Computation of freq (vector of frequency samples) if istfraff(method), freq=eval(['p',num2str(nargin-4)]); % last input argument is freqs.else freq=(0.5*(0:Nf2-1)/Nf2); % 设定freq为显示的单位频率。0,......,0.5。end% Initialization of the variables 初始化和显示有关的变量。if exist('options.mat'), load optionselse threshold=5.0; % visualization threshold linlogtfr=0; % tfr visualization scale : 0 for linear 1 for logarithmic linlogspec=1; % spectrum visualization scale sigenveloppe=0; % signal enveloppe visualization levelnumb=6; % number of levels in the contour plot colmap=1; % colormap index display=2; % display index isgridsig=0; % grid on signal isgridspec=0; % grid on spectrum isgridtfr=0; % grid on tfr issig=0; % display signal isspec=0; % display spectrum iscolorbar=0; % display colorbarend;fs=1.0;% Test of analycity % 判断输入信号是否为解析信号。 if ~isempty(sig), for k=1:Ncol, % spec(:,k)=abs(fft(sig(min(t):max(t),k))).^2; Nsp=length(spec); % modifications : F. Auger (fog), 30/11/97 Lt_fog=max(t)-min(t)+1; Nb_tranches_fog = floor(Lt_fog/tfrrow); % fprintf('%f \n',Nb_tranches_fog); spec(:,k)=zeros(tfrrow,1); for Num_tranche_fog=0:Nb_tranches_fog-1, % fprintf('%f \n',Num_tranche_fog); spec(:,k)=spec(:,k)+abs(fft(sig(min(t)+tfrrow*Num_tranche_fog+(0:tfrrow-1),k))).^2; end; if (Lt_fog>Nb_tranches_fog*tfrrow), spectre_fog=fft(sig(min(t)+tfrrow*Nb_tranches_fog:max(t),k),tfrrow); spectre_fog=spectre_fog(:); spec(:,k)=spec(:,k)+abs(spectre_fog).^2; end; % spec1=sum(spec(1:tfrrow/2,k)); % spec2=sum(spec(tfrrow/2+1:Nsp,k)); spec1=sum(spec(1:tfrrow/2,k)); spec2=sum(spec(tfrrow/2+1:tfrrow,k)); if spec2>spec1/10, disp('Be careful : the signal is not analytic!'); end endend% Test of realityif (Ncol==2 & ~isreal(tfr)), disp('Cross distribution. As the result is complex, we display the real part.'); tfr=real(tfr);endChoiceDisplay = 1; % All the possible values of the choice variableChoiceLayout = 2;ChoiceColormap = 3;ChoiceSampling = 4;ChoiceThreshold = 5;ChoiceLinlog = 6;ChoiceLevels = 7;ChoiceGrid = 8;ChoiceRedraw = 9;ChoiceNewFigure =10;ChoiceSaveResults =11;ChoiceSaveOptions =12;ChoicePrint =13;ChoiceClose =14;CallTfrView = 1; % 1 to call tfrview, 0 not to do itRefreshFigure=1; % 1 to refresh figure every time, 0 to freezechoice=ChoiceSampling;while choice~=ChoiceClose, % while not close if RefreshFigure & CallTfrView, % Call to tfrview linlog=linlogtfr+2*linlogspec+4*sigenveloppe; isgrid=isgridsig+2*isgridspec+4*isgridtfr; layout=issig+isspec*2+iscolorbar*4+1; param = [display,linlog,threshold,levelnumb,Nf2,layout,fs,isgrid]; % display:显示方式选择contour,imagesc,pcolor,surf,mesh; % linlog: tfr显示视觉刻度,频谱视觉刻度,信号包络视觉; % threshold:视觉阈值 % levelnumb:contour绘图等级数 % Nf2:tfr的行数,输出频点数 % layout:issig(显示信号),isspec(显示频谱)和iscolorbar(显示色彩条)组合确定显示布局。 % fs:取样频率。 % isgrid:isgridsig(信号网格),isgridspec(频谱网格)和isgridtfr(tfr网格)组合确定是否显示grid。 if (nargin<=4), tfrview(tfr,sig,t,method,param); elseif (nargin==5), tfrview(tfr,sig,t,method,param,p1); elseif (nargin==6), tfrview(tfr,sig,t,method,param,p1,p2); elseif (nargin==7), tfrview(tfr,sig,t,method,param,p1,p2,p3); elseif (nargin==8), tfrview(tfr,sig,t,method,param,p1,p2,p3,p4); elseif (nargin==9), tfrview(tfr,sig,t,method,param,p1,p2,p3,p4,p5); end; end; if (linlogtfr==0), % Lin/log scale of the tfr 在menu中显示可改变刻度 linlogstr='Change to a logarithmic scale'; else linlogstr='Change to a linear scale'; end; if ~issig & ~isspec, % 消除和添加grid if isgridtfr, GridStr='Remove the grid'; else GridStr='Add a grid'; end; else GridStr='Grids'; end; if (RefreshFigure==1), % 重画 redrawstr='Don''t redraw yet'; else redrawstr='Redraw now'; end; % Main menu choice=menu ('TFRQVIEW MENU :',... 'Change the display mode',... % ChoiceDisplay 'Change the display layout',... % ChoiceLayout 'Change the color map',... % ChoiceColormap 'Change the sampling frequency',... % ChoiceSampling 'Change the threshold',... % ChoiceThreshold linlogstr,... % ChoiceLinlog 'Change the number of levels',... % ChoiceLevels GridStr,... % ChoiceGrid redrawstr,... % ChoiceRedraw 'New figure',... % ChoiceNewFigure 'Save results',... % ChoiceSaveResults 'Save options',... % ChoiceSaveOptions 'Print',... % ChoicePrint 'Close'); % ChoiceClose % 按所输入的选择打开相应的子菜单:1.Change the display mode;2.Change the display layout; % 3.Change the color map;4.Change the sampling frequency;5.Change the threshold; % 6.Change to a logarithmic scale;7.Change the number of levels;8.Grids;9.Don't redraw yet; % 10.New figure; 11.Save results;12.Save options;13.Print;14.Close. if (choice==ChoiceDisplay), % Change the display mode 1 display=menu('DISPLAY MODE :',... % 显示模式子菜单选择 'contour',... % 1 'imagesc',... % 2 'pcolor',... % 3 'surf',... % 4 'mesh',... % 5 'cancel'); % 6 if (display==6), CallTfrView=0; else CallTfrView=1; end; elseif (choice==ChoiceLayout), % Change the display layout 改变显示布局 2 layout=1; if issig==0, SignalStr= 'display signal'; % 显示信号 else SignalStr='remove signal'; end; if isspec==0, SpectrumStr= 'display spectrum'; % 显示频谱 else SpectrumStr='remove spectrum'; end; if iscolorbar==0, ColorbarStr='display colorbar'; % 显示色条 else ColorbarStr='remove colorbar';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -