function nv = analyze(nt,nv);

%order of operations:
% 1. load hr file
% 2. resample hr
% 3. run analysis:
%    a. FFT
%    b. EMD
%    c. SPWV
%    d. STFT

plots = 3;
if(nargin < 2)
    [fn pn]  = uigetfile('*.rrd', 'Select rr interval file');
    [rrt rr] = textread([pn fn], '%f %f');
    [nt,nv] = hrtach(0, rr, ones(size(rr)),fs);
    l = 2^floor(log(length(rr))/log(2));
    nt = nt(1:l);
    nv = nv(1:l);
else 
    fs = 1/(nt(2)-nt(1));
end

l = length(nv);

figure(gcf);
subplot(plots,1,1);
plot(nt, nv);
title('Heart rate');
xlabel('T');
ylabel('Rate (bpm)');
nv = nv(1:l) - mean(nv(1:l));

%figure(gcf+1);
subplot(plots,1,2);
myfft(nv,fs);


%figure(gcf+1);
subplot(plots,1,3);
myemd(nv,fs);

close(figure(gcf+1));