%% Feature Extraction from EEG Rhythm in Time Domain, EO1, Active

clc

clear

close all

%% Load EO1, Active

load P01EO1

load P03EO1

load P05EO1

load P08EO1

load P09EO1

load P10EO1

load P11EO1

load P17EO1

load P18EO1

load P19EO1

load P21EO1

load P24EO1

load P25EO1

load P27EO1

%%

fs=256; % Sampling frequency(Hz)

Nf=36; %number of feautures

Nch= size(P01EO1,2); % number of columns(channels)

TfeaturesR_P01EO1= zeros(Nf,Nch);

TfeaturesR_P03EO1= zeros(Nf,Nch);

TfeaturesR_P05EO1= zeros(Nf,Nch);

TfeaturesR_P08EO1= zeros(Nf,Nch);

TfeaturesR_P09EO1= zeros(Nf,Nch);

TfeaturesR_P10EO1= zeros(Nf,Nch);

TfeaturesR_P11EO1= zeros(Nf,Nch);

TfeaturesR_P17EO1= zeros(Nf,Nch);

TfeaturesR_P18EO1= zeros(Nf,Nch);

TfeaturesR_P19EO1= zeros(Nf,Nch);

TfeaturesR_P21EO1= zeros(Nf,Nch);

TfeaturesR_P27EO1= zeros(Nf,Nch);

TfeaturesR_P25EO1= zeros(Nf,Nch);

TfeaturesR_P27EO1= zeros(Nf,Nch);

%% Step1: Denoising (50Hz)

% Design stop filter

fl= 49.9;

fh= 50.1;

order= 3;

wn= [fl fh]/ (fs/2);

type= ‘stop’;

[b1,a1]= butter(order,wn,type);

% Set up a for loop

for i=1:Nch

sig1= P01EO1(:,i);

sig2= P03EO1(:,i);

sig3= P05EO1(:,i);

sig4= P08EO1(:,i);

sig5= P09EO1(:,i);

sig6= P10EO1(:,i);

sig7= P11EO1(:,i);

sig8= P17EO1(:,i);

sig9= P18EO1(:,i);

sig10= P19EO1(:,i);

sig11= P21EO1(:,i);

sig12= P24EO1(:,i);

sig13= P25EO1(:,i);

sig14= P27EO1(:,i);

% Apply notch (stop) filter

sig1= filtfilt(b1,a1,sig1);

sig2= filtfilt(b1,a1,sig2);

sig3= filtfilt(b1,a1,sig3);

sig4= filtfilt(b1,a1,sig4);

sig5= filtfilt(b1,a1,sig5);

sig6= filtfilt(b1,a1,sig6);

sig7= filtfilt(b1,a1,sig7);

sig8= filtfilt(b1,a1,sig8);

sig9= filtfilt(b1,a1,sig9);

sig10= filtfilt(b1,a1,sig10);

sig11= filtfilt(b1,a1,sig11);

sig12= filtfilt(b1,a1,sig12);

sig13= filtfilt(b1,a1,sig13);

sig14= filtfilt(b1,a1,sig14);

%% Frequency Bands

% delta= 1-4 Hz,

% theta= 4-8 Hz,

% alpha= 8-12 Hz,

% beta= 12-20 Hz,

% low gamma= 20-25 Hz,

% gamma= 25-40 Hz

band= [1,4,8,12,20,25;

4,8,12,20,25,40];

%% Step2: Extract EEG Rhythms in Time Domain

for j=1:size(band,2); %first column:delta

% Design bandpass filter

wn= band(:,j)/ (fs/2);

[b2,a2]= butter(3,wn,‘bandpass’);

% Apply designed bandpass filter

sig_1= filtfilt(b2,a2,sig1);

sig_2= filtfilt(b2,a2,sig2);

sig_3= filtfilt(b2,a2,sig3);

sig_4= filtfilt(b2,a2,sig4);

sig_5= filtfilt(b2,a2,sig5);

sig_6= filtfilt(b2,a2,sig6);

sig_7= filtfilt(b2,a2,sig7);

sig_8= filtfilt(b2,a2,sig8);

sig_9= filtfilt(b2,a2,sig9);

sig_10= filtfilt(b2,a2,sig10);

sig_11= filtfilt(b2,a2,sig11);

sig_12= filtfilt(b2,a2,sig12);

sig_13= filtfilt(b2,a2,sig13);

sig_14= filtfilt(b2,a2,sig14);

tp_P01EO1(:,j)= myfeatureExtraction(sig_1);

tp_P03EO1(:,j)= myfeatureExtraction(sig_2);

tp_P05EO1(:,j)= myfeatureExtraction(sig_3);

tp_P08EO1(:,j)= myfeatureExtraction(sig_4);

tp_P09EO1(:,j)= myfeatureExtraction(sig_5);

tp_P10EO1(:,j)= myfeatureExtraction(sig_6);

tp_P11EO1(:,j)= myfeatureExtraction(sig_7);

tp_P17EO1(:,j)= myfeatureExtraction(sig_8);

tp_P18EO1(:,j)= myfeatureExtraction(sig_9);

tp_P19EO1(:,j)= myfeatureExtraction(sig_10);

tp_P21EO1(:,j)= myfeatureExtraction(sig_11);

tp_P24EO1(:,j)= myfeatureExtraction(sig_12);

tp_P25EO1(:,j)= myfeatureExtraction(sig_13);

tp_P27EO1(:,j)= myfeatureExtraction(sig_14);

end

%% Step3: Feature Extraction in time domain

TfeaturesR_P01EO1(:,i)= tp_P01EO1(:);

TfeaturesR_P03EO1(:,i)= tp_P03EO1(:);

TfeaturesR_P05EO1(:,i)= tp_P05EO1(:);

TfeaturesR_P08EO1(:,i)= tp_P08EO1(:);

TfeaturesR_P09EO1(:,i)= tp_P09EO1(:);

TfeaturesR_P10EO1(:,i)= tp_P10EO1(:);

TfeaturesR_P11EO1(:,i)= tp_P11EO1(:);

TfeaturesR_P17EO1(:,i)= tp_P17EO1(:);

TfeaturesR_P18EO1(:,i)= tp_P18EO1(:);

TfeaturesR_P19EO1(:,i)= tp_P19EO1(:);

TfeaturesR_P21EO1(:,i)= tp_P21EO1(:);

TfeaturesR_P24EO1(:,i)= tp_P24EO1(:);

TfeaturesR_P25EO1(:,i)= tp_P25EO1(:);

TfeaturesR_P27EO1(:,i)= tp_P27EO1(:);

% disp([‘iteration’,num2str(i)])

end

Tfeatures_Rhythms_EO1Active= [TfeaturesR_P01EO1;TfeaturesR_P03EO1;TfeaturesR_P05EO1;

TfeaturesR_P08EO1;TfeaturesR_P09EO1;TfeaturesR_P10EO1;

TfeaturesR_P11EO1;TfeaturesR_P17EO1;TfeaturesR_P18EO1;

TfeaturesR_P19EO1;TfeaturesR_P21EO1;TfeaturesR_P24EO1;

TfeaturesR_P25EO1;TfeaturesR_P27EO1];

save Tfeatures_allRhythms_EO1Active TfeaturesR_P01EO1 TfeaturesR_P03EO1 TfeaturesR_P05EO1 TfeaturesR_P08EO1 TfeaturesR_P09EO1 TfeaturesR_P10EO1 TfeaturesR_P11EO1 TfeaturesR_P17EO1 TfeaturesR_P18EO1 TfeaturesR_P19EO1 TfeaturesR_P21EO1 TfeaturesR_P24EO1 TfeaturesR_P25EO1 TfeaturesR_P27EO1

save Tfeatures_Rhythms_EO1Active Tfeatures_Rhythms_EO1Active