function density=KernelDensityEstimate(x,particles,weights,kernelstd)
%function to calculate a Kernel approximation for given samples and weights
%-inputs
%%%-x : Values to evaluate the kernel approximated density function
%%%-particles : array holding the samples from the density of size 1 x N. 
%%%-weights : array holsing the weights for the samples of size 1 x N
%%%-kernelstd : standard deviation for the kernel function
%-outputs
%%%-density : kernel approximated density evaluated at points x.

N=length(weights);%number of samples 
density=zeros(size(x));%initiate the kernel approximated density
for i=1:N,%for all samples
    density=density+weights(i)*normpdf(x-particles(i),0,kernelstd);%add the corresponding kernel approximation
end



