clc %emol
clearvars %emol
close all %emol

load impact_data_raw
% experiment performed 10 times, each signal recorded for 8s (emol)
% input signals: in1,...,in10; output signals: out1,...,out10 (emol)

fs=256; % anti-aliasing filter applied, cut-off frequency of 100 Hz (emol)
N=length(in1); 
f=fs*(0:N-1)/N;
T=N/fs; 
t=0:1/fs:T-1/fs; 

In1=fft(in1); 
Out1=fft(out1);
H=Out1./In1;

figure(1)
subplot(2,2,1) %emol
plot(f(41:761),20*log10(abs(H(41:761))))
axis([5 95 -30 50])
xlabel('Frequency (Hz)'); ylabel('FRF (Modulus, dB)')
grid on %emol
subplot(2,2,2) %emol
plot(f(41:761),unwrap(angle(H(41:761))))
axis([5 95 -3.5 3.5])
xlabel('Frequency (Hz)'); ylabel('FRF (Phase, rad)')
grid on %emol

% load impact_data_pre_processed
% 
% In1=fft(in1); 
% Out1=fft(out1);
% H=Out1./In1;
% 
% subplot(2,2,3) %emol
% plot(f(41:761),20*log10(abs(H(41:761))))
% axis([5 95 -30 50])
% xlabel('Frequency (Hz)'); ylabel('FRF (Modulus, dB)')
% grid on %emol
% subplot(2,2,4) %emol
% plot(f(41:761), unwrap(angle(H(41:761))))
% axis([5 95 -3.5 3.5])
% xlabel('Frequency (Hz)'); ylabel('FRF (Phase, rad)')
% grid on %emol
% 
% % --> Preprocessed data produce a much cleaner FRF.