clear
close all

%define the input file names generated by splitFile.m
fileName = 'Aug12-2010-1442.56';
tensFileName = strcat(fileName, 'Tens.csv');
xBowFileName = strcat(fileName, 'xBow.csv');
iLinkFileName = strcat(fileName, 'iLink.csv');

%read the tension file
tensStruct = importdata(tensFileName, '\t');
tension = tensStruct.data(:,1);
tension(1:length(tension)-1);    
tensionNS = tension(30000:length(tension));
%deal with NaNs
tensNSNaNIndex = find(isnan(tensionNS));
tensionNS(tensNSNaNIndex) = tensionNS(tensNSNaNIndex-1);

clear tensStruct ;
%define the PSD arguments
Fs = 10.0;
windowName = 'Hamming';
segmentLength = 512;
overlapPercent = 50;
%calculate the PSD
tensNSHs = spectrum.welch(windowName, segmentLength, overlapPercent);
tensionNSPSD = psd(tensNSHs, tensionNS, 'Fs', Fs);

%read the buoy xBow file
xBowStruct = importdata(xBowFileName, '\t');
buoyAccZ = xBowStruct.data(:,9);
buoyZ = xBowStruct.data(:,15);

%deal with NaNs
buoyAccZNSNaNIndex = find(isnan(buoyAccZNS));
buoyAccZNS(buoyAccZNSNaNIndex) = buoyAccZNS(buoyAccZNSNaNIndex-1);
buoyZNSNaNIndex = find(isnan(buoyZNS));
buoyZNS(buoyZNSNaNIndex) = buoyZNS(buoyZNSNaNIndex-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);
buoyAccZNSPSD = psd(xBowHs, buoyAccZNS, 'Fs', Fs);
buoyZNSPSD = psd(xBowHs, buoyZNS, '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(tensionNS)
% title('Tension (lbf w/Skirt)');
% figure
% plot(tensionNSPSD)
% title('Tension PSD (w/Skirt)');
% figure
% plot(buoyAccZNSPSD)
% title('Buoy Z Acceleration PSD (w/Skirt)');
% figure
% plot(buoyZNSPSD)
% title('Buoy Z PSD (w/Skirt)');
% figure
% plot(ESPAccZPSD)
% title('ESP Z Acceleration PSD (w/Skirt)');

fclose('all');