%% spike spectra, error bars

display('To compute the spectrum of the spiking activity, press return');
pause
%
% Compute spectrum for the 1st cell
%
data=dsp1t; % data from 1st cell
delay_times=[1 2]; % start and end time of delay
data=extractdatapt(data,delay_times,1); % extracts spikes within delay period
params.Fs=1000; % inverse of the spacing between points on the grid used for computing slepian functions
params.fpass=[0 100]; % range of frequencies of interest
params.tapers=[10 19]; % tapers
params.trialave=1; % average over trials

p=0.05; % p value for errors
params.err=[1 p]; % chi2 errors
[S,f,R,Serr]=mtspectrumpt(data,params);
%
% Plot spectrum and rate
%
figure;
subplot(211);
plot_vector(S,f,[],Serr,'y');line(get(gca,'xlim'),[10*log10(R) 10*log10(R)],'Color','r');
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel('frequency Hz'); ylabel('Spectrum dB');
title(['Spectrum for Cell 1 with \chi_{2\nu} error bars W=' num2str(params.tapers(1)) 'Hz']);
position_figure
%
% Compute spectrum for the 2nd cell
%
data=dsp2t;
data=extractdatapt(data,delay_times,1);
params.err=[1 0.05];
params.fpass=[0 500];
[S,f,R,Serr]=mtspectrumpt(data,params);
%
% Plot spectrum
subplot(212);
plot_vector(S,f,[],Serr,'y');line(get(gca,'xlim'),[10*log10(R) 10*log10(R)],'Color','r');
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel('frequency Hz'); ylabel('Spectrum dB');
title(['Spectrum for Cell 2 with \chi_{2\nu} error bars W=' num2str(params.tapers(1)) 'Hz']);
position_figure
