r_fft_net.m 1.24 KB
function r_fft_net(file)

rootdir  = '/MP_oceanographie/MP/images/netLogo2mat/5_fps';
cd(rootdir)
[data] = netlogo2mat(file);
  
floe_pos = detrend(data(:,18),'constant');
time     = data(:,9);

L1 = 200;                   % start of data
L2 = 550;                   % end of data

Fs   = 5;
%%
figure(1); clf
subplot(2,2,[1,2])
plot(time,floe_pos);
title('detrend')
xlabel('time')
ylabel('pos (m)')

%% Frequency spectrum
m    = length(floe_pos);
NFFT = pow2(nextpow2(m)); % Next power of 2 from length of y
Y    = fft(floe_pos,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])


figure(2); 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,floe_pos);
subplot(2,2,[1,2])
plot(time,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(3);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,floe_pos);
plot(time,fi,'r');

hold off

end