资源简介
CSP 用于处理EEG信号数据 特征提取算法

代码片段和文件信息
function CSPMatrix = learnCSP(EEGSignals)
%
%
% Copyright (C) 2010 Fabien LOTTE
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation either version 3 of the License or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not see .
%
%this function learns the CSP (Common Spatial Patterns) filters to
%discriminate two mental states in EEG signals
%
%Input:
%EEGSignals: the training EEG signals composed of 2 classes. These signals
%are a structure such that:
% EEGSignals.x: the EEG signals as a [Ns * Nc * Nt] Matrix where
% Ns: number of EEG samples per trial
% Nc: number of channels (EEG electrodes)
% nT: number of trials
% EEGSignals.y: a [1 * Nt] vector containing the class labels for each trial
% EEGSignals.s: the sampling frequency (in Hz)
%
%Output:
%CSPMatrix: the learnt CSP filters (a [Nc*Nc] matrix with the filters as rows)
%
%by Fabien LOTTE (fprlotte@i2r.a-star.edu.sg)
%created: 02/03/2010
%last revised: 02/03/2010
%
%See also: extractCSPFeatures
%check and initializations
nbChannels = size(EEGSignals.x2);
nbTrials = size(EEGSignals.x3);
classLabels = unique(EEGSignals.y);
nbClasses = length(classLabels);
if nbClasses ~= 2
disp(‘ERROR! CSP can only be used for two classes‘);
return;
end
covMatrices = cell(nbClasses1); %the covariance matrices for each class
%computing the normalized covariance matrices for each trial
trialCov = zeros(nbChannelsnbChannelsnbTrials);
for t=1:nbTrials
E = EEGSignals.x(::t)‘;
EE = E * E‘;
trialCov(::t) = EE ./ trace(EE);
end
clear E;
clear EE;
%computing the covariance matrix for each class
for c=1:nbClasses
covMatrices{c} = mean(trialCov(::EEGSignals.y == classLabels(c))3);
end
%the total covariance matrix
covTotal = covMatrices{1} + covMatrices{2};
%whitening transform of total covariance matrix
[Ut Dt] = eig(covTotal); %caution: the eigenvalues are initially in increasing order
eigenvalues = diag(Dt);
[eigenvalues egIndex] = sort(eigenvalues ‘descend‘);
Ut = Ut(:egIndex);
P = diag(sqrt(1./eigenvalues)) * Ut‘;
%transforming covariance matrix of first class using P
transformedCov1 = P * covMatrices{1} * P‘;
%EVD of the transformed covariance matrix
[U1 D1] = eig(transformedCov1);
eigenvalues = diag(D1);
[eigenvalues egIndex] = sort(eigenvalues ‘descend‘);
U1 = U1(: egIn
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3027 2010-10-28 17:26 CSP\learnCSP.m
文件 2845 2010-10-28 17:26 CSP\learnCSPLagrangian.m
目录 0 2011-07-08 17:22 CSP
----------- --------- ---------- ----- ----
5872 3
相关资源
- 读取txt文件内容matlab代码实现
- 细胞图像分割matlab代码
- 基于MP的时频分析MATLAB代码
- WCDMA matlab代码
- 图像降噪Matlab代码
- matlab人脸识别和特征提取
- 圣诞树(matlab代码)
- 心音信号处理分析(附matlab代码)
- Pattern Recognition and Machine Learning(高清
- 均值滤波和FFT频谱分析Matlab代码
- 欧拉放大论文及matlab代码
- GPS信号的码捕获matlab代码.7z
- 高光谱图像pca分析特征提取
- matlab读取SP3文件
- 图像的饱和度,亮度,色调的matlab代
- 肤色检测matlab代码
- sutton强化学习随书MATLAB代码
- 压缩鬼成像matlab代码
- 压缩感知(Compressed Sensing CS)matlab代
- 基于OFDMA系统的多用户资源分配算法,
- Allan方差分析MATLAB代码,含MPU6050八小
- 均匀球体剖面重力异常正演模拟Matl
- 印章识别matlab代码
- 连续潮流matlab代码
- 线性拟合仿真-最小二乘法、正交回归
- 矩阵填充MATLAB代码
- 大型飞机航拍图处理matlab代码
- LMS语音信号去噪matlab代码
- 卡尔曼滤波MATLAB代码
- Matlab代码编写的semi-supervised CCA 程序
评论
共有 条评论