%synthetic seismogram for homogeneous string, u(t)
%calculated by normal mode summation
%string length
alngth=1.0;
%velocity m/sec
c=1.0;
%number modes
nmode=200;
%source position
xsrc=0.2;
%receiver position
xrcvr=0.7;
%seismogram time duration
tdurat=1.25;
%number time steps
nstep=100;
%time step
dt=tdurat/nstep;
%source shape term
tau=0.02;
fprintf('%s\n','synthetic seismogram for string')
fprintf('%s %0.5g\n','number modes', nmode)
fprintf('%s %0.5g %0.5g\n','length and velocity', alngth, c)
fprintf('%s %0.5g %0.5g\n','posn src and rcvr',xsrc,xrcvr)
fprintf('%s %0.5g %0.5g %0.5g\n','durn, time steps, del t',tdurat,nstep,dt)
fprintf('%s %0.5g\n','source shape', tau)
%initialize displacement
for cnt=1:nstep
    u(cnt)=0;
end
for k=1:nstep
    t(k)=dt*(k-1);
end
%outer loop over modes
for n=1:nmode
    anpial=n*pi/alngth;
%space terms - src & rcvr
    sxs=sin(anpial*xsrc);
    sxr=sin(anpial*xrcvr);
%mode freq
    wn=n*pi*c/alngth;
%time indep terms
    dmp=(tau*wn)^2;
    scale=exp(-dmp/4);
    space=sxs*sxr*scale;
%inner loop oner time  steps
    for k=1:nstep
%        t=dt*(k-1);
%        cwt=cos(wn*t);
        cwt=cos(wn*t(k));
%compute disp
        u(k)=u(k)+cwt*space;
    end
end
plot(t,u)
