% EXEC - plate
% Description:  demonstration program, revealing principle of Ibrahim
%               time domain algorithm
% 
% Author:       Matus Jakus
% Year:         2016
% =========================================================================
% Program is part of appendix to master's thesis Creation and Application 
% of Algorithms for Estimating Modal Parameters in Time Domain and 
% Sensitivity to the Boundary Condition Study

clc; clear all; close all;

%% 5DOF - loading displacement data
% 
% cropping signal
n_s = 10535;          % first value
n_e = n_s + 6000;

% row A
[x1a, t] = readSignal(n_s, n_e, 'signals\5DOF_3DL\A\beam001_data1.txt');
[x2a, t] = readSignal(n_s, n_e, 'signals\5DOF_3DL\A\beam001_data2.txt');
[x3a, t] = readSignal(n_s, n_e, 'signals\5DOF_3DL\A\beam001_data3.txt');
[x4a, t] = readSignal(n_s, n_e, 'signals\5DOF_3DL\A\beam001_data4.txt');
[x5a, t] = readSignal(n_s, n_e, 'signals\5DOF_3DL\A\beam001_data5.txt');

% row B
[x1b, t] = readSignal(n_s, n_e, 'signals\5DOF_3DL\B\beam001_data1.txt');
[x2b, t] = readSignal(n_s, n_e, 'signals\5DOF_3DL\B\beam001_data2.txt');
[x3b, t] = readSignal(n_s, n_e, 'signals\5DOF_3DL\B\beam001_data3.txt');
[x4b, t] = readSignal(n_s, n_e, 'signals\5DOF_3DL\B\beam001_data4.txt');
[x5b, t] = readSignal(n_s, n_e, 'signals\5DOF_3DL\B\beam001_data5.txt');

% trajectory matrix
Xa = [x1a'; x2a'; x3a'; x4a'; x5a'];
Xb = [x1b'; x2b'; x3b'; x4b'; x5b'];

%% function ITD
% outputs:  MS - Modal shape matrix
%           D - f_r matrix
% inputs:   T - sampling period of signal
%           X - trajectory matrix from n-channel sensor
%           N - amount of loaded samples
%           d - delta (shift in ITD)

T = 5e-4;
N = 2000;
d = 2;
[MS_A, D_A] = ITD( Xa, N, d);
[MS_B, D_B] = ITD( Xb, N, d);

% natural frequency
sizeX = size(Xa);

for i = 1:sizeX(1,1)
    f_A(1, i) = 1/(d*T) * sqrt(log(D_A(i*2-1, i*2-1)) * log(D_A(i*2, i*2))) / (2*pi);
    f_B(1, i) = 1/(d*T) * sqrt(log(D_B(i*2-1, i*2-1)) * log(D_B(i*2, i*2))) / (2*pi);
end
f_A = fliplr(f_A);
f_B = fliplr(f_B);

%% plot
myPlot