function [s] = spec(a, xi, dt, T)
%-------------------------------------------------------------
% spec(a, xi, dt, T)
% PURPOSE
%  Compute seismic response spectra for elastic design.
%
% INPUT:
%    a : acceleration time history at 
%        equal time step dim(a)= ntimes x 1
%    xi: damping ratio, dim(xi)= 1 x 1
%    dt: time step dim(dt)= 1 x 1
%    f : frequency vector, dim(f)= nfreq x 1
%
% OUTPUT:
%    s : complex response matrix 
%        dim(Y)= m x nw, m : number of dof's
%-------------------------------------------------------------

% LAST MODIFIED: H Carlsson 1993-09-21   
% Copyright (c)  Division of Structural Mechanics and
%                Department of Solid Mechanics.
%                Lund Institute of Technology
%-------------------------------------------------------------

test0 = find(T == 0);

if (isempty(test0) ~= 1)
    T(test0) = ones(length(test0), 1);
    
end

f = 1 ./ T;

[np nr]=size(f);

for (i = 1:np)
    r=sqrt(1-xi*xi);
    w=2*pi*f(i);
    wt=w*dt;
    e=exp(-xi*wt);
    c1=2*e*cos(r*wt);
    c2=e*e;
    c3=e/r/wt*sin(r*wt);
    c4=[-c3 2*c3 -c3];
    c5=[1 -c1 c2];
    y=filter(c4,c5,a);
    s(i)=max(abs(y+a));
end  


if (isempty(test0) ~= 1)
    s(test0) = max(abs(a)) .* ones(test0, 1);
    
end


s = s';

%--------------------------end--------------------------------
