% Sample of how to load project test data and compute auto and cross
% spectra using psdest.
%
% M.S. Allen, Fall 2020

clear all; close all

[data,dinfo]=loaduff;

for k=1:length(data); leg_txt{k}=data{k}.d1; end
for k=1:length(data); x(k,:)=data{k}.measData; end
ts=data{1}.x;

%% PSD Estimation
[Gyy, ws] = psdest(x.',[14],ts.',2^14,'hanning',0.5,'rs');

figure(1); 
plot(ts,x); legend(leg_txt)
xlabel('time (s)')

figure(2);
subplot(2,1,1)
semilogy(ws/2/pi,abs(Gyy(:,:,1)));
grid on; legend(leg_txt);
title('Y as Reference')
subplot(2,1,2)
semilogy(ws/2/pi,abs(Gyy(:,:,2)));
grid on; title('Z as Reference'); xlabel('\bfFrequency (Hz)')
sdaxsetb([0,25]);