function simpleBS(method,resetFigs)

if nargin < 2
    resetFigs = true;
end

if resetFigs
    close all
end

nStep = 250;
model = 'stocVolatility';
a = .9;
b = .1;
sigma = .75;

[x,y] = createData(nStep,a,b,sigma);

% Number of particles
N = 2^17;
% Stratum weights
W = ones(N,nStep);
% Draw the first sample
xs = randn(N,1)-3;

% Arrays for collecting data over time
X = zeros(N,nStep);
Xpost = zeros(N,nStep);
MU = zeros(1,nStep);

% Show progress bar for the impatient user
hwb = waitbar(0,'Running alphaSMC...');

% Main loop
for i = 1:nStep
    
    % Evaluate the likelihoods
    g = likelihood(model,xs,y(i),b);
    g = g / sum(g);
    
    % Resample
    inds = multinomialResample(N,g);
    Xpost(:,i) = xs(inds(:));
    % Mutate
    xs = transitionSample(model,xs(inds(:)),[a,sigma]);
        
    % Store particle history
    X(:,i) = xs(:);    
    MU(i) = mean(X(:,i));
    
    waitbar(i/nStep,hwb);
%     if i == 205
%         keyboard
%     end
end
close(hwb);

% keyboard
% ------------------------------------------------------------------------
% Visualization

figure
hold on
for i = 1:nStep
    plot(i*ones(N,1),X(:,i),'.','markersize',1);
end
plot(1:nStep,x,'k-');
plot(1:nStep,y,'rx');
hold off
set(gcf,'windowStyle','docked');
title(['Samples and signal (' method ')'])
xlabel('time');
ylabel('State space');

% Create histogram
Ngd = 150;
histLim = 10;
gd = linspace(-histLim,histLim,Ngd);
H = zeros(Ngd,nStep);
for i = 1:nStep
    htmp = hist(Xpost(:,i),gd);
    H(:,i) = htmp(:) / sum(htmp);
end

figure
imagesc(1:nStep,gd,H);
set(gca,'ydir','normal');
hold on
plot(1:nStep,x,'k-');
plot(1:nStep,MU,'m-');
plot(1:nStep,y,'rx');
plot(1:nStep,y,'ro');
set(gcf,'windowStyle','docked');
title(['Histogram and signal (' method ')'])
xlabel('time');
ylabel('State space');

