function [ spec, Ffc, t ] = time_evolv_spectra_part( data, Fs, Nwind)
%time_evolv_spectra: esimate time-evolution of spectra of data
%   Uses sliding window and Matlab psd (welch) to esimate power spectra of
%   *data*
%   INPUTS:     data    (vector of time series data)
%               Fs      sample rate associated with data (in cycles/s)
%               Nwind   the length for the sliding window
%
%   OUTPUTS:    spec    a 2 index matrix giving psd as function of freq
%                       and time
%               Ffc     vector of frequencies for psd (Fourier)estimates
%               t       time associated with each sliding window analyzed

% *** NOTE: this doesn't work as is, you'll need to fix it up (and
% 'translate' into python if need be. DL ***

% (place for things like N, length of data, # of windows (steps) in data,
% a dummy time array for estimating central time of each sliding window
% later
N = length(data)
% *** a bit fancier, I'll overlap sliding windows, an arbitrary choices
Novwin = round(0.50 * Nwind)
% given that I've hard set an overlap above (50%), you'll need to calculate
% the number of windows you'll process in the for loop

dt = 1/Fs;
tt = 0:dt:(N-1)*dt;

% *** could pre-estimate Ffcs with one call of psd ***
% *** if using the "spectrum.*" model, generate h for a welch spectrum
h = spectrum.welch('tukey',Nwind);
Hpsd = psd(h,data(1:Nwind),'Fs',Fs);
Ffc = Hpsd.Frequencies;

% *** Hpsd is something called a 'structure' containing lots of different
% data, this is how we get the Frequencies out of the structure ***

% *** start a for loop stepping through data with sliding window
ns = 1;
spec = zeros(length(Ffc),Nslide);
for i=1:Nslide
    % *** determine data chunk for this sliding window, need pointer to end
    % of window
    
    % *** what if last window exceeds the length of the time series?
    if (nend > N), nend = N;, end
    
    ldata = nend-ns+1;  % length of this data window
    % use pointers to define window of time series for FFTing
%   above sets up something to pass to our FFT builtin ('psd'), with
%   padding (zeros) if need be for last window

    % *** estimate central time for this window, populate t, location of
    % center times for spectral estimates.  Develop next element in time
    % array for plotting
    navg = round((ns + nend)/2);
    t(i) = tt(navg);
    
    % *** estimate psd for this data chunk
    % you'll need to do this....
    
    % *** load psd into spec, note it is in a Matlab 'structure' 
    spec(:,i) = Hpsd.Data;
    
    % *** update ns for next go-round 
    
end

% *** could optionally do some sort of fancy plot here, but perhaps better
% to do this in the calling routine?


end

