%
% Play with the error bar computation for the other LFP channels
%

display('We will now compute error bars of a specified kind for a chosen channel');
display('Press return to continue');
pause
%
% Declares default values just in case they have been deleted
%
params.Fs=1000; % inverse of the spacing of the grid onw hcih tapers are computed
params.fpass=[0 100]; % frequency range of interest
params.tapers=[5 9]; % tapers
params.err=0; % no eror computation
params.trialave=1; % average over trials


user_continues='y';
while strcmp(user_continues,'y')
  ch=input('Give me a channel between 1 and 4 ');
  if ~isempty(ch);
     if ch<1 || ch>4; ch=1;display('We have only 4 channels, using channel 1 '); end;
  else;
     ch=1;
     display('User has not specified channel, using channel 1');
  end;
  eval(['data=dlfp' num2str(ch) 't;']);
  delay_period=1001:2000;
  data=data(delay_period,:);
  errtype=input('Which type of error, type 1 for chi2 and 2 and Jackknife ');
  if isempty(errtype); errtype=1; display('User did not specify error type, using default, chi2 ');end;
  p=input('Give me a p value, e.g. 0.01 ');
  if isempty(p); p=0.05;display('User did not specify p value, using default 0.05'); end;
  params.err=[errtype p];
  [S,f,Serr]=mtspectrumc(data,params);
  figure
  plot_vector(S,f,[],Serr,'y');
  set(gca,'FontName','Times New Roman','Fontsize', 16);
  xlabel('frequency Hz'); ylabel('Spectrum dB');
  title('LFP spectrum for 1 trial over a restricted frequency range');
  position_figure
  user_continues=input('Do you want to continue to play ? Type y for Yes, and n for No ','s');
end