基于Matlab的脑电波信号处理

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

做脑电波信号处理滴嘿嘿。。Matlab addicted

Codes

%FEATURE EXTRACTER

function [features] = EEGfeaturetrainmod(filename,m)

a = 4;

b = 7;

d = 12;

e = 30;

signals = 0;

for index = 1:9; % read in the first ten EEG data because the files are numbered as ha11test01 rather than ha11test1.

s = [filename '0' num2str(index) '.dat'];

signal = tread_wfdb(s);

if signals == 0;

signals = signal;

else signals = [signals signal];

end

end

for index = 10:1:m/2; % read in the rest of the EEG training data

s = [filename num2str(index) '.dat'];

signal = tread_wfdb(s);

if signals == 0;

signals = signal;

else signals = [signals signal];

end

end

%%%%% modification just for varying the training testing ratio ------

for index = 25:1:25+m/2; % read in the rest of the EEG training data s = [filename num2str(index) '.dat'];

signal = tread_wfdb(s);

if signals == 0;

signals = signal;

else signals = [signals signal];

end

end

%%%%%end of modification just for varying the training testing ratio-----

for l = 1:m % exrating features (power of each kind of EEG wave forms) [Pxx,f]=pwelch(signals(:,l)-mean(signals(:,l)), [], [], [], 200); % relative power fdelta(l) = sum(Pxx(find(f

ftheta(l) = sum(Pxx(find(fa)));

falpha(l) = sum(Pxx(find(fb)));

fbeta(l) = sum(Pxx(find(fd)));

fgama(l)= sum(Pxx(find(f>e))); % gama wave included for additional work

end

features = [fdelta; ftheta; falpha; fbeta a; fgama];

features = features';

end

%CLASSIFIER

%(Has three similar classification modifation: EEGclassification, EEGclassificationmod and EEGclassificationmod1 saved and used in the running file for additional works)

function [class, err, classall, errall]= EEGclassification(trainfilename, m, testfilename,n, p,q)

% p - waveform 1, q - wave form two o –wave form three

% 1 - delta 2 - theta 3 - alpha 4 –beta 5 - Gamma

[featurestrain] = EEGfeature(trainfilename, m);

% modification to EEGfeaturemod function for varying testing training ratio

[featurestest] = EEGfeature(testfilename,n);

training = [featurestrain(:,p) featurestrain(:,q)];

% modify how many features to extract here

sample = [featurestest(:,p) featurestest(:,q)];

group = [ones(m/2,1);2*ones(m/2,1)];

traininga = featurestrain;

samplea = featurestest;

[class, err, POSTERIOR, logp, coeff]= classify(sample, training, group, 'quadratic'); %'mahalanobis','quadratic','linear'as default

[classall, errall]= classify(samplea, traininga, group, 'quadratic');

display(class);

display(err);

% running file

%------------------ using 2 features out of 4 comparison -----------

class = 0; err = 0;

p = 1;

for q = 2:1:4

[clas, er]= EEGclassification('ha11train',50,'ha11test', 10, p,q);

if class == 0; % appending newly generated classificaton and error

class = clas;

else class = [class clas];

end

if err ==0;

err = er;

else err = [err er];

相关文档
最新文档