clear all
close all

sampleRate = 100;        %samples / second
Tdistance = 1 * sampleRate;
Tlimit = [3000 4000 5000 6000];

fileStr(1,:) = '2011 - run2\Results_ESPdrifter_2010_2010wave.sim.mat';
fileStr(2,:) = '2011 - run2\Results_ESPdrifter_2011_2010wave.sim.mat';
fileStr(3,:) = '2011 - run2\Results_ESPdrifter_2011_mean99.sim.mat  ';
fileStr(4,:) = '2011 - run2\Results_ESPdrifter_2011_mean100.sim.mat ';
fileStr(5,:) = '2011 - run2\Results_ESPdrifter_2011_median99.sim.mat';

fileStr(6,:) = 'THIRD_set\Results_ESPdrifter_2011_mean99.sim.mat    ';
fileStr(7,:) = 'THIRD_set\Results_ESPdrifter_2011_mean100.sim.mat   ';
fileStr(8,:) = 'THIRD_set\Results_ESPdrifter_2011_median99.sim.mat  ';
file = cellstr(fileStr);

for i = 1:length(file)
    for j = 1:length(Tlimit)
        fprintf(1, 'file: %s   Tension limit: %d\n', fileStr(i,:), Tlimit(j) )
        clear pks locs data;
        data = load( char(file(i)) );
        [pks, locs] = findpeaks(data.tension2, 'minpeakheight', Tlimit(j), 'minpeakdistance', Tdistance);
        
        onlyPeaks(i,j,:) = zeros(1, length(data.tension2));
        for k = 1:length(locs)
            onlyPeaks(i,j,locs(k)) = pks(k);
        end
        totalPeaks(i,j) = length(pks);
    end
end

bar(totalPeaks(1:5,1:4), 'grouped');
title('Number of Peaks > Tlimit (2011-run2)')
xlabel('1=mean99, 2=mean100, 3=median99')
for i=1:length(Tlimit)
    legendStr(i,:) = strcat(num2str(Tlimit(i)), ' lbf');
end
legend(legendStr);

figure
bar(totalPeaks(6:8,1:4), 'grouped');
title('Number of Peaks > Tlimit (THIRD set)')
xlabel('1=2010 buoy, 2=2011 buoy, 3=mean99, 4=mean100, 5 = median99')
for i=1:length(Tlimit)
    legendStr(i,:) = strcat(num2str(Tlimit(i)), ' lbf');
end
legend(legendStr);









