Single trial spectrograms

61 views
Skip to first unread message

Munaza Ramzan

unread,
Jul 16, 2019, 4:22:55 AM7/16/19
to analyzingneura...@googlegroups.com
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

Mike X Cohen

unread,
Jul 16, 2019, 7:42:50 AM7/16/19
to analyzingneura...@googlegroups.com
Hi Munaza. Perhaps you can be a bit more specific about what is causing your confusion. Regardless, single-trial dB normalization is generally not a good idea, as the results can be unstable. 

Mike



--
You received this message because you are subscribed to the Google Groups "AnalyzingNeuralTimeSeriesData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzingneuraltimes...@googlegroups.com.
Visit this group at https://groups.google.com/group/analyzingneuraltimeseriesdata.
To view this discussion on the web visit https://groups.google.com/d/msgid/analyzingneuraltimeseriesdata/CADMDcdwCMbF_gbQ6RXwgJObcSdPnk81e_qEFPxB1CMfHfJNFoA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Mike X Cohen, PhD
Fresh look: mikexcohen.com

Munaza Ramzan

unread,
Jul 16, 2019, 8:52:34 AM7/16/19
to analyzingneura...@googlegroups.com
Thank you sir for your reply.

Axtually I want to analyze the brain dynamics for different types of emotions and all the 40 trials(40 different movies clips of 1min)are different (eg.  Trial1:sad, trial2: entertairnment.....). I am confused in how to take an average over all different trials. If so, then how wud i differentiate these different trials  tend to interpret different emotions. 

Please suggest me. 

Munaza Ramzan

unread,
Jul 17, 2019, 10:47:47 AM7/17/19
to analyzingneura...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages