% EXEC
% 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 = 820;          % first value
n_e = n_s + 4000;

[x1, t] = readSignal(n_s, n_e, 'signals\5DOF\beam001_data1.txt');
[x2, t] = readSignal(n_s, n_e, 'signals\5DOF\beam001_data2.txt');
[x3, t] = readSignal(n_s, n_e, 'signals\5DOF\beam001_data3.txt');
[x4, t] = readSignal(n_s, n_e, 'signals\5DOF\beam001_data4.txt');
[x5, t] = readSignal(n_s, n_e, 'signals\5DOF\beam001_data5.txt');

% trajectory matrix
X = [x1'; x2'; x3'; x4'; x5'];

%% example of data (plot)
%myData

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

T = 5e-4;   % T - sampling period
N = 100;
d = 5;
[MS, D] = ITD(X, N, d);

% natural frequency calculation
sizeX = size(X);
for i = 1:sizeX(1,1)
    f(1, i) = 1/(d*T) * sqrt(log(D(i*2-1, i*2-1)) * log(D(i*2, i*2))) / (2*pi);
end
f = fliplr(f);

%% plot results
myPlot