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;

% first topic: measured signals (emol)
figure(1)
subplot(1,2,1) %emol
plot(t,in1); 
axis([-0.1 8 -1.5 2.5])
xlabel('\itt\rm (seconds)'); ylabel('\itx\rm(\itt\rm)')
grid on %emol
subplot(1,2,2)
plot(t,out1)
axis([-0.1 8 -4 4])
xlabel('\itt\rm (seconds)'); ylabel('\ity\rm(\itt\rm)')
grid on %emol
% --> offset and noise in input signal
% --> truncated output signal

% % second topic: effect of noise on input signal (emol)
% In1=fft(in1);
% figure(2); 
% plot(f(1:N/2+1),20*log10(abs(In1(1:N/2+1))))
% axis([0 128 -70 30])
% xlabel('Frequency (Hz)'); ylabel('Modulus (dB)')
% grid on %emol

% % third topic: pre-processing of input signal (emol)
% % (noise region replaced with constant values; compensation of offset;
% %  each signal preprocessed individually and differently)
% figure(3)
%   % original signal (emol)
% subplot(1,2,1) %emol
% plot(in1(1:50))
% axis([0 50 -3 3]) %emol
% xlabel('Index(n)'); ylabel('x(n)') %emol
% grid on
%   % replacement of noise (emol)
% in1(1:4)=in1(20);
% in1(20:end)=in1(20);
%   % compensation of offset (emol)
% in1=in1-in1(20);
%   % adjustment of output signal (emol)
% out1(1:4)=0;
%   % pre-processed signal
% subplot(1,2,2) %emol
% plot(in1(1:50))
% axis([0 50 -3 3]) %emol
% xlabel('Index(n)'); ylabel('x(n)') %emol
% grid on

% % fourth topic: spectrum of pre-processed input signal (emol)
% In1=fft(in1);
% figure(4) %emol
% plot(f(1:N/2+1), 20*log10(abs(In1(1:N/2+1))))
% axis([0 128 -70 30])
% xlabel('Frequency (Hz)'); ylabel('Modulus (dB)')
% grid on %emol