📄 waveleted.m
字号:
function waveleted(arg1,arg2,arg3)
% WAVELETED is an interactive wavelet editor for creating and modifying
% wavelets. It accepts an EarthObject full of wavelets and provides
% graphical facilities for the analysis and/or modification of the existing
% wavelets and the creation of new wavelets which are then put into the
% object.
%
% Calling mechanisms:
% waveleted ... with no arguments, a blank wavelet editor window is opened
% which can then be used to create or import any number
% of wavelets or to open an existing wavelet object from disk
% waveleted(waveletobj) ... with a single argument which is a wavelet object,
% WAVELETED opens an editor with the wavelets in this object
% available for editing
% waveleted(waveletobj,hmasterfig,transferfcn) ... this mode is used when it
% is desired to have another program (or figure) in control of
% the wavelet editor. It causes the 'xmit' action in WAVELETED
% to be enabled. If the user selects 'xmit', WAVELETED does
% the following:
% figure(hmasterfig)
% eval([transferfcn '(''wavelets'',waveletobj)'])
% That is it sets the figure whose handle is hmasterfig to be
% c urrent and then uses the MATLAB eval function to call the
% function whose name is given by the string transferfcn with
% the arguments 'wavelets',waveletobj. Thus if you have a
% program called DOSTUFF which wants to invoke the wavelet
% editor, then you must include a segment of code in DOSTUFF
% which can respond to the call:
% dostuff('wavelets',waveletobj) and you supply
% WAVELETED with the string 'dostuff' as its third argument.
% (This 'xmit' action will not dismiss the editor, that must
% be done manually.)
%
% G.F. Margrave, March 1994
% Updated July 1997
%
% NOTE: Wavelet files saved in version 4.x are not compatible with current
% version 5.
%
% NOTE: It is illegal for you to use this software for a purpose other
% than non-profit education or research UNLESS you are employed by a CREWES
% Project sponsor. By using this software, you are agreeing to the terms
% detailed in this software's Matlab source file.
% BEGIN TERMS OF USE LICENSE
%
% This SOFTWARE is maintained by the CREWES Project at the Department
% of Geology and Geophysics of the University of Calgary, Calgary,
% Alberta, Canada. The copyright and ownership is jointly held by
% its author (identified above) and the CREWES Project. The CREWES
% project may be contacted via email at: crewesinfo@crewes.org
%
% The term 'SOFTWARE' refers to the Matlab source code, translations to
% any other computer language, or object code
%
% Terms of use of this SOFTWARE
%
% 1) Use of this SOFTWARE by any for-profit commercial organization is
% expressly forbidden unless said organization is a CREWES Project
% Sponsor.
%
% 2) A CREWES Project sponsor may use this SOFTWARE under the terms of the
% CREWES Project Sponsorship agreement.
%
% 3) A student or employee of a non-profit educational institution may
% use this SOFTWARE subject to the following terms and conditions:
% - this SOFTWARE is for teaching or research purposes only.
% - this SOFTWARE may be distributed to other students or researchers
% provided that these license terms are included.
% - reselling the SOFTWARE, or including it or any portion of it, in any
% software that will be resold is expressly forbidden.
% - transfering the SOFTWARE in any form to a commercial firm or any
% other for-profit organization is expressly forbidden.
%
% END TERMS OF USE LICENSE
% Description of Wavelet objects
% 1) The wavelets themselves are stored in a fleximat whos x coordinate
% is just a numeric index and whos y coordinate is time.
% 2) The fleximat is in a container whose datatype is 'wlet' and whose name
% refers to the entire collection of wavelets e.g.: 'Freds favorite wavelets'
% 3) The name of the fleximat within the container will always be 'wavelets'
% 4) The individual wavelet names will be in a string matrix and stored in the
% container under the name 'wavelet names'. The string matrix will pad the
% names with 1's so that they are distinct from blanks and can be detected and
% removed. Note that objget will return this as a numeric matrix and you
% must run setstr on the result to get strings.
% 5) Additionally, WAVELETED will insert a parameters object that, among other
% things, will remember which wavelets were last being edited
%
global currentMenu
if(nargin<1)
action='init';
wlet=[]; hmasterfig=[]; transfer=[]; dt=[];
else
if( ~isstr(arg1) )
action='init';
wlet=arg1;
dt=[];
if( nargin< 2)
hmasterfig=[];
transfer=[];
else
hmasterfig=arg2;
transfer=arg3;
end
else
action=arg1;
end
end
global COMPILED
global EXPIRATION_DATE;
crcompile; % set COMPILED and EXPIRATION_DATE in crcompiled.m
if( nargin < 1 )
action = 'init';
end
if(COMPILED&strcmp(action,'init'))
today=datenum(date);
daysleft=EXPIRATION_DATE-today;
if((daysleft<30)&(daysleft>0))
uiwait(msgbox(['Your license for WAVELETED will expire in ' num2str(daysleft) ' days. ',...
'CREWES Sponsors can download new executables on Jan 2 of the next year.'],...
' CREWES wants you to know ','modal'))
end
if(daysleft<=0)
msgbox(['Your license for WAVELETED has expired. '...
'Please contact CREWES at crewesinfo@crewes.org to renew sponsorship or purchase a new license.'],...
'Oh Oh, this is a truly sad day...')
return
end
end
% userdata assignments:
% the figures userdata contains all relevent handles of children
% set(hfig,'userdata',[haction, hnew, hchange, hxmit, hsave, hsaveascii,...
% hsaveobject, hquit, hax1, hax2, hax3, hwave, ...
% hactive, hmsg hdelete hzoom hunzoom hrename,...
% hsavecurrent hsaveall hshowsave]);
% haction (the actions menu) ... integer indicating the current action
% hnew (new action menu) ... integer 1 and the handle of the active design
% window
% hchange (change action menu) ... integer 2
% hxmit (xmit action menu) ... integer 4 and the handle of the master figure
% hsave (save action menu) ... integer 5
% hsaveascii (saveascii action menu) ... the transfer function used by xmit
% hsaveobject (saveobject action menu) ... the time sample rate
% hquit (quit action menu) ... the wavelet object
% hax1 (time axis) ... don't use (used by zooming etc)
% hax2 (db freq axis) ... don't use (used by zooming etc)
% hax3 (phase freq axis) ... don't use (used by zooming etc)
% hwave (wavelets menu) ... vector of handles of the wavlet submenus. Handle is
% negative if the wavelet is on display
% hactive (active wavlet msg panel) ... the menu handle of the active wavelet
% hmsg (msg panel) ... six pairs of numbers giving the default axis settings for
% the 3 plots
% hdelete (delete menu) ... the integer 3
% hzoom ... the integer 6
% hunzoom ... the integer 7
% hrename ... the integer 8
% hmenu (the various wavelet menus) ... if the wavelet is plotted, then the
% userdata has the handles of the three curve (time, amp, phs) otherwise
% it is null
% hsavecurrent ... not used
% hsaveall ... not uset
% hshowsave ... not used
if( strcmp(action,'init') )
%put a file object in the wavlet object if needed
%get the fileobj
if( ~isempty(wlet) )
fileobj=objget(wlet,'file');
if( isempty(fileobj) )
fileobj=contobj('file','prvt');
filename='undefined';
pathname=' ';
fileobj=objset(fileobj,'filename',filename);
fileobj=objset(fileobj,'pathname',pathname);
wlet=objset(wlet,'file',fileobj);
end
end
%open up a new figure
hfig=figure;
positionWindow(hfig,'waveleted','main',800,800);
set(hfig,'menubar','none');
set(hfig,'name','Wavelet Editor','numbertitle','off');
%create an actions menu
haction=uimenu(hfig,'label','File','userdata',0);
% various action submenus
hopen=uimenu(haction,'label','Open Saved Wavelet File','callback',...
'waveleted(''open'')','userdata',9);
hnew=uimenu(haction,'label','New Wavelet','callback',...
'waveleted(''new'')','userdata',[1 0]);
hchange=uimenu(haction,'label','Modify Active Wavelet','callback',...
'waveleted(''change'')','userdata',2,'enable','off');
hrename=uimenu(haction,'label','Rename Active Wavelet','callback',...
'waveleted(''rename'')','userdata',8,'enable','off');
hdelete=uimenu(haction,'label','Delete Active Wavelet','callback',...
'waveleted(''delete'')','userdata',3,'enable','off');
hxmit=uimenu(haction,'label','Transmit Changes','callback',...
'waveleted(''xmit'')','userdata',[4 hmasterfig]);
if( isempty(hmasterfig) )
set(hxmit,'enable','off');
end
hsave=uimenu(haction,'label','Save...','userdata',5,...
'callback','waveleted(''save'');');
hsaveopts=uimenu(haction,'label','Save Options');
hsaveascii=uimenu(hsaveopts,'label','ASCII file','callback',...
'waveleted(''saveopts'')','checked','off','userdata',transfer);
hsaveobject=uimenu(hsaveopts,'label','Object file','callback',...
'waveleted(''saveopts'')','userdata',dt,'checked','on');
hsavecurrent=uimenu(hsaveopts,'label','Save Active Wavelet','callback',...
'waveleted(''saveopts'')','checked','off');
hsaveall=uimenu(hsaveopts,'label','Save All Wavelets','callback',...
'waveleted(''saveopts'')','checked','on');
hshowsave=uimenu(hsaveopts,'label','Show Save File','callback',...
'waveleted(''showsave'')');
hquit=uimenu(haction,'label','Quit','callback','waveleted(''quit'')');
set(hquit,'userdata',wlet);
%create an view menu
hview=uimenu(hfig,'label','View','userdata',0);
hzoom=uimenu(hview,'label','Zoom','callback',...
'waveleted(''zoominit'')','userdata',6);
hunzoom=uimenu(hview,'label','unZoom','callback',...
'waveleted(''unzoom'')','userdata',7);
%make three axes
%reserve the bottom 10% for controls, each axis gets 30%
hax1=axes('Position',[.15,.65,.8,.23]);
set(hax1,'ylabel',text(0,0,'Amplitude'));
set(hax1,'xlabel',text(0,0,'Time'));
hax2=axes('Position',[.15,.35,.8,.23]);
set(hax2,'ylabel',text(0,0,'Decibels'));
set(hax2,'xlabel',text(0,0,'Frequency'));
hax3=axes('Position',[.15,.05,.8,.23]);
set(hax3,'ylabel',text(0,0,'Phase Angle'));
set(hax3,'xlabel',text(0,0,'Frequency'));
% make the wavelets menu
hwave=uimenu(gcf,'label','Wavelets');
%get the wavelet names
if( ~isempty(wlet) )
wnames=objget(wlet,'wavelet_names');
[numnames,r]=size(wnames);
wletparms=objget(wlet,'waveleted params');
else
wletparms=[];
wnames=[];
numnames=0;
end
%make the wavelets menus
if( isempty(wletparms) )
wletparms=zeros(1,numnames);
wletparms(1)=1;
end
nameflags=wletparms(1:numnames);
hwmenu=zeros(1,numnames);
for k=1:numnames
if(nameflags(k))
checked='on';
else
checked='off';
end
hwmenu(k)=uimenu(hwave,'label',strunpad(wnames(k,:)),...
'callback','waveleted(''switchwave'')','checked',checked);
% - sign to indicate a live wavelet
if( strcmp( checked,'on' ) )
hwmenu(k)=-hwmenu(k);
end
end
%
set(hwave,'userdata',hwmenu);
%make the msg window and the active wavelet window
sep=.005;
height=.03;
xnow=sep;ynow=1.0-height-sep;width=1.0-2*sep;
hactive=uicontrol('style','text','string','Active Wavelet: none',...
'units','normalized','position',[xnow,ynow,width,height]);
ynow=ynow-height-sep;
if( ~isempty(wlet) )
hmsg=uicontrol('style','text','string',...
'Click on a wavelet to activate it',...
'units','normalized','position',[xnow,ynow,width,height]);
else
hmsg=uicontrol('style','text','string',...
'Make a new wavelet or open a wavelet file',...
'units','normalized','position',[xnow,ynow,width,height]);
end
% save handles in user data of figure
set(hfig,'userdata',[haction, hnew, hchange, hxmit, hsave, hsaveascii,...
hsaveobject, hquit, hax1, hax2, hax3, hwave, ...
hactive, hmsg hdelete hzoom hunzoom hrename,...
hsavecurrent hsaveall hshowsave]);
%plot the active wavelets
waveleted('plot');
return;
end
if( strcmp(action,'quit') )
h=get(gcf,'userdata');
hxmit=h(4);
flag=get(hxmit,'enable');
if( strcmp(flag,'on') )
yes = questdlg('Transmit changes first?',...
'Exit confirmation',...
'Yes','No','Yes');
if yes
waveleted('quit2');
end
else
yes = questdlg('Are you sure you want to quit?',...
'Exit confirmation',...
'Yes','No','Yes');
if yes
waveleted('quit2');
end
end
return;
end
if(strcmp(action,'quit2'))
h=get(gcf,'userdata');
hxmit=h(4);
a=yesnofini;
if( a==-1 )
return;
end
flag=get(hxmit,'enable');
hfig=gcf;
if(a>0 & strcmp(flag,'on') )
waveleted('xmit');
elseif( a>0 )
waveleted('save');
end
saveWindowPosition(hfig,'waveleted','main');
close(hfig);
return;
end
if( strcmp(action,'plot') )
h=get(gcf,'userdata');
hsaveobject=h(7);
hquit=h(8);
hax1=h(9);
hax2=h(10);
hax3=h(11);
hwave=h(12);
hmsg=h(14);
% get the wavelets
wlet=get(hquit,'userdata');
if( isempty(wlet) )
return;
end
fmw=objget(wlet,'wavelets');
ws=fmget(fmw,'mat');
t=fmget(fmw,'y');
%generate some colors
nkol=6;
c=zeros(3,nkol);
c(1,:)=(nkol:-1:1)/nkol;%red
c(2,:)=[2:2:nkol nkol-2:-2:0]/nkol;%green
c(3,:)=(1:nkol)/nkol;%blue
%get the wavelet menu handles
hws=get(hwave,'userdata');
set(gcf,'currentaxes',hax1);
cla;
set(gcf,'currentaxes',hax2);
cla;
set(gcf,'currentaxes',hax3);
cla;
%loop over wavelets and plot as requested
for k=1:length(hws)
if(hws(k)<0)
%get the wavelet
wavelet=ws(:,k);
%get the live samples
ilive=find(~isnan(wavelet));
wavelet=wavelet(ilive);
tw=t(ilive);
%plot it in hax1
kcol=rem(k,nkol);
if(kcol==0) kcol=6; end
set(gcf,'currentaxes',hax1);
hwtime=line(tw,real(wavelet),'color',c(:,kcol)','userdata',abs(hws(k)),...
'buttondownfcn','waveleted(''activate'')');
%transform it
%wp=padpow2(wavelet);
%twp=xcoord(tw(1),tw(2)-tw(1),wp);
wp=wavelet;
twp=tw;
%adjust for time zero
izero=near(twp,0);
%make sure its close
if(abs(twp(izero))<twp(2)-twp(1))
wp=[wp(izero:length(wp));wp(1:izero-1)];
else
disp('***WARNING*** unable to find time zero, phase may be inaccurate')
end
[W,f]=fftrl(wp,twp);
% adjust for time zero
%phs_shift=exp(-i*2*pi*twp(1)*f);
%W=W.*phs_shift;
%to db & phs
W=todb(W);
%plot amp spectrum
set(gcf,'currentaxes',hax2);
hwamp=line(f,real(W),'color',c(:,kcol)','userdata',abs(hws(k)),...
'buttondownfcn','waveleted(''activate'')');
%set(hax2,'ylim',[-80 0]);
%plot phase spectrum
set(gcf,'currentaxes',hax3);
hwphs=line(f,180*imag(W)/pi,'color',c(:,kcol)','userdata',...
abs(hws(k)),'buttondownfcn','waveleted(''activate'')');
%store the curve handles in the menu userdata
set(abs(hws(k)),'userdata',[hwtime, hwamp, hwphs]);
if(k==1)
dt=tw(2)-tw(1);
set(hsaveobject,'userdata',dt);
end
end
end
set(hmsg,'string','Click on a wavelet to activate it');
return;
end
% turn wavelets on and off
if(strcmp(action,'switchwave'))
h=get(gcf,'userdata');
hwave=h(12);
hactive=h(13);
hchange=h(3);
hdelete=h(15);
hrename=h(18);
hws=get(hwave,'userdata');
hmenu=gcbo;
if(isempty(hmenu))
hmenu=currentMenu;
ind=find(abs(hws)==hmenu);
if(isempty(ind))
disp('faulty switch')
return;
end
end
ind=find(abs(hws)==hmenu);
if(isempty(ind))
hmenu=currentMenu;
ind=find(abs(hws)==hmenu);
if(isempty(ind))
disp('faulty switch')
return;
end
end
flag=get(hmenu,'checked');
if( strcmp(flag,'on') ) % turn it off
set(hmenu,'checked','off','userdata',[]);
ind=find(abs(hws)==hmenu);
hws(ind)=hmenu;
dat=get(hactive,'userdata');
if( ~isempty(dat) )
if(hmenu==dat)
set(hactive,'userdata',[],'string','Active Wavelet: none');
set(hchange,'enable','off');
set(hdelete,'enable','off');
set(hrename,'enable','off');
end
end
else %turn it on
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -