Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
JingweiToo authored Dec 12, 2020
1 parent 645fb85 commit e51ffac
Show file tree
Hide file tree
Showing 32 changed files with 424 additions and 0 deletions.
59 changes: 59 additions & 0 deletions A_Main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
% Electroencephalogram (EEG) Feature Extraction toolbox

%---Input-------------------------------------------------------------
% X : EEG signal (1 x samples)
% opts : parameter settings
%

%---Output------------------------------------------------------------
% feat: Feature vector
%---------------------------------------------------------------------


%% Generate a sample random signal X
fs = 500; % Sampling frequency
Ts = 1 / fs; % Period
t = 0 : Ts : 0.5;
X = 0.01 * (sin(2 * pi * fs * t) + randn(1, length(t)));

% Plot sample signal
plot(t,X); grid on
xlabel('Number of samples');
ylabel('Amplitude');


%% Example 1 : Extract 3 normal features ( without parameter )
% Generate a sample random signal X
fs = 500; % Sampling frequency
Ts = 1 / fs; % Period
t = 0 : Ts : 0.5;
X = 0.01 * (sin(2 * pi * fs * t) + randn(1, length(t)));

% Hjorth Activity
f1 = jfeeg('ha', X);
% Hjorth Mobility
f2 = jfeeg('hm', X);
% Hjorth Complexity
f3 = jfeeg('hc', X);

% Feature vector
feat = [f1, f2, f3];


%% Example 2 : Extract 2 features with parameter
% Generate a sample random signal X
fs = 500; % Sampling frequency
Ts = 1 / fs; % Period
t = 0 : Ts : 0.5;
X = 0.01 * (sin(2 * pi * fs * t) + randn(1, length(t)));

% Band Power Alpha
opts.fs = 500;
f1 = jfeeg('bpa', X, opts);
% Tsallis Entropy
opts.alpha = 2;
f2 = jfeeg('te', X, opts);

% Feature vector
feat = [f1, f2];

7 changes: 7 additions & 0 deletions jArithmeticMean.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%[2014]-"A Comparative Study on Classification of Sleep Stage Based on
%EEG Signals Using Feature Selection and Classification Algorithms" (4)

function AM = jArithmeticMean(X,~)
AM = mean(X);
end

14 changes: 14 additions & 0 deletions jAutoRegressiveModel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%[2012]-"Classification of EMG signals using combined features and
%soft computing techniques" (1-2)

function AR = jAutoRegressiveModel(X,opts)
% Parameter
order = 4; % order

if isfield(opts,'order'), order = opts.order; end

Y = arburg(X,order);
% First index is meaningless
AR = Y(2 : order + 1);
end

13 changes: 13 additions & 0 deletions jBandPowerAlpha.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

function BPA = jBandPowerAlpha(X,opts)
% Parameters
f_low = 8; % 8 Hz
f_high = 12; % 12 Hz

% sampling frequency
if isfield(opts,'fs'), fs = opts.fs; end

% Band power
BPA = bandpower(X, fs, [f_low f_high]);
end

13 changes: 13 additions & 0 deletions jBandPowerBeta.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

function BPB = jBandPowerBeta(X,opts)
% Parameters
f_low = 12; % 12 Hz
f_high = 30; % 30 Hz

% sampling frequency
if isfield(opts,'fs'), fs = opts.fs; end

% Band power
BPB = bandpower(X, fs, [f_low f_high]);
end

13 changes: 13 additions & 0 deletions jBandPowerDelta.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

function BPD = jBandPowerDelta(X,opts)
% Parameters
f_low = 1; % 1 Hz
f_high = 4; % 4 Hz

% sampling frequency
if isfield(opts,'fs'), fs = opts.fs; end

% Band power
BPD = bandpower(X, fs, [f_low f_high]);
end

13 changes: 13 additions & 0 deletions jBandPowerGamma.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

function BPG = jBandPowerGamma(X,opts)
% Parameters
f_low = 30; % 30 Hz
f_high = 64; % 64 Hz

% sampling frequency
if isfield(opts,'fs'), fs = opts.fs; end

% Band power
BPG = bandpower(X, fs, [f_low f_high]);
end

13 changes: 13 additions & 0 deletions jBandPowerTheta.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

function BPT = jBandPowerTheta(X,opts)
% Parameters
f_low = 4; % 4 Hz
f_high = 8; % 8 Hz

% sampling frequency
if isfield(opts,'fs'), fs = opts.fs; end

% Band power
BPT = bandpower(X, fs, [f_low f_high]);
end

11 changes: 11 additions & 0 deletions jFirstDifference.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%[2014]-"Feature Extraction and Selection for Emotion Recognition from
%EEG"

function FD = jFirstDifference(X,~)
T = length(X);
Y = 0;
for t = 1 : T - 1
Y = Y + abs(X(t+1) - X(t));
end
FD = (1 / (T - 1)) * Y;
end
7 changes: 7 additions & 0 deletions jHjorthActivity.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%[2018]-"A Novel Multi-Class EEG-Based Sleep Stage Classification System"
%(3)

function HA = jHjorthActivity(X,~)
sd = std(X);
HA = sd ^ 2;
end
16 changes: 16 additions & 0 deletions jHjorthComplexity.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%[2018]-"A Novel Multi-Class EEG-Based Sleep Stage Classification System"
%(5)

function HC = jHjorthComplexity(X,~)
% First & second derivative
x0 = X(:);
x1 = diff([0; x0]);
x2 = diff([0; x1]);
% Standard deviation of first & second derivative
sd0 = std(x0);
sd1 = std(x1);
sd2 = std(x2);
% Complexity
HC = (sd2 / sd1) / (sd1 / sd0);
end

13 changes: 13 additions & 0 deletions jHjorthMobility.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%[2018]-"A Novel Multi-Class EEG-Based Sleep Stage Classification System"
%(4)

function HM = jHjorthMobility(X,~)
% First derivative
x0 = X(:);
x1 = diff([0; x0]);
% Standard deviation
sd0 = std(x0);
sd1 = std(x1);
HM = sd1 / sd0;
end

5 changes: 5 additions & 0 deletions jKurtosis.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

function KURT = jKurtosis(X,~)
% Kurtosis
KURT = kurtosis(X);
end
8 changes: 8 additions & 0 deletions jLogEnergyEntropy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%[2017]-"Automated detection of focal EEG signals using features
%extracted from flexible analytic wavelet transform" (8)

function LogEn = jLogEnergyEntropy(X,~)
% Entropy
LogEn = sum(log(X .^ 2));
end

11 changes: 11 additions & 0 deletions jLogRootSumOfSequentialVariation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%[2018]-"A Novel Multi-Class EEG-Based Sleep Stage Classification
%System" (11)

function LRSSV = jLogRootSumOfSequentialVariation(X,~)
N = length(X);
Y = zeros(1, N-1);
for i = 2:N
Y(i-1) = (X(i) - X(i-1)) ^ 2;
end
LRSSV = log10(sqrt(sum(Y)));
end
7 changes: 7 additions & 0 deletions jMaximum.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%[2014]-"A Comparative Study on Classification of Sleep Stage Based on EEG
%Signals Using Feature Selection and Classification Algorithms" (2)

function X_max = jMaximum(X,~)
X_max = max(X);
end

12 changes: 12 additions & 0 deletions jMeanCurveLength.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%[2014]-"A Comparative Study on Classification of Sleep Stage Based on
%EEG Signals Using Feature Selection and Classification Algorithms" (13)

function MCL = jMeanCurveLength(X,~)
N = length(X);
Y = 0;
for m = 2:N
Y = Y + abs(X(m) - X(m-1));
end
MCL = (1 / N) * Y;
end

6 changes: 6 additions & 0 deletions jMeanEnergy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%[2014]-"A Comparative Study on Classification of Sleep Stage Based on
%EEG Signals Using Feature Selection and Classification Algorithms" (12)

function ME = jMeanEnergy(X,~)
ME = mean(X .^ 2);
end
12 changes: 12 additions & 0 deletions jMeanTeagerEnergy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%[2014]-"A Comparative Study on Classification of Sleep Stage Based on
%EEG Signals Using Feature Selection and Classification Algorithms" (11)

function MTE = jMeanTeagerEnergy(X,~)
N = length(X);
Y = 0;
for m = 3:N
Y = Y + ((X(m-1) ^ 2) - X(m) * X(m-2));
end
MTE = (1 / N) * Y;
end

7 changes: 7 additions & 0 deletions jMedian.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%[2014]-"A Comparative Study on Classification of Sleep Stage Based on
%EEG Signals Using Feature Selection and Classification Algorithms" (8-9)

function X_med = jMedian(X,~)
X_med = median(X);
end

7 changes: 7 additions & 0 deletions jMinimum.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%[2014]-"A Comparative Study on Classification of Sleep Stage Based on EEG
%Signals Using Feature Selection and Classification Algorithms" (1)

function X_min = jMinimum(X,~)
X_min = min(X);
end

12 changes: 12 additions & 0 deletions jNormalizedFirstDifference.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%[2014]-"Feature Extraction and Selection for Emotion Recognition from
%EEG"

function NFD=jNormalizedFirstDifference(X,~)
T = length(X);
Y = 0;
for t = 1 : T - 1
Y = Y + abs(X(t+1) - X(t));
end
FD = (1 / (T - 1)) * Y;
NFD = FD / std(X);
end
12 changes: 12 additions & 0 deletions jNormalizedSecondDifference.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%[2014]-"Feature Extraction and Selection for Emotion Recognition from
%EEG"

function NSD = jNormalizedSecondDifference(X,~)
T = length(X);
Y = 0;
for t = 1 : T - 2
Y = Y + abs(X(t+2) - X(t));
end
SD = (1 / (T - 2)) * Y;
NSD = SD / std(X);
end
20 changes: 20 additions & 0 deletions jRatioBandPowerAlphaBeta.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

function RBA = jRatioBandPowerAlphaBeta(X,opts)
% Parameters
f_low1 = 8; % 8 Hz
f_high1 = 12; % 12 Hz

f_low2 = 12; % 12 Hz
f_high2 = 30; % 30 Hz

% sampling frequency
if isfield(opts,'fs'), fs = opts.fs; end

% Band power alpha
BPA = bandpower(X, fs, [f_low1 f_high1]);
% Band power beta
BPB = bandpower(X, fs, [f_low2 f_high2]);
% Ratio beta/alpha
RBA = BPB / BPA;
end

16 changes: 16 additions & 0 deletions jRenyiEntropy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%[2018]-"Improved binary dragonfly optimization algorithm and wavelet
%packet based non-linear features for infant cry classification" (4)

function ReEn = jRenyiEntropy(X,opts)
% Parameter
alpha = 2; % alpha

if isfield(opts,'alpha'), alpha = opts.alpha; end

% Convert probability using energy
P = (X .^ 2) ./ sum(X .^ 2);
% Entropy
En = P .^ alpha;
ReEn = (1 / (1 - alpha)) * log2(sum(En));
end

11 changes: 11 additions & 0 deletions jSecondDifference.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%[2014]-"Feature Extraction and Selection for Emotion Recognition from
%EEG"

function SD = jSecondDifference(X,~)
T = length(X);
Y = 0;
for t = 1 : T - 2
Y = Y + abs(X(t+2) - X(t));
end
SD = (1 / (T - 2)) * Y;
end
11 changes: 11 additions & 0 deletions jShannonEntropy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%[2018]-"Improved binary dragonfly optimization algorithm and wavelet
%packet based non-linear features for infant cry classification" (3)

function ShEn = jShannonEntropy(X,~)
% Convert probability using energy
P = (X .^ 2) ./ sum(X .^ 2);
% Entropy
En = P .* log2(P);
ShEn = -sum(En);
end

5 changes: 5 additions & 0 deletions jSkewness.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

function SKEW = jSkewness(X,~)
SKEW = skewness(X);
end

7 changes: 7 additions & 0 deletions jStandardDeviation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

function SD = jStandardDeviation(X,~)
N = length(X);
mu = mean(X);
SD = sqrt((1 / (N - 1)) * sum((X - mu) .^ 2));
end

Loading

0 comments on commit e51ffac

Please sign in to comment.