<div dir="ltr"><div class="gmail_default" style="font-family:times new roman,serif">Dear Arno,<br></div><div class="gmail_quote"><div dir="ltr"><div dir="ltr"><div style="font-family:"times new roman",serif"><br></div><div style="font-family:"times new roman",serif">I tried adapting your code for my dataset. However, I would prefer to first detect the SOs (similar to setting the parameters in the GUI provided by the detectevent plugin for sleep spindles) on each EEG dataset and then run PSD analyses. The reason for doing so is because we plan to conduct some exploratory analyses on the frequency and density of SOs and spindles within the N2 and N3 sleep stages as well so it would be better if first I detect the SOs in the dataset along with their duration and negative peak.</div><div style="font-family:"times new roman",serif"><br></div><div style="font-family:"times new roman",serif">In the case of running sleep spindle PSD analysis (i.e. after performing the sleep detection), I adopt a similar strategy. However, I noticed that when I used the following code to generate the power spectra plot and absolute power within the sigma (11-16 Hz) band, I get a negative log transformed PSD distribution plots for my datasets. Is it because of the prior bandpass filtering I do before spindle detection? The reason I do such filtering is because I want the spindles to be detected within the sigma band (based on the criteria set in the pop_detectevent). If I don't do such filtering and run detectevent plugin, then I end up with more detected spindles which could be from other frequency bands (that reminds me to ask you, is it also possible to get information about the mean frequency and amplitude of the detected spindle from the detectevent plugin; this could be a way for me to cross-check that the detected spindles are within the sigma band). </div><div style="font-family:"times new roman",serif">But not using the filter prior to spindle detection, produces positive log transformed power values within the sigma band. So I am unclear as to why filtering the dataset within the sigma band is giving me negative power values.</div><div style="font-family:"times new roman",serif">Following is the code snippet from my script:</div><div style="font-family:"times new roman",serif"><br></div><div style="font-family:"times new roman",serif"><div>%% SPINDLE DETECTION AND PSD</div><div> EEG = pop_loadset([subject '_N2_N3_COMBINED.set']);</div><div> </div><div> EEG.setname = [subject '_spindle'];</div><div> </div><div> EEG = pop_basicfilter( EEG, 1:10 , 'Boundary', 'boundary', 'Cutoff', [ 11 16], 'Design', 'butter', 'Filter', 'bandpass', 'Order', 2 );</div><div> </div><div> EEG = pop_detectevent(EEG);</div><div> </div><div> figure; [power_spindle{s}, freq_spindle{s}] = spectopo(EEG.data(3:6, :), 0, 250, 'freqrange', [0 25], 'title', [subject '_spindle'], 'freqfac', 2);</div><div> </div><div> %average power within the predefined frequency range</div><div> meanPower_spindle{s} = mean(10.^(power_spindle{s}(freq_spindle{s} >= 11 & freq_spindle{s} <= 16)/10));</div><div> </div><div>I am using the spectopo function to calculate the power so is it that the plot I see shows me the relative power (which I read in some papers could be negative for sleep spindles; reference the 2017 Nature Communications paper by Purcell and colleagues on sleep spindles) or is there something wrong with my codes? Please note that when I calculate absolute power, the value is positive but they are in the range of 0 (e.g. 0.02, 0.5 etc.) which is weird because its not the typical score range of other sleep spindle power studies. Your help is once again very much appreciated. I will also cc: this mail to Eeglablist as well since I raise multiple issues dealing with spindles, SO, PSD, and filtering in this email and some may find it relevant to their research and help me solve these issues.</div><div><br></div><div>Regards, </div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 27, 2019 at 12:01 PM Arnaud Delorme <<a href="mailto:arno@ucsd.edu" target="_blank">arno@ucsd.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear Mo,<br>
<br>
Yes, I think the plugin could do that with a function that computes power (instead of RMS over a window, it could compute power in that window and return power of the SO). I guess a simple wrapper on the spectopo function (disabling plotting) or even using Matlab FFT function would do. Something like<br>
<br>
function soPower = detectso(data)<br>
<br>
srate = 256;<br>
soFreq = 1;<br>
<br>
data = data .* hanning(length(data));<br>
data = fft(data);<br>
f = linspace(0, srate/2, floor(length(data)/2));<br>
[~,ind] = min( abs(f-soFreq));<br>
soPower = data(ind)*conj(data(ind));<br>
<br>
Let me know if it works for you.<br>
<br>
Cheers,<br>
<br>
Arno<br>
<br>
> On Feb 26, 2019, at 7:46 PM, VARMA, MOHITH MUKUND <<a href="mailto:mohith96@connect.hku.hk" target="_blank">mohith96@connect.hku.hk</a>> wrote:<br>
> <br>
> Dear Arno,<br>
> <br>
> Thanks a lot with the help and providing the plugin for spindle detection! Since, I am also doing some slow oscillation (SO) power analysis, I wonder is there plugin or EEGLAB function to detect positive-to-negative crossings of EEG data points in order to mark SO events in the EEG sleep datasets? I am trying to detect SOs in my datasets using the criteria reported in the same 2018 Current Biology paper by Antony and colleagues (because it seems to be quite a robust and well-cited detection algorithm, and if there is an EEGLAB function/plugin based on it then that would be great and easy for researchers like me who have to do sleep physiology analyses). Currently I am using the fieldtrip z value calculations to detect slow oscillations, however, I would prefer to do all my analyses using EEGLAB filters and functions.<br>
> <br>
> In order to detect SOs first I need to identify successive positive-to-negative crossings of EEG data points that last for 0.75 to 2 seconds. Once I can identify such data points then I think I will be able to apply the other two SO classification criteria which are as follows:<br>
> (a) there needs to be a negative peak of -40 microvolt within these series of data points and, (b) a peak-to-peak amplitude of 75 microvolts. The part that I am stuck at is detecting these zero crossings so yours or the expert researchers in this community help is very much appreciated.<br>
> <br>
> Regards,<br>
> <br>
> On Sat, Feb 23, 2019 at 5:25 AM Arnaud Delorme <<a href="mailto:arno@ucsd.edu" target="_blank">arno@ucsd.edu</a>> wrote:<br>
> Dear Mo,<br>
> <br>
> The function rmsave will not compute a moving average.<br>
> Try downloading the following plugin to detect spindles and place it in the EEGLAB plugin folder<br>
> <br>
> <a href="https://github.com/arnodelorme/detectevent" rel="noreferrer" target="_blank">https://github.com/arnodelorme/detectevent</a><br>
> <br>
> When plotting the data, you can decide to plot event durations (menu Display > Plot event duration)<br>
> <br>
> Best wishes,<br>
> <br>
> Arno<br>
> <br>
> > On Feb 20, 2019, at 7:44 PM, VARMA, MOHITH MUKUND <<a href="mailto:mohith96@connect.hku.hk" target="_blank">mohith96@connect.hku.hk</a>> wrote:<br>
> > <br>
> > Dear all,<br>
> > <br>
> > I am trying to extract the sleep spindle power from my nap EEG datasets and I am trying to adopt the methodology adopted by Antony and colleagues (2018) in the Current Biology paper on sleep spindle refractoriness. Their method of detecting spindles in the raw EEG data and the subsequent power analysis involves computing the root mean square (RMS) at each time point on a specific channel using a moving window of +/- 0.2 sec. I am using the rmsave function on EEGLAB to compute the RMS at each time point on a channel, however I am not able to implement the moving window criteria into my RMS calculation. Your help in debugging this problem is very much appreciated. Following is the code snippet:<br>
> > <br>
> > EEG = pop_biosig(['ub' subject 'scored.edf']);<br>
> > <br>
> > EEG.setname = [subject '_bsd'];<br>
> > <br>
> > EEG = pop_basicfilter( EEG, 1:8 , 'Boundary', 'boundary', 'Cutoff', [ 11 16], 'Design', 'butter', 'Filter', 'bandpass', 'Order', 2 ); %filter the dataset within 11-16 Hz<br>
> > <br>
> > averms = rmsave(EEG.data, 400); %calculate RMS score for each channel<br>
> > <br>
> > trans = transpose(averms);<br>
> > <br>
> > After I have calculated the RMS scores for each channel separately, I want to calculate the spindle threshold criteria by multiplying the standard deviation of the entire channel signal (in RMS) to 1.5. I think I did this part correctly. However, in order to detect a sleep spindle I have a criteria which is that any RMS score that is above the threshold consecutively for 0.5 to 3 seconds will be considered as a spindle. I am having difficulty in implementing the IF condition for this part along with calculating the onset and offset for each detected spindle. Following is the remainder code that I have come up with so far:<br>
> > <br>
> > threshold = std(trans).* 1.5;<br>
> > <br>
> > for s=1:trans(: , 1)<br>
> > <br>
> > if s > threshold & %time condition for RMS scores being 0.5 to 3 seconds<br>
> > <br>
> > %here the variable to store each spindle without replacing the previous detected one.<br>
> > <br>
> > %onset and offset time for the spindle along with its mean frequency and positive/negative peaks<br>
> > <br>
> > end;<br>
> > <br>
> > end;<br>
> > <br>
> > Thanks in advance for your help!<br>
> > <br>
> > Regards,<br>
> > <br>
> > -- <br>
> > Mohith M. Varma (Mo)<br>
> > Graduate Research Assistant<br>
> > <br>
> > Social & Cognitive Neuroscience Laboratory<br>
> > Department of Psychology<br>
> > Faculty of Social Sciences<br>
> > The University of Hong Kong<br>
> > Tel: (+852) 52622875<br>
> > Email: <a href="mailto:mohith96@connect.hku.hk" target="_blank">mohith96@connect.hku.hk</a><br>
> > _______________________________________________<br>
> > Eeglablist page: <a href="http://sccn.ucsd.edu/eeglab/eeglabmail.html" rel="noreferrer" target="_blank">http://sccn.ucsd.edu/eeglab/eeglabmail.html</a><br>
> > To unsubscribe, send an empty email to <a href="mailto:eeglablist-unsubscribe@sccn.ucsd.edu" target="_blank">eeglablist-unsubscribe@sccn.ucsd.edu</a><br>
> > For digest mode, send an email with the subject "set digest mime" to <a href="mailto:eeglablist-request@sccn.ucsd.edu" target="_blank">eeglablist-request@sccn.ucsd.edu</a><br>
> <br>
> _______________________________________________<br>
> Eeglablist page: <a href="http://sccn.ucsd.edu/eeglab/eeglabmail.html" rel="noreferrer" target="_blank">http://sccn.ucsd.edu/eeglab/eeglabmail.html</a><br>
> To unsubscribe, send an empty email to <a href="mailto:eeglablist-unsubscribe@sccn.ucsd.edu" target="_blank">eeglablist-unsubscribe@sccn.ucsd.edu</a><br>
> For digest mode, send an email with the subject "set digest mime" to <a href="mailto:eeglablist-request@sccn.ucsd.edu" target="_blank">eeglablist-request@sccn.ucsd.edu</a><br>
> <br>
> <br>
> -- <br>
> Mohith M. Varma (Mo)<br>
> Graduate Research Assistant<br>
> <br>
> Social & Cognitive Neuroscience Laboratory<br>
> Department of Psychology<br>
> Faculty of Social Sciences<br>
> The University of Hong Kong<br>
> Tel: (+852) 52622875<br>
> Email: <a href="mailto:mohith96@connect.hku.hk" target="_blank">mohith96@connect.hku.hk</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_2430964474684850257gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><font size="2" face="times new roman, serif">Mohith M. Varma (Mo)</font></div><div><span style="font-family:"times new roman",serif;font-size:small">Graduate Research Assistant</span><br></div><div><font size="2" face="times new roman, serif"><br></font></div><div><font size="2" face="times new roman, serif">Social & Cognitive Neuroscience Laboratory</font></div><div><span style="font-family:"times new roman",serif;font-size:small">Department of Psychology</span></div><div><font size="2" face="times new roman, serif">Faculty of Social Sciences</font></div><div><font size="2" face="times new roman, serif">The University of Hong Kong</font></div><div><font size="2" face="times new roman, serif">Tel: (+852) 52622875</font></div><div><font size="2" face="times new roman, serif">Email: <a href="mailto:mohith96@connect.hku.hk" target="_blank">mohith96@connect.hku.hk<br></a></font></div><div style="font-size:small"></div></div></div></div></div></div></div>
</div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><font size="2" face="times new roman, serif">Mohith M. Varma (Mo)</font></div><div><span style="font-family:"times new roman",serif;font-size:small">Graduate Research Assistant</span><br></div><div><font size="2" face="times new roman, serif"><br></font></div><div><font size="2" face="times new roman, serif">Social & Cognitive Neuroscience Laboratory</font></div><div><span style="font-family:"times new roman",serif;font-size:small">Department of Psychology</span></div><div><font size="2" face="times new roman, serif">Faculty of Social Sciences</font></div><div><font size="2" face="times new roman, serif">The University of Hong Kong</font></div><div><font size="2" face="times new roman, serif">Tel: (+852) 52622875</font></div><div><font size="2" face="times new roman, serif">Email: <a href="mailto:mohith96@connect.hku.hk" target="_blank">mohith96@connect.hku.hk<br></a></font></div><div style="font-size:small"></div></div></div></div></div></div></div></div>