clear all; close all; clc; restoredefaultpath;
mkdir(mfilename)

load('expt.mat','expt')
ncs = expt.ncs;
nxs = expt.nxs;
nsets = length(expt.sets);
ntaxels = expt.ntaxels;
pos = expt.disp.pos;

for iset = 1:nsets
    for ic = 1:expt.ncs
        
        fname = ['c' sprintf('%02d',ic) '_' expt.sets{iset}];
        load(fname,'store');
        dirs = {'x','y'}; ndirs = length(dirs);
        
        %% plot results
        figure; clf
        col = colormap(jet(ntaxels/2));
        nx0 = 15; % assumed duration per tap
        
        for idir = 1:ndirs
            subplot(ndirs,1,idir); hold on; box on; grid on
            for ix = 1:nxs
                for itaxel = 1:ntaxels/2
                    x = store{ix}(:, 2*(itaxel-1)+idir); nx = length(x);
                    t = (ix-1)*nx0 + (1:nx);
                    plot(t/nx0, x - pos(2*(itaxel-1)+idir), 'color', col(itaxel,:));
                end
            end
%             xlabel('sensor position', 'fontsize',8);
            ylabel([dirs{idir} '-deflection'], 'fontsize',7);
            set(gca,'xtick',linspace(0,nxs,11),'ytick',-20:10:20, 'fontsize',7)
            axis([0 nxs -10 10])
        end
        
        % export figure
        set(gcf, 'color', 'w', 'units', 'inches', 'position', [0 0 3.5 2.5])                       
    end
end
