-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_psd.m
35 lines (31 loc) · 1.13 KB
/
calc_psd.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function [ChanPSD, f] = calc_psd(EEG, window_length)
% function function [power, f] = calc_psd(EEG, window_length)
%
% This function is used to calculate PSD using welch method
% The function loads '.set' epoched EEG file for the respective SSVEP event
% ad calculates the PSD for each trial.
%
% Inputs:
% EEG (struct) : EEGLab EEG epoched data
% window_lengh (int) : length of the window for pwelch
%
% Ouput:
% ChanPSD (2D array) : PSD values averaged across trial for each channel (PSD values x channel)
% f (1D array) : frequency vector
%
% Example function call:
% erd = calc_erd(EEG, binsize, base_start, base_end)
% overlap of the window
overlap = window_length / 2;
% loop over channels
for iChan = 1:size(EEG.data,1)
% loop over trials
for iTrial = 1:size(EEG.data,3)
% computing psd usign pwelch
[pxx, f] = pwelch(EEG.data(iChan,:,iTrial), hamming(window_length), overlap, 2^nextpow2(window_length*4), EEG.srate);
% computing psd usign pwelch
pxx_all(:,iChan,iTrial) = pxx;
end
end
% average across trials
ChanPSD = mean(pxx_all,3);