% clear all
% close all
% 
% 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)
%     fprintf(1, 'reading file: %d  %s\n', i, fileStr(i,:))
%     data = load( char(file(i)) );
%     tension2(i,:) = data.tension2;
%     clear data;
% end

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

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

figure
bar(totalPeaks(1:5,1:4), 'grouped');
title('Number of Peaks > Tlimit (2011-run2: No Skirt No Cone)')
xlabel('1=2010 spectra/small buoy, 2=2010 spectra/big buoy, 3=mean99, 4=mean100, 5=median99')
for i=1:length(Tlimit)
    legendStr(i,:) = strcat(num2str(Tlimit(i)), ' lbf');
end
legend(legendStr);

figure
bar(totalPeaks(3:5,1:4), 'grouped');
title('Number of Peaks > Tlimit (2011-run2: No Skirt No Cone)')
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: Skirt & Cone)')
xlabel('More accurate buoy models 1=mean99, 2=mean100, 5 = median99')
for i=1:length(Tlimit)
    legendStr(i,:) = strcat(num2str(Tlimit(i)), ' lbf');
end
legend(legendStr);









