function PlotType1(PDC,COH,S,signif,ep_times,freq,E,channels,tit)

% Plot the different epochs in separate windows. Each window has the
% spectra in the diagonal subplots and the PDC in the offdiagonal. The
% significance level and COH (optionally) are also plotted.

CohOrNot = input('Do you want to include a plot of the ordinary coherence? Y / N: ', 's'); % choose whether to include COH
for ep=1:E                                                                  % For each epoch...
    figure                                                                  % open a new figure
    z=1;
    for r=1:channels                                                        % For each combination...
        for c=1:channels                                                    % of data pairs...
            if r==c                                                         % If they are the same array...
                sp = log10(abs(squeeze(S{ep}(r,c,:))));                     % calculate its power spectrum (magnitude)...
                subplot(channels,channels,z)                                % and plot it in the diagonal...
                plot(freq,sp,'k')                                           % in semilogarithmic plot
                xlim([min(freq) max(freq)]);
                xlabel('Frequency (Hz)');
                ylabel([tit,'Spectrum']);
                title(['Electr.', num2str(r), '   Time(sec):', ...
                    num2str(ep_times(ep)), '  >  ', num2str(ep_times(ep+1))]);
            else                                                            % If they are different arrays...
                pdc = squeeze(PDC{ep}(r,c,:));                              % keep the PDC for all frequencies in one vector
                sig = squeeze(signif{ep}(r,c,:));                           % same for the significance
                subplot(channels,channels,z)
                area(freq,pdc,'FaceColor',[0 1 1])                          % and plot PDC as shaded area.
                hold on
                plot(freq,sig,'-- k','LineWidth',1.7)
                if isempty(CohOrNot) || CohOrNot=='Y' || CohOrNot=='y'      % If the user chose to include coherence
                    coh = squeeze(abs(COH{ep}(r,c,:)));                     % keep the coherence for all frequencies
                    hold on
                    plot(freq,coh,'k','LineWidth',1.7)                      % and plot it as thick line.
                end
                axis([min(freq) max(freq) 0 1.2]);
                xlabel('Frequency (Hz)');
                ylabel([tit, 'PDC']);
                title(['Electr.', num2str(c), '  >  Electr. ', num2str(r), ...
                    '   Time(sec):',num2str(ep_times(ep)), '  ->  ', num2str(ep_times(ep+1))]);
            end
            z=z+1;
        end
    end
    %M(ep) = getframe(gcf);
end
hold off
%clf
%axes('Position',[0 0 1 1])
%movie(M,1,1);
%movie2avi(M,'PDCmovie','fps',1,'quality',100);