% Compute epsilon for a hypothetical ground motion
%
% by Jack Baker, 2/1/05
% Stanford University
% bakerjw@stanford.edu
%
% This script demonstrates the calculation of epsilon for a ground motion,
% using the record's spectral acceleration value and an attenuation
% prediction. The information input below comes from the Chihuahua record
% of the Imperial Valley earthquake (record IMPVALL/H-CHI282) from the PEER
% ground motion library [http://peer.berkeley.edu/smcat/]


% input the parameters of the ground motion
period = 0.8;
magnitude = 6.5;
distance = 28.7;
is_soil = 1; 
fault_type = 0;
HW = 0;
arb = 1; %we are analyzing only a single component of the ground motion

% input the record's spectral acceleration value, in units of g
Sa_actual = 0.6296;

% attenuation prediction
[Sa_predicted, sigma_lnSa] = AS_1997_horiz(magnitude, distance, period, is_soil, fault_type, HW, arb)

% compute epsilon
epsilon = (log(Sa_actual) - log(Sa_predicted))/sigma_lnSa