function [T, yc] = TM_EPOS(pickinfo,event_wfm,continuousfile,nwin,npre,fmin,fmax, ... min_dist,min_cor) % Check for integers if(floor(nwin) ~= nwin); error('nwin is not an integer'); end if(floor(npre) ~= npre); error('npre is not an integer'); end if(floor(min_dist) ~= min_dist); error('min_dist is not an integer'); end % Check frequencies if(fmin>fmax); error('fmin > fmax'); end %% Parameters definition (example) % % Filenames % pickinfo = 'picks.xml'; % Picking files % event_wfm= 'VN.TBVB..HHE.300000.SAC'; % Event waveform % continuousfile= 'VN.TBVB..HHE.620000.SAC'; % Continuous waveform % % % Set Template window parameters % nwin = 512; % Total number of samples in the template window % npre = 50; % Number of points before the arrival time % % % Set filter parameters % fmin = 1; % Minimum frequency % fmax = 15; % Maximum frequency % % % Set parameters for declaring a detection % min_dist = 200; % Minimum required distance (in samples) between 2 detections % min_cor = 0.7; % Correlation threshold for declaring a detection (optional) % Get the P-wave pick info [tp,sta,ntwk,channel]=read_xml(pickinfo); % Read the continuous sac file Fc=readsac(continuousfile); if(Fc.tau==-1); error('The continuous sac file does not exist'); end % And we will filter it. fs = round(1./Fc.delta) ; fn = fs/2; [b,a] = butter(4,[fmin fmax]./fn); yc = Fc.trace - mean(Fc.trace); yc = filtfilt(b,a,yc); % Read the event trace file Fe=readsac(event_wfm); if(Fe.tau==-1); error('The event sac file does not exist'); end % Check if the two waveforms correspond to the same station, channel, and % have the same sampling frequency if(Fe.delta ~= Fc.delta); error('Sampling frequencies are not the same'); end if(Fe.kcmpnm ~= Fc.kcmpnm); error('Components are not the same'); end if(Fe.kstnm ~= Fc.kstnm); error('Stations are not the same'); end % Check if picks correspond to the supplied waveform event file if(strcmp(Fe.kstnm,sta)) if(strcmp(Fe.kcmpnm,channel)) if(strcmp(Fe.knetwk,ntwk)) [mo,day]=jd2md(Fe.nzjday,Fe.nzyear); t0 = datenum(Fe.nzyear,mo,day,Fe.nzhour,Fe.nzmin,Fe.sec); t1 = t0 + (Fe.npts*Fe.delta)/(24*3600); % Check if the picking time is within the event waveform % file. It should be the case but just to be sure. if( (tp > t0) && (tp < t1)) % Extract the template waveform window y=mk_template(Fe.trace,fmin,fmax,tp,t0,1./Fe.delta,nwin,npre); % Compute the correlation R=compute_correlation(yc,y); % Find detections T= find_events(R,min_dist,min_cor); else error('Picking time not within the event waveform duration') end else error('Not the same Network') end else error('Not the same Channel') end else error('Not the same station') end