function [t, YPrimePrime, YPrime, Yout]= format_data

[time, yDotDot]= hip_walk; %time, acc

T = time(2)-time(1);         % Sample time
Fs = 1/T;                    % Sampling frequency

time= time- time(1); %zero the time
yDotDot= [yDotDot;yDotDot(1)]; % Makes the signal periodic
time= [time; time(end)+T];

L = length(yDotDot); % Length of signal (# intervals)
Lp=nextpow2(L);
L=2^Lp;         % WHEN WE USE FFT IT IS A LAW TO USE SIGNALS HAVING LENGTH THAT IS A POWER OF 2 - OTHERWISE EVERYTHING WILL BE WRONG!

time1 = linspace(0,time(end),L);
yDotDot1=interp1(time,yDotDot,time1); % make the periodic signal exactly of length 2^p

time=time1';
yDotDot=yDotDot1';

%get FFT using method shown on MATLAB website
t = time(1:2^Lp);            % Time vector            
y = yDotDot(1:2^Lp);         % Sinusoids plus noise

NFFT = 2^nextpow2(L); % Next power of 2 from length of yDotDot
Y = fft(y,NFFT)/L; %column vector. Complex numbers
f = (Fs/2*linspace(0,1,NFFT/2+1)); %row vector of frequencies for plotting single-sided amplitude spectrum
allFreq= ([-fliplr(f) f(2:length(f)-1)])'; %vector of frequencies in FFT


%determine velocity and displacement
b= fftshift(Y);
w= 2.*pi.*allFreq;

%set w=0 component to w= 1.
zeroIndex= round(length(w)/2)+1;
w(zeroIndex)= 1;

%set corresponding amplitude to 0.
Nf= 5; %May choose to zero out additional low-frequency components by setting Nf to a larger integer.
b(zeroIndex-Nf:zeroIndex+Nf)= 0; % filter +-Nf points close to DC - these are SLOW timescales (2*pi/f(Nf))
['We filter periods larger than ',num2str(2*pi/f(Nf))]
c = b./(1i.*w);
d = -b./(w.^2);

Yr=ifftshift(b);
Yv=ifftshift(c);
Yd=ifftshift(d);

YPrimePrime= ifft(ifftshift(b*L), NFFT);
YPrime = ifft(ifftshift(c*L), NFFT);
Yout= ifft(ifftshift(d*L), NFFT);    


figure(1);
subplot(3,2,5)
hold on
plot(t, YPrimePrime(1:length(t)), 'k');
title('Acceleration versus time')
grid;
xlabel('time (sec)');
ylabel('acceleration (m/s^2)');

figure(1);
subplot(3,2,3)
hold on
plot(t, YPrime(1:length(t)), 'k');
title('Velocity versus time')
grid;
xlabel('time (sec)');
ylabel('velocity (m/s)');


figure(1);
subplot(3,2,1)
plot(t, Yout(1:length(t)), 'k');
title('Displacement versus time')
grid;
xlabel('time (sec)');
ylabel('displacement (m)');

% %get FFT. 
accAmp= 2*abs(Yr(1:NFFT/2+1)); %acc amplitude
velocAmp= 2*abs(Yv(1:NFFT/2+1)); %veloc amplitude
dispAmp= 2*abs(Yd(1:NFFT/2+1)); %acc amplitude
w= 2.*pi.*f';


P_ave_time= sum(abs(YPrime).^2).*t(2)/t(length(t))
Ptot_spectrum= sum(abs(Yv).^2)
Ptot_spectrum2= 2*sum(abs(Yv(1:NFFT/2+1)).^2)


[maxValue, maxIndex]= max(abs(Yv));
domFreq= f(maxIndex)
P_domFreq= maxValue.^2
ratio= P_domFreq/Ptot_spectrum

Ptot= Ptot_spectrum; %sum(accAmp(2:length(accAmp)).^2./w(2:length(w)));%total power
%add to index ca until have reached 90% Ptot
ca= 1;
Ptemp= 0;
while (Ptemp<.99*Ptot)
    Ptemp= Ptemp+ 2*abs(Yv(ca))^2;
    ca= ca+1;
end


figure(1);
subplot(3,2,2) %plot FFT of displacement
hold on;
plot(f(Nf+1:ca),dispAmp(Nf+1:ca), 'ok', 'LineWidth',.5);
xlabel('frequency (Hz)');
ylabel('displacement (m)');
title('FFT of Displacement');
xlim([0 20])

subplot(3,2,4) %plot FFT of velocity
hold on
plot(f(Nf+1:ca),velocAmp(Nf+1:ca), 'ok', 'LineWidth',.5);
xlabel('frequency (Hz)');
ylabel('velocity (m/s)');
title('FFT of Velocity');
xlim([0 20])

figure(1);
subplot(3,2,6) %plot FFT of acceleration
hold on;
plot(f(Nf+1:ca),accAmp(Nf+1:ca), 'ok', 'LineWidth',.5);
xlabel('frequency (Hz)');
ylabel('acceleration (m/s^2)');
title('FFT of Acceleration');
xlim([0 20])

end
