r_fft.m 2.73 KB
function r_fft(expNumber,camNumber,rowNumber)
% R_FFT - Produces figures to see where we have to fiter position data. 
%
% Syntax: 
%    r_fft(expNumber,camNumber,rowNumber)
%
% Inputs:
%    expNumber     - The experiment number
%    camNumber     - The camera number
%    rowNumber     - The row number
%
% Example:
%    r_fft(201307231730,1,1)
%
% Other m-files required: r_fil_data
% Subfunctions: none
% MAT-files required: figs_data_$fpsfps_$nbFf_ave_$exp_$cam_$row 
%                     (produced by R_DATA_POS)
% See also: R_DATA_POS
%
% Author: Marie-Pier Marquis, Dany Dumont
% UQAR/ISMER
% email: dany_dumont@uqar.ca
% Website: http://www.ismer.ca/dumont-dany
% July 2014 Last revision : October 2014
% ________________________________________________________________________
%%
nbF      = 80;
fps      = 5;
ave      = 2;       % 1 : mean 60+5*tpms to 60+15*tpms
                    % 2 : mean 75+5*tpms to 75+75*tpms
                    % 3 : mean 75+5*tpms to 75+30*tpms 
nbFStr   = num2str(nbF);
fpsStr   = num2str(fps);
aveStr   = num2str(ave);
cam      = num2str(camNumber);
exp      = num2str(expNumber);
row      = num2str(rowNumber);

rootdir  = ['/MP_oceanographie/MP/images/multicam_',nbFStr,'f'];
expdir   = [rootdir,'/',exp,'_multicam'];
resdir   = [expdir,'/',fpsStr,'fps_',nbFStr,'f_2_results_c'];
datafile = [resdir,'/figs_data_c_',fpsStr,'fps_',nbFStr,'f_',...
               aveStr,'_',exp,'_',cam,'_',row,'.mat'];
fftdir   = [rootdir,'/fft'];

cd(resdir)
load(datafile)

if ~exist(fftdir,'dir')
    mkdir(fftdir)
end
cd(fftdir)

%% detrend data
Fs   = 5;                   % Sampling frequency
L1 = 200;                   % start of data
L2 = 550;                   % end of data

y  = floeF(1,:)';                 
y1 =  r_fill_data( y );
z = detrend(y1(L1:L2),'constant');

figure(4); clf
subplot(2,2,[1,2])
plot(time(L1:L2),z);
title('detrend')
xlabel('time')
ylabel('pos (m)')

%% Frequency spectrum
m    = length(z);
NFFT = pow2(nextpow2(m)); % Next power of 2 from length of y
Y    = fft(z,NFFT)/m;
f0   = Fs/2*linspace(0,1,NFFT/2+1);

subplot(2,2,[3,4])
plot(f0,2*abs(Y(1:NFFT/2+1)))
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
title('{\bf 0-Centered}')
xlim([0 2.5])
%% filtered data



figure(5); clf
h = fdesign.lowpass('Fp,Fst,Ap,Ast',2*(1/0.95+0.1)/Fs,2*(1/0.95+0.2)/Fs,1,60);
d = design(h,'equiripple');
fi = filtfilt(d.Numerator,1,z);
subplot(2,2,[1,2])
plot(time(L1:L2),fi);
% xlim([0 250])
% ylim([-0.15 0.15])

%% New frequency spectrum
subplot(2,2,[3,4])
Z  = fft(fi,NFFT)/m;
plot(f0, 2*abs(Z(1:NFFT/2+1)));
xlim([0 2.5])




figure(6);clf
subplot(2,2,[1,2])
hold on
plot(f0, 2*abs(Z(1:NFFT/2+1)),'r');
plot(f0,2*abs(Y(1:NFFT/2+1)))
xlim([0 2.5])
hold off
subplot(2,2,[3,4])
hold on
plot(time(L1:L2),z);
plot(time(L1:L2),fi,'r');

hold off



end