protected void resample(double sample) {
        double[] wweights;
        double[][] newpweights;
        double initialWeight;
        double r, s;
        int j;

        wweights = prob(sample);
        initialWeight = 1.0 / particleCount;
        newpweights = new double[2][particleCount];
        for (int i = 0; i < particleCount; i++) {
            newpweights[0][i] = 0;
        }

        for (int i = 0; i < particleCount; i++) {
            r = Math.random();
            s = 0.0;
            j = 0;
            while (j < particleCount && s < r) {
                s += wweights[j];
                j++;
            }
            j--;
            newpweights[0][i] += wweights[j];
//            newpweights[1][i] = particles[1][j] + ((Math.random() * 60.0) - 30.0);
            //add some noise to the new sample
            newpweights[1][i] = particles[1][j] + (rnd.nextGaussian() * resampleVariance);

        }
        particles = newpweights;

    }