Hello Sir Mike,
I want to plot time-freq plots (spectrograms) of single trials for each channel (32 chans and 40 different trials, total of 1280 plots for each channel with each trial). I am trying to plot it but a bit confused. Below is the code which I have used from your Lecture series:
min_freq=0.5;
max_freq=40;
num_freq=50;
freq=linspace(min_freq,max_freq,num_freq);
chan2use='FP1';
range_cycles=[8 20];
s= logspace(log10(range_cycles(1)),log10(range_cycles(end)),num_freq)./(2*pi*freq);
wavetime=-2:1/EEG.srate:2;
half_wave=(length(wavetime)-1)/2;
tic; %HOW LONG IMPLEMENTATION IN MATLAB
nwave=length(wavetime);
nData=EEG.pnts; %NO OF POIVNTS IN FFT=NO OF DATA POINTS IN EEG BECAUSE WE ARE GOING TO DO CONVOLUTION SEPARETLY FOR EACH CHANNEL.
nconv=nwave + nData - 1;
tf=zeros(length(freq),EEG.pnts,EEG.trials);%initialize time-freq matrix which stores the data of trials
for fi=1:length(freq)%FOR ALL FREQUENCIES...
wavelet=exp(2*1i*pi*freq(fi).*wavetime) .* exp(-wavetime.^2./(2*s(fi)^2));
waveletX=fft(wavelet,nconv);
waveletX=waveletX./max(waveletX); %NORMALIZE
for triali=1:EEG.trials %loop over trials
dataX=fft(squeeze(EEG.data(strcmpi(chan2use,{EEG.chanlocs.labels}),:,triali)),nconv); %dataX is freq spectrum of data
as=ifft(waveletX .* dataX);
as=as(half_wave+1:end-half_wave);%as means analytic signal
tf(fi,:,triali) = abs(as).^2; %compute power
%{
figure
contourf(EEG.times,freq,squeeze(tf(:,:,triali)),'linecolor','none')
set(gca,'clim',[0 3], 'ydir','normal','xlim',[0 8000])
xlabel('time(ms)')
ylabel('Frequency (Hz)')
%}
end
end
Please correct me and how I do the db for each plot.
--
Thanks & Regards
Munaza Ramzan