MATLAB: Calculating SEF (spectral edge frequency) of a EEG

eeg

I currently have a file with a 4 channel EEG, and I want to calculate the SEF (95%) using that raw data. I wanted to know if there is as automated way of doing so using Matlab. I also have computed data Hz x time x dB of the given raw EEG file.
ADICIONAL INFO: The SEF is a Hz by time chart where the Hz shown is the threshold frequency where 95% of the EEG power lies beneath it at a given time (I don't know which algorithm to use) though.
Thank you in advance!

Best Answer

I would use cumtrapz to do the integration, and interp1 using the cumtrapz result and the frequency vector to find the SEF.
Example
% First, Create Data
t = 0 : 0.01 : 1;
for f = 1 : 2 : 10
y(f,:) = sin (2 * pi .* f .* t);
end
L = length(t); % Signal Length
Ts = t(2) - t(1); % Sampling Time Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
Fourier = fft(y, [], 2)/L; % Fourier Transform (Along Rows Of Matrix)
Fouriers = sum(abs(Fourier)); % Spectrum
IntSpectrum = cumtrapz(Fv, Fouriers(Iv)); % Numeric Integration
SEF = interp1(IntSpectrum, Fv, 0.95*IntSpectrum(end), 'linear'); % Interploate To Find ‘SEF’
figure(1)
plot(Fv, Fouriers(Iv)*2)
hold on
plot([1 1]*SEF, ylim, '--r')
hold off
Related Question