r_data_pos.m 4.22 KB
function [StdHs, dyHs] = r_data_pos(expNumber,camNumber,rowNumber,nbF,...
                                   StdHs,dyHs,hs,tp,rowCounter)
% R_DATA_POS - Produces data for r_figs_pos and r_figs_summary_pos.
%
% Syntax:  r_data_pos
%
% Inputs: 
%     expNumber    - experiment number
%     camNumber    - camera number
%     rowNumber    - row number
%     nbF          - number of floes (40 or 80)
%     dyHs         - array (5x10x16) of mean displacement for each 
%                    experiment and row
%     StdHs        - array (5x10x16)
%     hs           - wave heigth
%     tp           - wave period
%     rowCounter   - row count
%
% Outputs:
%
% Example:
%    r_data_pos
%
% Other m-files required: R_CREATE_FLOE, R_FILL_DATE, R_CHOOSE_HT
%                         Image Processus Toolbox
% Subfunctions: none
% MAT-files required: data_$expNumber_$camNumber.mat (produced by R_RECON)
%                     list1.mat (To update before using this function)
%
% See also: R_DATA_POS_ALL, R_RECON, R_LIST, R_FIGS_POS, R_FIGS_SUMMARY_POS, 
%           R_INFO
%
% Author: Marie-Pier Marquis, Dany Dumont
% UQAR/ISMER
% email: dany_dumont@uqar.ca
% Website: http://www.ismer.ca/dumont-dany
% July 2014, Last revision: January 2015
% ________________________________________________________________________
%% Open files

nbFStr  = num2str(nbF);
cam     = num2str(camNumber);
exp     = num2str(expNumber);
row     = num2str(rowNumber);
tpms    = tp./10;

rootdir   = r_root(nbF);
listfile2 = [rootdir, '/info.mat'];
load(listfile2)

fps        = info.fps;
int1       = info.int1;
int2       = info.int2;
int3       = info.int3;
int4       = info.int4;
ave        = info.average;
data       = info.data;
res        = info.result;
figsdata   = info.figsData;
createFloe = info.createFloes;
fpsStr     = num2str(fps);
aveStr     = num2str(ave);

expdir     = [rootdir,'/',exp,'_multicam'];
datafile   = [expdir,'/',data,exp,'_',cam,'_',row,'.mat'];
resdir     = [expdir,'/',fpsStr,'fps_',nbFStr,'f_',aveStr,res];
cd(expdir)

if ~exist(resdir,'dir')
    mkdir(resdir)
end
load(datafile)
%% Sort data by position along the y-axis
nFrames  = size(xpos,1);
nObjects = size(xpos,2);

% Use r_create_floe or r_createFloeCircle
if createFloe == 1
    [floe] = r_create_floe(nFrames,nObjects,xpos,ypos,c,a,s,camNumber);
elseif createFloe == 2
    [floe] = r_createFloeCircle(nFrames,nObjects,xpos,ypos,camNumber);
end

% Initialization
floePos = nan.*ones(nObjects,size(ypos,1));
floeD   = nan.*ones(nObjects,nFrames);  % detrend data
floeF   = nan.*ones(nObjects,nFrames);  % filtered data

% Filter parameters as a function of the wave period
%h = fdesign.lowpass('Fp,Fst,Ap,Ast',2*((1/tpms)+0.1)/fps,...
%                      2*((1/tpms)+0.2)/fps,1,60);
%d = design(h,'equiripple');

% Filtering data
for k = 1:nObjects
    floePos(k,:) = r_fill_data(floe(k,:,2));
    floeD(k,:)   = detrend(floePos(k,:),'constant');
    floeF(k,:)   = floeD(k,:);
    %floeF(k,:)   = filtfilt(d.Numerator,1,floeD(k,:));
    floeF(k,:)   = floePos(k,:);
end

% Mean displacement of floes in the wave propagation direction.
% Retrieve the mean start position of all floes by averaging over the
% first 10 seconds (from 40 to 50s).

iPos    = nan.*ones(nObjects,1);
fPos    = nan.*ones(nObjects,1);
iStdPos = nan.*ones(nObjects,1);
fStdPos = nan.*ones(nObjects,1);

for k = 1:nObjects
    iPos(k)    = nanmean(squeeze(floeF(k,time < 50)));
    iStdPos(k) = nanstd(squeeze(floeF(k,time < 50)));
    fPos(k)    = nanmean(squeeze(floeF(k,time >=...
        (int1 + int3.*tpms) & time <= (int2+int4.*tpms))));
    fStdPos(k) = nanstd(squeeze(floeF(k,time >=...
        (int1 + int3.*tpms) & time <= (int2+int4.*tpms))));
end

delta      = fPos - iPos;
meanDisp   = nanmean(delta);
meanStdSummary = nanstd(delta);
deltaStd   = (iStdPos)+ (fStdPos);
meanStd    = mean(deltaStd);

%% Saving data for each experiment and each row

disp(' Saving data ... ');
save([resdir,figsdata,fpsStr,'fps_',nbFStr,'f_',aveStr,'_',exp,'_',...
    cam,'_',row],'floeF','delta','deltaStd','meanDisp','meanStd',...
    'iStdPos','fStdPos','iPos','fPos','nObjects','time','nFrames','-v7.3');

%% Sort data by wave height, wave period and main displacement

[h,t] = r_choose_ht(hs,tp);

StdHs(h,t,rowCounter) = meanStdSummary;
dyHs(h,t,rowCounter)  = meanDisp;


end