clear;
chaos1=csvread('walk_CSA1.txt');
sa=csvread('walk_sa.txt');
chaos2=csvread('walk_CSA2.txt');
chaos3=csvread('walk_CSA3.txt');

res_chaos1=csvread('result_CSA1.txt');
res_sa=csvread('result_sa.txt');
res_chaos2=csvread('result_CSA2.txt');
res_chaos3=csvread('result_CSA3.txt');

max_result_chaos1 = max(res_chaos1)
max_result_chaos2 = max(res_chaos2)
max_result_sa = max(res_sa)
max_result_chaos3 = max(res_chaos3)


num_steps = 400;

%find a value of n that is the closest power of 2 to the number of samples
n = pow2(nextpow2(num_steps)); 

% calculate the fft of the x component
sa_fft = fft(res_sa,n)/num_steps;
chaos1_fft = fft(res_chaos1,n)/num_steps;
chaos2_fft = fft(res_chaos2,n)/num_steps;
chaos3_fft = fft(res_chaos3,n)/num_steps;
% determine the sampling frequency
fs = 1;
% generate the frequecy vector, where each step is the sampling frequency
f = (0:n-1)*(fs/n);
% calculate the power spectrum (in dB)
sa_power = 10*log10((abs(sa_fft).^2));
chaos1_power = 10*log10((abs(chaos1_fft).^2));
chaos2_power = 10*log10((abs(chaos2_fft).^2));
chaos3_power = 10*log10((abs(chaos3_fft).^2));
% calculate the amplitude spectrum
%amplitude = 2*abs(sa_fft);
% calculate the phase of the spectrum
%phase = angle(sa_fft);

% plot the amplitude, phase, and power
%figure;
%plot(f, amplitude)
%figure;
%plot(f, phase)
%figure;
%plot(f, power)
%figure;
%this is the log-log plot of the power
log_sa_power = sa_power(1:256)/10;
log_chaos1_power = chaos1_power(1:256)/10;
log_chaos2_power = chaos2_power(1:256)/10;
log_chaos3_power = chaos3_power(1:256)/10;
log_f = log10(f(1:256));

%plot(log10(f(1:256)), sa_power(1:256)/10)
%figure;
%plot(log10(f(1:256)), chaos1_power(1:256)/10)
%figure;
%plot(log10(f(1:256)), chaos2_power(1:256)/10)
%figure;
%plot(log10(f(1:256)), new_chaos_power(1:256)/10)
