
clear 
close all

% Define a Gaussian probability density function and draw samples from it

s=.5;  % in s this is for the hypocentre location problem

% Define interval and discrete space
t=-5:.01:5;

c1=1; c2=3;
t1=-1.5; t2=1.3;
s1=.3; s2=.8;

% Calculate pdf
gauss=1./(sqrt(2*pi)*s)*exp(-.5/s^2*t.^2) +   ...
      c1/(sqrt(2*pi)*s1)*exp(-.5/s1^2*(t-t1).^2) + ...
      c2/(sqrt(2*pi)*s2)*exp(-.5/s2^2*(t-t2).^2)

n=10000;
for i=1:n, 
    sample(i)=draw_from_pdf(t,gauss);
end

% check std
s_est=std(sample);

subplot(211), hist(sample,100), axis([-2 2 -Inf Inf])
title(' Histrogram from drawn samples ')
ylabel(' Frequency ' )
xlabel(' Time error (s) ')
subplot(212), plot(t,gauss), axis([-2 2 -Inf Inf])
title(' Gauss pdf ')
ylabel(' Probability ' )
xlabel(' Time error (s) ')