function [rho] = baker_correlation(T1, T2, opp);

% Created by Jack Baker, 2/2/05
% Compute the correlation of epsilons at two different periods. The
% correlation can be for epsilons in the same axis, or perpendicular axes.
%
% The function is strictly empirical, and should not be extrapolated beyond
% the range 0.05s <= T1, T2 <= 5s
%
% Documentation of this model is provided in the following:
%
% Baker J.W. and Cornell C.A. (2006). "Correlation of Response Spectral Values 
% for Multi-Component Ground Motions," Bulletin of the Seismological Society of 
% America, 96 (1), 215-227. 
%
%
% INPUT
%
%   T1, T2      = The two periods of interest. The periods may be equal,
%                 and there is no limit on one being larger than the other.
%   opp         = 0 for correlation in the same axis (default)
%               = 1 for correlation on perpendicular axes
%
% OUTPUT
%
%   rho         = The predicted correlation coefficient

    
    T_min = min(T1, T2);
    T_max = max(T1, T2);    
    
    X = 1 - log(T_max/T_min)*(0.32 - 0.133*exp( -(log(T_max)+1.51)^2 -5*(log(T_min)+2.59)^2));
    D = 9 - log(T_max/T_min^4);
    rho = max([X, X-0.17*D, 0.15]);
    
    if nargin < 3 opp=0; end
    if opp == 1
        reduction = 0.78* sqrt( (1-0.05*log(T1)) * (1-0.05*log(T2)));
        rho = rho * reduction;
    end