image thumbnail

How to decompose and verify EEG data to bands.

version 1.0.0 (18.6 MB) by Mahsa Hassankashi
There is EEG signal (one channel). It has been decomposed to gamma, beta, alpha, theta, delta and code makes multiple verifications plots.

12 Downloads

Updated 03 Aug 2021

View License

There is EEG signal (one channel). It has been decomposed to gamma, beta, alpha, theta, delta and code makes multiple verifications plots.
wavedec example: [ c , l ] = wavedec( x , n , wname ) returns the wavelet decomposition of the 1-D signal x at level n using the wavelet wname . The output decomposition structure consists of the wavelet decomposition vector c and the bookkeeping vector l , which contains the number of coefficients by level.
waverec performs a multilevel one-dimensional wavelet reconstruction using either a specific wavelet ('wname', see wfilters) or specific reconstruction filters (Lo_R and Hi_R). waverec is the inverse function of wavedec in the sense that the abstract statement waverec(wavedec(X,N,'wname'),'wname') returns X.
EEG_data_C3_4 = csvread('A-eeg.csv');
V = EEG_data_C3_4(:,1);
N=length(EEG_data_C3_4(:,1));
yy1=bandpass(V,[4 30],128);
waveletFunction = 'db8';
[C,L] = wavedec(V,8,waveletFunction); % Denoise EOG from EEG
cD1 = detcoef(C,L,1);
cD2 = detcoef(C,L,2);
cD3 = detcoef(C,L,3);
cD4 = detcoef(C,L,4);
cD5 = detcoef(C,L,5); %GAMMA
cD6 = detcoef(C,L,6); %BETA
cD7 = detcoef(C,L,7); %ALPHA
cD8 = detcoef(C,L,8); %THETA
cA8 = appcoef(C,L,waveletFunction,5); %DELTA
D1 = wrcoef('d',C,L,waveletFunction,1); %NOISY
A1 = wrcoef('a',C,L,waveletFunction,1); %Level 1 Approximation
D2 = wrcoef('d',C,L,waveletFunction,2); %NOISY
A2 = wrcoef('a',C,L,waveletFunction,2); %Level 2 Approximation
D3 = wrcoef('d',C,L,waveletFunction,3); %NOISY
A3 = wrcoef('a',C,L,waveletFunction,3); %Level 3 Approximation
D4 = wrcoef('d',C,L,waveletFunction,4); %NOISY
A4 = wrcoef('a',C,L,waveletFunction,4); %Level 4 Approximation
D5 = wrcoef('d',C,L,waveletFunction,5); %GAMMA
A5 = wrcoef('a',C,L,waveletFunction,5); %Level 5 Approximation
D6 = wrcoef('d',C,L,waveletFunction,6); %BETA
A6 = wrcoef('a',C,L,waveletFunction,6); %Level 6 Approximation
D7 = wrcoef('d',C,L,waveletFunction,7); %ALPHA
A7 = wrcoef('a',C,L,waveletFunction,7); %Level 7 Approximation
D8 = wrcoef('d',C,L,waveletFunction,8); %THETA 4-7
A8 = wrcoef('a',C,L,waveletFunction,8); %DELTA 1-4 Level 8 Approximation
figure;
subplot(2,1,1);plot(V);title('Original'); axis off
subplot(2,1,2);plot(A8);title('Level 8 Approximation');axis off
sgtitle('wrcoef Approximation vs Original eeg');
fs=128;
fmin = 30; % minimum passband frequency in Hz (High Gamma) 30
fmax =50; % maximum passband frequency in Hz (High Gamma) 50
Rs = 20; % stopband attenuation in dB 20
Rp = 1; % passband ripples in dB 1
% for High gamma band
[order, Wn] = ellipord([fmin/(fs/2), fmax/(fs/2)], [(fmin-1)/(fs/2), (fmax+1)/(fs/2)], Rp, Rs);
[B,A] = ellip(order, Rp, Rs, [fmin/(fs/2), fmax/(fs/2)]);
%filtering of entire data into High Gamma band
data_hgamma = filtfilt(B,A,V);
figure;
subplot(3,1,1);plot(D6);title('wavelet'); axis off
subplot(3,1,2);plot(data_hgamma);title('ellipord'); axis off
sgtitle('waverec gamma vs ellipord gamma');
dLen = length(D7);
dF = fs/dLen;
f = dF*(0:dLen-1)';
A0 = waverec(C,L,'db8');
err = max(abs(V-A0));
disp(err);
Cnew = C;
tmp = cumsum(L);
Cnew(tmp(end-2)+1:tmp(end-1)) = 0;
Rec_signal=waverec(Cnew,L,'db8');
figure;
subplot(4,1,1);plot(V,'k');title('Original'); axis off
subplot(4,1,2); plot(Rec_signal,'r','linewidth',2);title('Reconstruct');axis off
sgtitle('waverec reconstruct wavelet');

Cite As

Mahsa Hassankashi (2021). How to decompose and verify EEG data to bands. (https://www.mathworks.com/matlabcentral/fileexchange/97072-how-to-decompose-and-verify-eeg-data-to-bands), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Verify Decomposition