Code in matlab is:
clc;
clear all;
close all;
load EEG1_1c31;% loading data
Ts=2;% sampling period
Fs=500;%sampling frequency
[N,nu]=size(data);%obtain size of data
t=(1:N)*Ts;%generates time vector
Fs = 500; % Sampling Frequency
Fstop1 = 7.5; % First Stopband Frequency
Fpass1 = 8; % First Passband Frequency
Fpass2 = 12; % Second Passband Frequency
Fstop2 = 12.5; % Second Stopband Frequency
Dstop1 = 0.0001; % First Stopband Attenuation
Dpass = 0.057501127785; % Passband Ripple
Dstop2 = 0.0001; % Second Stopband Attenuation
dens = 20; % Density Factor
% Calculate the order from the parameters using FIRPMORD.
[N, Fo, Ao, W] = firpmord([Fstop1 Fpass1 Fpass2 Fstop2]/(Fs/2), [0 1 0], [Dstop1 Dpass Dstop2]);
% Calculate the coefficients using the FIRPM function.
b3 = firpm(N, Fo, Ao, W, {dens});
Hd3 = dfilt.dffir(b3);
x3=filter(Hd3,data);
%FREQUENCY SPECTRUM OF ALPHA BAND
L=10;
Fs=500;
NFFT = 2^nextpow2(L); % Next power of 2 from length of x3
Y3 = fft(x3,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2);
%BETA BAND PASS FILTER (12-30)
Fs = 500; % Sampling Frequency
Fstop1 = 11.5; % First Stopband Frequency
Fpass1 = 12; % First Passband Frequency
Fpass2 = 30; % Second Passband Frequency
Fstop2 = 30.5; % Second Stopband Frequency
Dstop1 = 0.0001; % First Stopband Attenuation
Dpass = 0.057501127785; % Passband Ripple
Dstop2 = 0.0001; % Second Stopband Attenuation
dens = 20; % Density Factor
% Calculate the order from the parameters using FIRPMORD.
[N, Fo, Ao, W] = firpmord([Fstop1 Fpass1 Fpass2 Fstop2]/(Fs/2), [0 1 0], [Dstop1 Dpass Dstop2]);
% Calculate the coefficients using the FIRPM function
b4 = firpm(N, Fo, Ao, W, {dens});
Hd4 = dfilt.dffir(b4);
x4=filter(Hd4,data);
x=x3./x4;
b= x3(:,3);
c= x3(:,4);
d= x4(:,3);
e= x4(:,4);
f=(b./c)-(d./e);
for j= 2:32
sum=0;
for i= 1:16
sum = sum + x(j,i);
end
Mean_arousal = sum/16;
Mean_valence = f(j,:);
if Mean_arousal>0
if Mean_valence>0
a = 'Happy';
end
end
if Mean_arousal>0
if Mean_valence<0
a = 'stressed';
end
end
if Mean_arousal<0
if Mean_valence<0
a = 'Depressed';
end
end
if Mean_arousal<0
if Mean_valence>0
a = 'Sad';
end
end
end