clear
close all

%define the input file names generated by splitFile.m
fileName = 'Aug12-2010-1405.09';
tensFileName = strcat(fileName, 'Tens.csv');
xBowFileName = strcat(fileName, 'xBow.csv');
iLinkFileName = strcat(fileName, 'iLink.csv');

%read the tension file
tensStruct = importdata(tensFileName, '\t');
tensionWS = tensStruct.data(:,1);
tensionWS = tensionWS(1:length(tensionWS)-1);    
%deal with NaNs
tensNaNIndex = find(isnan(tensionWS));
tensionWS(tensNaNIndex) = tensionWS(tensNaNIndex-1);

clear tensStruct ;
%define the PSD arguments
Fs = 10.0;
windowName = 'Hamming';
segmentLength = 512;
overlapPercent = 50;
%calculate the PSD
tensHs = spectrum.welch(windowName, segmentLength, overlapPercent);
tensionWSPSD = psd(tensHs, tensionWS, 'Fs', Fs);

%read the buoy xBow file
xBowStruct = importdata(xBowFileName, '\t');
buoyAccZ = xBowStruct.data(:,9);
buoyZ = xBowStruct.data(:,15);

%deal with NaNs
buoyAccZNaNIndex = find(isnan(buoyAccZ));
buoyAccZ(buoyAccZNaNIndex) = buoyAccZ(buoyAccZNaNIndex-1);
buoyZNaNIndex = find(isnan(buoyZ));
buoyZ(buoyZNaNIndex) = buoyZ(buoyZNaNIndex-1);

clear xBowStruct
%define the PSD arguments
Fs = 10.0;
windowName = 'Hamming';
segmentLength = 512;
overlapPercent = 50;
%calculate the spectrums
xBowHs = spectrum.welch(windowName, segmentLength, overlapPercent);
buoyAccZPSD = psd(xBowHs, buoyAccZ, 'Fs', Fs);
buoyZPSD = psd(xBowHs, buoyZ, 'Fs', Fs);

%read the iLink file
iLinkStruct = importdata(iLinkFileName, '\t');
ESPAccZ = iLinkStruct.data(:,3);
%deal with NaNs
iLinkNaNIndex = find(isnan(ESPAccZ));
ESPAccZ(iLinkNaNIndex) = ESPAccZ(iLinkNaNIndex-1);

clear iLinkStruct ;
%define the PSD arguments
Fs = 10.0;
windowName = 'Hamming';
segmentLength = 512;
overlapPercent = 50;
%calculate the PSD
ESPAccZHs = spectrum.welch(windowName, segmentLength, overlapPercent);
ESPAccZPSD = psd(ESPAccZHs, ESPAccZ, 'Fs', Fs);

% plot(tensionWS)
% title('Tension (lbf w/Skirt)');
% figure
% plot(tensionWSPSD)
% title('Tension PSD (w/Skirt)');
% figure
% plot(buoyAccZPSD)
% title('Buoy Z Acceleration PSD (w/Skirt)');
% figure
% plot(buoyZPSD)
% title('Buoy Z PSD (w/Skirt)');
% figure
% plot(ESPAccZPSD)
% title('ESP Z Acceleration PSD (w/Skirt)');

fclose('all');