# [Eeglablist] Calculating PSD within scored sleep data

VARMA, MOHITH MUKUND mohith96 at connect.hku.hk
Tue Mar 5 02:21:54 PST 2019

```Dear all:

I am trying to run PSD analysis for each sleep stage within a scored sleep
data. First of all I import the event file which contains the information
on the latency for each sleep stage and I notice EEGLAB converts this
latency information into EEG data points. I would like to run PSD for one
specific sleep stage while ignoring the channel activity from other stages.
I am not sure how to implement it using the if else statements. Basically I
want to tell MATLAB that if the EEG.event.type == REM, then it should run
PSD only for the data points that fall in the time period which is scored
as REM. Along with running the PSD analysis, I also want to generate
separate .set files for each sleep stage. Your help in solving this problem
is highly appreciated.

Following is the code snippet I have used so far:

EEG.setname = [subject '_sleep_stages'];

[EEG, indices] = pop_importevent( EEG, 'event',[subject
'_event_info.txt'],'fields',{'latency' 'type'},'skipline',1,'timeunit',1);

% Obtain event indices whose 'type' is 'N1, N2, N3, REM, ART'
allEventTypes = {EEG.event.type}';
N1 = find(strcmp(allEventTypes, 'N1'));
N2 = find(strcmp(allEventTypes, 'N2'));
N3 = find(strcmp(allEventTypes, 'N3'));
REM = find(strcmp(allEventTypes, 'REM'));
Art = find(strcmp(allEventTypes, 'Art'));

% if EEG.event.type == 'REM'

%PSD analysis
figure; [power_whole{s}, freq_whole{s}] = spectopo(EEG.data(3:6,
:), 0, 250, 'freqrange', [0 25],              'title', [subject],
'freqfac', 2);

% ifelse EEG.event.type == 'N2'

%PSD analysis
figure; [power_whole{s}, freq_whole{s}] = spectopo(EEG.data(3:6,
:), 0, 250, 'freqrange', [0 25],              'title', [subject],
'freqfac', 2);

Regards,

--
Mohith M. Varma (Mo)

Social & Cognitive Neuroscience Laboratory
Department of Psychology
Faculty of Social Sciences
The University of Hong Kong
Tel: (+852) 52622875
Email: mohith96 at connect.hku.hk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sccn.ucsd.edu/pipermail/eeglablist/attachments/20190305/affa895c/attachment.html>
```