%
%   script to analyze the two accelerometers on the longboard.
%   WDL25 was on the front with channel 1 front, channel2 left, and
%   channel 3 up.
%   WDL26 was on the reak with channel 1 front, channel2 left, and
%   channel 3 up.
%
%
%   load the data
%
load exp16_25.txyz
load exp16_26.txyz
t25=exp16_25(:,1);
x25=exp16_25(:,2);
y25=exp16_25(:,3);
z25=exp16_25(:,4);
t26=exp16_26(:,1);
x26=exp16_26(:,2);
y26=exp16_26(:,3);
z26=exp16_26(:,4);
%
% measure the offset by eye and overlay plots of CH3
%
t0=t25(9142)-t26(1);
figure(1)
subplot(3,1,1);plot(t25,z25);xlabel('time(s)');ylabel('CH3');title('WDL25')
subplot(3,1,2);plot(t26,z26);xlabel('time(s)');ylabel('CH3');title('WDL26')
subplot(3,1,3);plot(t25-t0,z25,t26,z26);xlabel('time(s)');ylabel('CH3');title('WDL26')
axis([0,900,-10,30])
%
%  cut the matching segments of time series
%
t1=t25(9142+1:9142+28672)-t0;
x1=x25(9142+1:9142+28672);
y1=y25(9142+1:9142+28672);
z1=z25(9142+1:9142+28672);
t2=t26(1:28672);
x2=x26(1:28672);
y2=y26(1:28672);
z2=z26(1:28672);
%
% plot all three channels together
%
figure(2)
subplot(3,1,1);plot(t1,x1,t2,x2);xlabel('time(s)');ylabel('CH1')
subplot(3,1,2);plot(t1,y1,t2,y2);xlabel('time(s)');ylabel('CH2')
subplot(3,1,3);plot(t1,z1,t2,z2);xlabel('time(s)');ylabel('CH3')
%
%   plot the in phase and out of phase components
%
figure(3)
subplot(3,1,1);plot(t1,x1+x2,t1,x1-x2);xlabel('time(s)');ylabel('CH1')
subplot(3,1,2);plot(t1,y1+y2,t1,y1-y2);xlabel('time(s)');ylabel('CH2')
subplot(3,1,3);plot(t1,z1+z2,t1,z1-z2);xlabel('time(s)');ylabel('CH3')
%
%   lets look at the transfer function between the accelerometers
%
figure(4)
nfft=2048;
fs=32;
[pxx,f]=tfestimate(x1,x2,hanning(nfft),nfft/2,nfft,fs);
[cxx,f]=mscohere(x1,x2,hanning(nfft),nfft/2,nfft,fs);
subplot(3,1,1);plot(f,abs(pxx)),xlabel('frequency Hz');ylabel('trans - amp');title('CH1 along surfboard')
axis([0,10,-.1,1.2])
subplot(3,1,2);plot(f,angle(pxx)),xlabel('frequency Hz');ylabel('trans - phase')
axis([0,10,-pi,pi])
subplot(3,1,3);plot(f,cxx),xlabel('frequency Hz');ylabel('coherence')
axis([0,10,0.,1.])
figure(5)
nfft=2048;
fs=32;
[pyy,f]=tfestimate(y1,y2,hanning(nfft),nfft/2,nfft,fs);
[cyy,f]=mscohere(y1,y2,hanning(nfft),nfft/2,nfft,fs);
subplot(3,1,1);plot(f,abs(pyy)),xlabel('frequency Hz');ylabel('trans - amp');title('CH2 across surfboard')
axis([0,10,-.1,1.2])
subplot(3,1,2);plot(f,angle(pyy)),xlabel('frequency Hz');ylabel('trans - phase')
axis([0,10,-pi,pi])
subplot(3,1,3);plot(f,cyy),xlabel('frequency Hz');ylabel('coherence')
axis([0,10,0.,1.])
figure(6)
nfft=2048;
fs=32;
[pzz,f]=tfestimate(z1,z2,hanning(nfft),nfft/2,nfft,fs);
[czz,f]=mscohere(z1,z2,hanning(nfft),nfft/2,nfft,fs);
subplot(3,1,1);plot(f,abs(pzz)),xlabel('frequency Hz');ylabel('trans - amp');title('CH3 vertical')
axis([0,10,-.1,1.2])
subplot(3,1,2);plot(f,angle(pzz)),xlabel('frequency Hz');ylabel('trans - phase')
axis([0,10,-pi,pi])
subplot(3,1,3);plot(f,czz),xlabel('frequency Hz');ylabel('coherence')
axis([0,10,0.,1.])
