Home > . > makeh.m

makeh

PURPOSE ^

MAKEH - generates metric perturbation for GW source

SYNOPSIS ^

function hij = makeh(simId, ampl, startSamp, sampFreq)

DESCRIPTION ^

 MAKEH - generates metric perturbation for GW source

 hij = makeh(simID, ampl, startSamp, sampFreq);

 simId         string containing signal information
 ampl          fixed signal amplitude
 startSamp     start time of (in samples) of signal; mostly interested in 
               fractional part to properly line up signal samples with data 
               samples
 sampFreq      sampling frequency

 hij           metric perturbation

 Currently supported signals are:
       Gaussians                         'G'
       sine-Gaussians                    'SG'
       cosine-Gaussian                   'CG' 
       BH ringdowns                      'BH'
       sine                              'SIN'
       cosine                            'COS'
       sinc                              'SINC'
       linear chirp                      'CHIRP'
       square wave                       'SQUARE'
       Gaussian modulate square wave     'SQUAREG'
       sawtooth wave                     'SAWTOOTH'
       Gaussian modulated sawtooth wave  'SAWTOOTHG'

 SEE ALSO: GRAVEN, SIMPARSE

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function hij = makeh(simId, ampl, startSamp, sampFreq)
0002 
0003 % MAKEH - generates metric perturbation for GW source
0004 %
0005 % hij = makeh(simID, ampl, startSamp, sampFreq);
0006 %
0007 % simId         string containing signal information
0008 % ampl          fixed signal amplitude
0009 % startSamp     start time of (in samples) of signal; mostly interested in
0010 %               fractional part to properly line up signal samples with data
0011 %               samples
0012 % sampFreq      sampling frequency
0013 %
0014 % hij           metric perturbation
0015 %
0016 % Currently supported signals are:
0017 %       Gaussians                         'G'
0018 %       sine-Gaussians                    'SG'
0019 %       cosine-Gaussian                   'CG'
0020 %       BH ringdowns                      'BH'
0021 %       sine                              'SIN'
0022 %       cosine                            'COS'
0023 %       sinc                              'SINC'
0024 %       linear chirp                      'CHIRP'
0025 %       square wave                       'SQUARE'
0026 %       Gaussian modulate square wave     'SQUAREG'
0027 %       sawtooth wave                     'SAWTOOTH'
0028 %       Gaussian modulated sawtooth wave  'SAWTOOTHG'
0029 %
0030 % SEE ALSO: GRAVEN, SIMPARSE
0031 
0032 % $Id: makeh.m,v 1.23 2004/05/17 21:21:01 stuver Exp $
0033 
0034 hij = [];
0035 
0036 % GET signal information from simId
0037 % CHECK for errors
0038 % GENERATE time vector
0039 
0040 % Make simId all upper case for ease in using strcmp
0041 simId = upper(simId);
0042 % Get signal information from simId
0043 [id, f0, tau, durationSec] = simparse(simId);
0044 
0045 % Check that simparse did not return an empty value
0046 if isempty(id) | isempty(f0) | isempty(tau) | isempty(durationSec)
0047     [id, f0, tau, durationSec]
0048     error('makeh: simparse returned an empty value')
0049 end
0050 
0051 % Check that sampFreq is > 0
0052 if sampFreq <= 0 | ~isreal(sampFreq) | isnan(sampFreq) | isinf(sampFreq)
0053     sampFreq
0054     error('makeh: sampFreq must the > 0, real and finite')
0055 end
0056 
0057 % Check that durationSec is > 0
0058 if durationSec <= 0 | ~isreal(durationSec) | isnan(durationSec) ...
0059         | isinf(durationSec)
0060     durationSec
0061     error('makeh: durationSec must be > 0, real and finite')
0062 end
0063 
0064 % Deterimine length of time vector in samples (floor trucated)
0065 durationSamp = floor(durationSec*sampFreq);
0066 % Check that durationSamp is not < 1
0067 if durationSamp < 1
0068     durationSamp
0069     error('makeh: durationSamp is < 1')
0070 end
0071 % Time vector = times at which IFO samples waveform
0072 ti = ((1:durationSamp)./sampFreq)+((1-mod(startSamp,1))/sampFreq);
0073 % N.B. This accounts for intersample start times
0074 
0075 % Check to make sure ti is not empty
0076 if isempty(ti)
0077     ti
0078     error('makeh: ti is empty')
0079 end
0080 
0081 % GENERATE needed base functions
0082 
0083 % The logical(sum(strcmp(id, {...}))) makes it so that if any one the
0084 % strings match id, then the appropriate base is generated
0085 if sum(strcmp(id, {'G', 'SG', 'CG', 'SQUAREG', 'SAWTOOTHG'})) > 0
0086     % A gaussian base needs to be generated
0087     
0088     % Check that tau is > 0
0089     if tau <= 0 | ~isreal(tau) | isnan(tau) | isinf(tau)
0090         tau
0091         error('makeh: tau must be > 0, real, and finite for Gaussians')
0092     end
0093     
0094     % Generate the Gaussian waveform that is also the base for SG and CG
0095     % Offset times for Gaussians
0096     tg = ti-(ti(end)/2);
0097     % Generate Gaussian
0098     gauss = exp(-(tg/tau).^2); 
0099 end
0100 
0101 if sum(strcmp(id, {'SIN', 'SG'})) > 0
0102     % A sine wave base needs to be generated
0103     
0104     % Check that f >= 0 for periodic function
0105     checkperiodic(f0);
0106     
0107     sine = ampl.*sin(2*pi*f0*ti);
0108 end
0109 
0110 if sum(strcmp(id, {'COS', 'CG'})) > 0
0111     % Check that f >= 0 for periodic function
0112     checkperiodic(f0);
0113 
0114     % A cosine wave base needs to be generated
0115     cosine = ampl.*cos(2*pi*f0*ti);
0116 end
0117 
0118 if sum(strcmp(id, {'SQUARE', 'SQUAREG'})) > 0
0119     % Check that f >= 0 for periodic function
0120     checkperiodic(f0);
0121 
0122     % A square wave base needs to be generated
0123     squ = ampl*square(2*pi*f0*ti);
0124 end
0125 
0126 if sum(strcmp(id, {'SAWTOOTH', 'SAWTOOTHG'})) > 0
0127     % Check that f >= 0 for periodic function
0128     checkperiodic(f0);
0129 
0130     % A sawtooth wave base needs to be generated
0131     saw = ampl*sawtooth(2*pi*f0*ti);
0132 end
0133 
0134 % GENERATE desired metric perturbation based on simId
0135 % RETURN appropriate timeseries
0136 
0137 switch id
0138     case 'G'
0139         hij = make33time(gauss);
0140     case 'SIN'
0141         hij = make33time(sine);
0142     case 'SG'
0143         hij = make33time(sine.*gauss);
0144     case 'COS'
0145         hij = make33time(cosine);
0146     case 'CG'
0147         hij = make33time(cosine.*gauss);
0148     case 'SINC'
0149         func = ampl*sinc(2*pi*f0*ti);
0150         hij = make33time(func);
0151     case 'CHIRP'
0152         % Generate a chirp signal that goes from 0 to f0 frequency
0153         func = ampl*chirp(ti, 0, ti(end), f0);
0154         hij = make33time(func);
0155     case 'SAWTOOTH'
0156         hij = make33time(saw);
0157     case 'SAWTOOTHG'
0158         hij = make33time(saw.*gauss);
0159     case 'SQUARE'
0160         hij = make33time(squ);
0161     case 'SQUAREG'
0162         hij = make33time(squ.*gauss);
0163     otherwise
0164         if strcmp(id, 'BH')
0165             % Construct damped, periodic source for BH ringdown
0166             % hij = ampl*exp(-t/tau)*[sin, cos, 0; cos, sin, 0; 0, 0, 0]
0167             
0168             % GENERATE periodic part of metric perturbation in 3x3xtime
0169             % array format
0170             % MAKE BH ringdown
0171             
0172             % Initialize metric perturbation
0173             hij = zeros(3, 3, length(ti));
0174             
0175             % Generate vector of zeros in time dimension for use in
0176             % constructing the metric perturbation
0177             oh = zeros(1, 1, length(ti));
0178             % Generate vector of the sine function in the time dimension for
0179             % use in constructing the metric perturbation
0180             xx = reshape(sin(2*pi*f0*ti), [1, 1, length(ti)]);
0181             % Generate vector of the cosine function in the time dimension
0182             % for use in constructing the metric perturbation
0183             xy = reshape(cos(2*pi*f0*ti), [1, 1, length(ti)]);
0184             
0185             % Assemble the part of the metric perturbation that deals with
0186             % periodic functions
0187             periodic = [xx, xy, oh; xy, xx, oh; oh, oh, oh]; 
0188             % This is in full 3x3xtime array format
0189             
0190             % Multiply each time step of the periodic portion of the metric
0191             % of the coresponding time step of the exponential and the
0192             % amplitude
0193             for k = 1:length(ti)
0194                 hij(:,:,k) = (ampl*exp(-ti(k)/tau)).*periodic(:,:,k);
0195             end
0196             
0197         else    
0198             id
0199             error(['makeh: Code currently only supports simId=''G'''...
0200                     ', ''SG'', ''CG'', ''BH'', ''SIN'', ''COS'','...
0201                     ' ''SINC'', ''SQUARE'', ''SQUAREG'', ''SAWTOOTHG'','...
0202                     ' ''SAWTOOTH'' & ''CHIRP'''])
0203         end
0204 end
0205 
0206 return
0207 
0208 % ~~~ END MAIN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0209 
0210 function checkperiodic(f0)
0211 
0212 % CHECKPERIODIC - check the frequency of a periodic function for errors
0213 %
0214 % checkperiodic(f0)
0215 %
0216 % f0    if f0 is < 0, imaginary, NaN or Inf, the program errors out
0217 
0218 % Check that F0 is > 0, real, and finite
0219 if f0 < 0 | ~isreal(f0) | isnan(f0) | isinf(f0)
0220     f0
0221     error(['makeh: f0 must be positive, real and finite for periodic ' ...
0222             'functions'])
0223 end
0224 
0225 return
0226 
0227 % ~~~ END CHECKPERIODIC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0228 
0229 function hij = make33time(func)
0230 
0231 % MAKE33TIME - put a timeseries vector into a 3x3xtime array
0232 %
0233 % hij = make33time(func)
0234 %
0235 % func  function timeseries to be copied into the 3x3xtime array
0236 %
0237 % hij   3x3xtime array
0238 
0239 % Put in full 3x3xtime array format
0240 hij = repmat(reshape(func, [1, 1, length(func)]), [3, 3, 1]);
0241 % reshape puts the elements of the func vector in the time dimension
0242 %   of the 3x3xtime array
0243 % repmat replicates the time dimension in the 3x3xtime array
0244 
0245 return

Generated on Tue 05-Oct-2004 10:40:50 by m2html © 2003