%% Spike spectrogram

display('To compute the spike spectrograms, press enter');
pause
%
% Preliminary parameter settings
%
params.Fs=1000; % inverse of the spacing of the grid onw hcih tapers are computed
params.fpass=[0 100]; % frequency range of interest
params.pad=2; % pad
params.tapers=[5 9]; % tapers
params.err=0; % no eror computation
params.trialave=1; % average over trials
%
% spectrogram of the first cell
%
data=dsp1t; % data from 1st cell
[S,t,f,R]=mtspecgrampt(data,movingwin,params); % compute spectrogram
%
% Plot the spectrogram
%
figure; 
subplot(211);
plot_matrix(S./repmat(R,[1 size(S,2)]),t,f);xlabel([]);caxis([-5 6]);colorbar; % plot spectrogram normalized by rate
set(gca,'FontName','Times New Roman','Fontsize', 14);
title({['Spectrogram normalized by the rate: Cell 1, W=' num2str(params.tapers(1)/movingwin(1)) 'Hz'];['moving window = ' num2str(movingwin(1)) 's, step = ' num2str(movingwin(2)) 's']});
ylabel('frequency Hz');
%
% spectrogram of second cell
data=dsp2t; % data from 2nd cell
[S,t,f,R]=mtspecgrampt(data,movingwin,params); % compute spectrogram
%
% Plot the spectrogram
%
subplot(212);
plot_matrix(S./repmat(R,[1 size(S,2)]),t,f);caxis([-5 6]);colorbar; % plot spectrogram normalized by rate
set(gca,'FontName','Times New Roman','Fontsize', 14);
title({['Spectrogram normalized by the rate: Cell 2, W=' num2str(params.tapers(1)/movingwin(1)) 'Hz'];['moving window = ' num2str(movingwin(1)) 's, step = ' num2str(movingwin(2)) 's']});
xlabel('time s'); ylabel('frequency Hz');
position_figure