How to re-sample particle filter's particles for a 1D door/wall problem So assuming your implementation of the motion model and sensor model is at a somewhat satisfying level, the question then is how do I stabilize localization with the re-sampling step. 
I'm currently dealing with the robot walking down a hallway with 3 doors, and rest wall using a door/wall classifier sensor.
Only when it reaches a door, do the importance weight indicate some good confidence of its location, however as soon as the robot walks past the door it's gone. I then thought it might be because my re-samples only focuses on removing low weight particles and replacing randomly, rather than replacing them randomly but closer to high weight particles.
The particle filter algorithm follows this sort of approach (after randomizing particles during initialization)
1. for particle i to M
2.     x of particle i = x of particle i + velocity + random noise
3.     w of particle i = p_door(x)(sensed_door) + p_wall(x)(sensed_wall)
4. normalize all w

The original implementation for the resampling I ended up thinking made sense but now believe is completely off(because it's too random) was
1. find max w
2. for particle i to M
3.      if w of particle i  < max*0.8
4.             replace particle i with new particle at random position

So I was wondering what is a common way, or a somewhat ideal way to tackle this problem. Current ideas that come to mind are
 1. Getting the top three particles out of N, then randomly replacing new particles around each of the three particles.
 2. Getting the max weight particle, and threshold at 80% of it's importance weight value, then placing new particles around those that surpass the that threshold.
Is this in the right direction for tackling a 1D particle filter problem or am I off?
 A: Cliffs: (depending on the meaning of 'at random position' in the resampling algorithm), the resampling algorithm proposed in the question loses information contained in the measurements $y_1,\ldots,y_k$. Instead, the resampled values should be selected from the existing values, using for example multinomial resampling.
Background
This looks like essentially the bootstrap particle filter by Gordon et al., 1993 [1], that is, for $k=1,\ldots$, the particles $x_k$ and weights $w_k$ form an approximation to the distribution of $x_k$ conditional on all measurements. I assume we have $M$ particles. First, the particles are set to some values $x_0^{(i)}$, for $i=1,\ldots,M$ and the weights are set to $w^{(i)} = 1/M$. Then, for each measurement $k$, 


*

*For $i = 1,2,...,M$:


*

*Draw $x^{(i)}_k$   from dynamic model $p(x^{(i)}_k \mid x^{(i)}_{k-1})$

*Weight based on dynamic model weights: $w^{(i)}_k = w^{(i)}_{k-1}\,p(y_k \mid x^{(i)}_k)$


*Normalize weights to sum to $1$.

*Possibly resampling: replace the current particles $x^{(1,2,...,M)}_k$ and weights $w^{(1,2,...,M)}_k$ by the result of the resampling algorithm


(The dynamic model and measurement model are not completely clear from the question, but the scope of the question is the resampling step anyway, so I assume there is some dynamic and measurement model, at least implicitly).
Resampling
The purpose of the resampling step is to obtain a new approximation to the filtering distribution, such that the degeneracy problem where one particle gets all weight, is prevented.
The problem with the proposed resampling algorithm is that if the new values of the particle are selected 'randomly' with some arbitrary distribution, they do not take into account the measurements obtained so far. And thus do not form a good approximation to the filtering distribution.
Instead, typically in the resampling step, the particles are selected from the existing particles. The simplest idea, used in [1], is the so-called multinomial resampling:
Input: old particles $x^{(1)}_k,x^{(2)}_k,...,x^{(M)}_k$
Output: new particles $\tilde{x}^{(1)}_k,\tilde{x}^{(2)}_k,...,\tilde{x}^{(M)}_k$.
For $i = 1,..., M$:


*

*Sample a random integer $J_i$ randomly with probabilities $w^{(1)},w^{(2)},...,w^{(M)}$

*Set $\tilde{x}_i := x_{J_i}$ (i.e., select the particle from old particles using the weights as probabilities)

*Set $\tilde{w}^{(i)}_k := 1/M$
Various other resampling schemes exist, see, e.g., [2].
References
[1] Gordon, N. J., Salmond, D. J., & Smith, A. F. (1993, April). Novel approach to nonlinear/non-Gaussian Bayesian state estimation. In IEE Proceedings F (Radar and Signal Processing) (Vol. 140, No. 2, pp. 107-113). IET Digital Library.
[2] Douc, Randal, and Olivier Cappé. "Comparison of resampling schemes for particle filtering." Image and Signal Processing and Analysis, 2005. ISPA 2005. Proceedings of the 4th International Symposium on. IEEE, 2005.
A: Using a low variance sampling algorithm can improve the performance of the particle filter (both in computational complexity and accuracy). Instead of sampling from a multinomial distribution for each particle, you sample from a uniform distribution once and "stride" through your weighted samples. The technique is called "low variance" because the shape of the resulting distribution varies less from the shape of the distribution you are sampling from. Here is the alorithm:
function [X] = lowVarianceRS(X0, weight, M)
    X = zeros(1,M)                  % Initialize empty set of particles
    r = rand(0, M^-1)               % Select random number between 0-M^-1
    w = weight(1)                   % Initial weight
    i = 1 
    j = 1 

    for m = 1:M
        U = r + (m - 1)/M           % Index of original sample + size^-1
        while U > w                 
            i = i + 1 
            w = w + weight(i) 
        end
        X(j) = X0(i)                % Add selected sample to resampled array
        j = j + 1 
    end
end

Where M is the number of particles in your filter. See Section 4.3.4 of [1] for more details.
References
[1] Thrun, S., Burgard, W., Fox, D. Probabalistic Robotics. 2006 Massachussetts Institute of Technology.
